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

Finish go to selected paged from category sidebar #4323

Closed
wants to merge 15 commits into from

Conversation

ben-qnimble
Copy link
Contributor

@ben-qnimble ben-qnimble commented Mar 1, 2021

Motivation

Pull #3898 looks very helpful (sidebar category linking to doc) but it seems like it got stalled, so I'm trying to get it over the finish line by addressing issues mentioned in the pull request code review.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Please see #3898. I set a few categories to have links and verified that they work as expected.

Related PRs

Adding to the commits in #3898 to address code review comments.

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 1, 2021
@netlify
Copy link

netlify bot commented Mar 1, 2021

@netlify
Copy link

netlify bot commented Mar 1, 2021

@github-actions
Copy link

github-actions bot commented Mar 1, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 86
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4323--docusaurus-2.netlify.app/classic/

@github-actions
Copy link

github-actions bot commented Mar 1, 2021

Size Change: 0 B

Total Size: 532 kB

ℹ️ View Unchanged
Filename Size Change
website/build/assets/css/styles.********.css 87.1 kB 0 B
website/build/assets/js/main.********.js 359 kB 0 B
website/build/blog/2017/12/14/introducing-docusaurus/index.html 60.3 kB 0 B
website/build/docs/introduction/index.html 235 B 0 B
website/build/index.html 25.4 kB 0 B

compressed-size-action

@ben-qnimble ben-qnimble marked this pull request as ready for review March 2, 2021 01:25
@ben-qnimble ben-qnimble requested a review from slorber as a code owner March 2, 2021 01:25
@ben-qnimble ben-qnimble mentioned this pull request Mar 2, 2021
@ben-qnimble ben-qnimble requested a review from lex111 March 2, 2021 19:02
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Thanks for working on this

Left some inline review comments

let me know if you need any help to handle those

if (Object.hasOwnProperty.call(item.link, 'type')) {
switch (item.link.type) {
case 'doc':
setInitialLink(item.link.id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not correct, the id is not the URL path, as docs can use slugs they have ids that can be totally different from their final URL.

This requires resolving the id to the doc URL path

(+ shouldn't need setState)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a function for getting the URL path from a document id?

@@ -97,7 +97,7 @@ function assertItem<K extends string>(
function assertIsCategory(
item: unknown,
): asserts item is SidebarItemCategoryJSON {
assertItem(item, ['items', 'label', 'collapsed', 'customProps']);
assertItem(item, ['items', 'label', 'collapsed', 'link', 'customProps']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to validate that the link attribute is valid in this function + add unit tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might need some help on this one

@ben-qnimble ben-qnimble requested a review from slorber March 11, 2021 01:12
@ben-qnimble ben-qnimble requested a review from lex111 March 29, 2021 15:50
Copy link
Contributor Author

@ben-qnimble ben-qnimble left a comment

Choose a reason for hiding this comment

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

Thanks for working on this

Left some inline review comments

let me know if you need any help to handle those

Yeah, I think I'll need help on what's left. Mostly decoding the url from the doc id and validation on the link. Thanks

if (Object.hasOwnProperty.call(item.link, 'type')) {
switch (item.link.type) {
case 'doc':
setInitialLink(item.link.id);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a function for getting the URL path from a document id?

@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Aug 13, 2021

Hi, what's the status of this PR? I'd be really looking forward to this feature.

@ben-qnimble In case you are still working on it, here are a few hints:

Is there a function for getting the URL path from a document id?

You need several hooks to extract this information, but here's a reference:

const doc = getDocInVersions(versions, docId);
const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);
return (
<DefaultNavbarItem
exact
{...props}
className={clsx(props.className, {
[activeDocInfimaClassName]:
activeDoc?.sidebar && activeDoc.sidebar === doc.sidebar,
})}
activeClassName={activeDocInfimaClassName}
label={staticLabel ?? doc.id}
to={doc.path}

We need to validate that the link attribute is valid in this function

Just follow the pattern below to verify that link is an object with type, to, href properties, etc., and it's pointing to a valid location (or not? Maybe just type check is sufficient)

I'm in need of this feature and it's a shame seeing it getting stalled multiple times now 🤦‍♂️

@@ -132,6 +153,7 @@ function DocSidebarItemCategory({
<DocSidebarItem
tabIndex={collapsed ? '-1' : '0'}
key={childItem.label}
link={link}
Copy link
Collaborator

@Josh-Cena Josh-Cena Aug 13, 2021

Choose a reason for hiding this comment

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

Why bind this to the children elements? Only the category with link attribute should have a link associated right?

@slorber
Copy link
Collaborator

slorber commented Aug 20, 2021

Hi, what's the status of this PR? I'd be really looking forward to this feature.

This is a complex feature and this PR is not really in the direction I'd like to take to provide a set of useful features to Docusaurus (in particular #2643)

I'll try to see if there's anything to take here, but ultimately it's likely that I close it.

I'll start to work on these features soon, this is the next big task on my todolist.

@Josh-Cena
Copy link
Collaborator

Closing in favor of #5830

@Josh-Cena Josh-Cena closed this Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants