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

feat: allow searching and filtering doc sidebar items #6945

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Mar 20, 2022

Motivation

The idea for this feature came to me a bit spontaneously when I had a lot of time to think, so when I had the opportunity, I decided to implement it right away. It's not the final implementation, I guess it needs more elaboration in terms of performance and UX/UI.

In any case, this is roughly how it should work:

ezgif com-gif-maker

I think it's a pretty handy feature, which will be especially useful in sidebars with lots of items. The end-user can try to filter doc items by title (label) without using full text search. Google Web Docs (https://developers.google.com/ ) has a similar feature, for reference.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Preview

Related PRs

@lex111 lex111 added the pr: new feature This PR adds a new API or behavior. label Mar 20, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 20, 2022
@netlify
Copy link

netlify bot commented Mar 20, 2022

[V2]

Name Link
🔨 Latest commit d2fa385
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/624b22c7f215350008f99f6b
😎 Deploy Preview https://deploy-preview-6945--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Mar 20, 2022

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 43
🟢 Accessibility 100
🟢 Best practices 92
🟢 SEO 100
🟢 PWA 90

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

@github-actions
Copy link

github-actions bot commented Mar 20, 2022

Size Change: -750 B (0%)

Total Size: 806 kB

Filename Size Change
website/build/assets/css/styles.********.css 106 kB +1.01 kB (+1%)
website/build/assets/js/main.********.js 611 kB -1.85 kB (0%)
website/build/index.html 38.5 kB +90 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 49.9 kB

compressed-size-action

@Josh-Cena
Copy link
Collaborator

This produces a weird UX when combined with autocollapsing sidebar:

Test

First is that the search expands all items, even when the query is later emptied. Currently, there's no way to fold them back on one click, so this could be rather inconvenient.

Second is that when a category is expanded before entering the query, the category becomes collapsed.

The collapsed state management is quite messy. If we can refactor that as well it would be great, but I don't know how to sort it out😅

@lex111
Copy link
Contributor Author

lex111 commented Mar 20, 2022

Yep, I'm aware of this bug :(, so far I have not been able to fix it, at the moment it is the biggest problem with introducing this feature.

@Josh-Cena
Copy link
Collaborator

My idea is that we eventually need to implement some type of "global collapsed state store", managed at the sidebar level, not at each category level. However, there's currently no way to uniquely identify a sidebar item within the sidebar tree, like a "sidebar item key" that's both unique and persistent (i.e. not array index)

@Josh-Cena Josh-Cena changed the title feat: add ability to filter doc sidebar items feat: search and filter doc sidebar items Mar 20, 2022
@Josh-Cena Josh-Cena changed the title feat: search and filter doc sidebar items feat: allow searching and filtering doc sidebar items Mar 20, 2022
@Josh-Cena Josh-Cena marked this pull request as draft March 21, 2022 08:57
@lex111
Copy link
Contributor Author

lex111 commented Mar 24, 2022

@slorber could you please take a look at this PR? Does this feature make sense in Docusaurus at all?

@slorber
Copy link
Collaborator

slorber commented Mar 25, 2022

🤷‍♂️ not 100% convinced that this kind of UX is worth it.
Have you seen this UX implemented anywhere so far?
Why would users use this instead of the regular search?

At least it should probably not be enabled by default (and we don't have a way to add sidebar-specific config)

@Josh-Cena
Copy link
Collaborator

The TS-ESLint website will benefit from it: https://typescript-eslint.io/rules/

And yes, we should really figure out adding metadata for each sidebar very soon.

@lex111
Copy link
Contributor Author

lex111 commented Mar 25, 2022

Yes, this feature can be useful in the case of categories with API functions for example. Or even just for doc sites like Redux, which have a lot of doc pages with pretty good titles for searching. The user can quickly find the desired function or page without using a regular full-text search which may not be available or produce too many irrelevant results. So using the filter is quite handy and easy for users in that case.

Docs sites that have a similar filter for reference:

You can see how works the filter on these sites. I think the UI/UX in my implementation is not that bad, but I definitely need help with getting the filter to work nice with autocollapsing sidebar feature.

@slorber
Copy link
Collaborator

slorber commented Mar 25, 2022

Thanks for the refs 👍 yes that looks like useful in some specific cases

I suggest postponing this implementation a bit because I planned to refactor the sidebar asap (was next on my list), so maybe it will be easier to implement/review once it's refactored.

we eventually need to implement some type of "global collapsed state store", managed at the sidebar level

Yes that's what I want to have too instead of state at every level

@lex111
Copy link
Contributor Author

lex111 commented Apr 27, 2022

I curious if we can get this feature for the next release? Then when "global collapsed state store" is implemented, we just refactor the current implementation. How's that sound?

@slorber
Copy link
Collaborator

slorber commented Apr 27, 2022

@lex111 as I mentioned in Discord I'd really like to focus on 2.0 launch. I only have a limited time and there are too many PRs to review for this to happen so I'm likely to not even take a look at this PR and other non-mandatory refactors until 2.0 is launched unfortunately, otherwise it will never happen 😅

@lex111
Copy link
Contributor Author

lex111 commented Apr 27, 2022

@slorber I understand you, but it seems not so critical and risky change, perhaps we as an experiment can include it in the new beta release?

@Babilinski
Copy link

I think this would be helpful ^ especially when using Docusaurus for API docs. DocFX has something like this -https://docs.unity3d.com/Packages/[email protected]/manual/index.html

@sserrata
Copy link
Contributor

sserrata commented Aug 3, 2022

I agree that this would be very useful when using Docusaurus for API docs. Now that 2.0 has been released, I'm happy to help test or work on this if there's still interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants