Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update links to subcommands #536

Merged
merged 4 commits into from
Aug 9, 2019
Merged

Conversation

iAdramelk
Copy link
Contributor

  • Chech if page exists and only create link it if it exists
  • If subcommand page exists – link to page, if not, create anchor

- Chech if page exists and only create link it if it exists
- If subcommand page exists link to page, if not, create anchor
@shcheklein shcheklein temporarily deployed to dvc-org-pr-536 August 9, 2019 01:10 Inactive

if (parts.length > 2) {
url += '#' + parts[2]
if (getItemByPath(tmpUrl + parts[2])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a little bit concerned re the performance of this if page is large enough, and sidebar will become bigger

also, why do we need to do this check - what are the cases when we want to be "smart"?

also, what are the cases with #?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically just object search in the list with 200 nodes without computations. And we only run it at max twice per node with dvc command. Right now all pages have at max 10 commands, so this search run max 20 times. It should be pretty fast.

But I think that I can change Makrdown.js to PureComponent from Component to prevent rerenders without markdown content changing. This way search will be run only on initial render and on page change.

About why we need it. We basically have this possible cases:

  1. dvc command.
  2. dvc command subcommand - subcommand page exists. E. g. dvc metrics add.
  3. dvc command subcommand - no subcommand page, but parent page has header with the command name. E. g. dvc config cache (there is a #cache header on the config page).
  4. dvc command subcommand - no subcommand page and parent page don't have corresponding header.

getItemByPath is used to check if subcommand page exists or not and if not set # instead. It's possible that there is no such anchor on the page, but unfortunately I can't check it without downloading .md file.

@@ -1,23 +1,36 @@
;`use strict`

import visit from 'unist-util-visit'
import { getItemByPath } from '../../SidebarMenu/helper'

function linker() {
function transformer(tree) {
visit(tree, 'inlineCode', function(node, index, parent) {
if (parent.type !== 'link' && /dvc\s+[a-z-.]+/.test(node.value)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to change the regex here to match three-parts nodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary. Right now this regexp just check if this is a dvc command or not. Breaking it to parts happens at the next line let parts = node.value.split(/\s+/). We can add additional check to part[2] to check if it matches command syntax, but we can leave regexp itself as is.

@shcheklein
Copy link
Member

https://dvc-org-pr-536.herokuapp.com/doc/commands-reference/remote/default - dvc remote modify has a wrong link link with #

Copy link
Contributor Author

@iAdramelk iAdramelk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shcheklein can confirm dvc remote modify bug, will check it.


if (parts.length > 2) {
url += '#' + parts[2]
if (getItemByPath(tmpUrl + parts[2])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically just object search in the list with 200 nodes without computations. And we only run it at max twice per node with dvc command. Right now all pages have at max 10 commands, so this search run max 20 times. It should be pretty fast.

But I think that I can change Makrdown.js to PureComponent from Component to prevent rerenders without markdown content changing. This way search will be run only on initial render and on page change.

About why we need it. We basically have this possible cases:

  1. dvc command.
  2. dvc command subcommand - subcommand page exists. E. g. dvc metrics add.
  3. dvc command subcommand - no subcommand page, but parent page has header with the command name. E. g. dvc config cache (there is a #cache header on the config page).
  4. dvc command subcommand - no subcommand page and parent page don't have corresponding header.

getItemByPath is used to check if subcommand page exists or not and if not set # instead. It's possible that there is no such anchor on the page, but unfortunately I can't check it without downloading .md file.

@shcheklein shcheklein temporarily deployed to dvc-org-pr-536 August 9, 2019 15:31 Inactive
@shcheklein shcheklein merged commit 967a5af into iterative:master Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants