-
Notifications
You must be signed in to change notification settings - Fork 394
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
Fix #305 #527
Fix #305 #527
Conversation
- Changed sidebar format so it can now have any number of levels - All json transformations and normalizations moved to src/Documentation/SidebarMenu/helper.js and done on the first init - Simplified docs.js, Markdown.js and SidebarMenu.js
- Fix bug then parent was added to prev/next order after children - Fix bug the prev item didn’t have source and was redirecting back to first child - Add check for items with source = false and without children, they throw erros now
const FILE_ROOT = '/static/docs/' | ||
const FILE_EXTENSION = '.md' | ||
|
||
let prevReference // We will save prev item reference here to use for the next and prev fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's definitely > 80 symbols. I would recommend to install the pre-commit hook: https://dvc.org/doc/user-guide/contributing-documentation#development-environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and run the prettier from the command line once again to reformat what has been committed already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think prettier ignores comments, so it probably didn't help. But I will fix comment lengths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you might be right - it just does not know what can be done with it.
pages/doc.js
Outdated
if (!item) { | ||
this.setState({ pageNotFound: true, currentItem: {} }) | ||
|
||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's probably better to use else
instead of an explicit return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will change it.
Fixed bug with nested intems with osurce false, it required large refactor of the normalization function.
} | ||
|
||
function normalizeSidebar(data, parentPath, currentSidebar) { | ||
data.forEach(item => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ie11? not that it's very important to keep supporting it, but if it's the only that breaks it I would do some workaround
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forEach works in IE starting with IE9 according to https://caniuse.com/#feat=es5 , so it should not be a problem.
|
||
const { label, slug, source } = item | ||
|
||
// If prev item don't have source we need to recirsively search for it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: don't -> doesn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
// Global cache vars used in normalization | ||
|
||
let prevReference // Save last item here to generate the prev field | ||
const normalizedSidebar = [] // Current state of sidebar to search for prev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current state of sidebar to search for
- a bit misleading. It's not only a "cache" to search for prev. This is what we export then as a final result, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will try to move them inside function and if I wasn't able to, will change text.
} | ||
} | ||
|
||
// Global cache vars used in normalization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we pass them to functions, do we actually need a global prevReference
, for example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an idea how it can be done, but I'm not sure that it will make code easier to understand, but I will try today.
@iAdramelk https://dvc-org-pr-527.herokuapp.com/doc/understanding-dvc/what-is-dvc.md - not found page is broken + the page itself is broken? |
- Fix typo in comment text - Fix error in slug name in sidebar.json - Move fetch inside else clause
@shcheklein Thie problem with https://dvc-org-pr-527.herokuapp.com/doc/understanding-dvc/what-is-dvc.md is that I forgot to remove |
Yep, removed prevReference and current result from global scope successfully. |
import { getParentsListFromPath } from './helper' | ||
|
||
function SidebarMenuItem({ children, label, path, activePaths, onNavigate }) { | ||
const isActive = activePaths && activePaths.includes(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use lodash.includes, otherwise we are breaking compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, will change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing stuff 🎉 :)
This PR should fix #305. It contains following changes.
New format for
sidebar.json
. It removes distinction between sections and files and allows any number of nesting levels.New format (full):
slug
- Required. URL part for the current link, will be also used as URL prefix for all children of the current category. Example:metrics
->/doc/metrics
. For the childadd
of metrics ->/doc/metrics/add
.label
- name of the menu item. If not set, it will be generated fromslug
usingstartCase
from lodash. Generating from slug example:get-started
->Get Started
.source
-> name of the corresponding .md file in the filesystem. If not set, it will be generated fromslug
. Generating from slug example:metrics
->metrics.md
. For legacy reasons you can explicitly set this field tofalse
, in this case after user select this item, its first child will be shown instead.children
- optional array of child items.You can also use short syntax.
metrics
is the same as{ "slug": "metrics" }
.This config is parsed using new
src/Documentation/SidebarMenu/helper.js
file. It will normalize data from "sidebar.json" and generate all necessary field. It's output structure is:This way we don't need to calculate them in react component anymore.
This file also exports two new helper functions:
getItemByPath
- recursively search for items in sidebar, that matches given path. It also resolve some edge cases (likesource = false
, and/doc/
route).getParentsListFromPath
- returns all parents paths from current path. Example:/doc/commands-reference/destroy
will return['/doc/commands-reference', '/doc/commands-reference/destroy']
. Used to make nescessary menu items active.pages/doc.js
,src/Documentation/Markdown/Markdown.js
andsrc/Documentation/SidebarMenu/SidebarMenu.js
are updated accordingly, all business logic related to parsingsidebar.json
are removed from them and replaced with data from new normalized menu items.Difference from the current version: