-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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(theme): add versions
attribute to docsVersionDropdown
navbar item
#10852
base: main
Are you sure you want to change the base?
Conversation
…ionDropdown" navbar item
…rsionDropdown" navbar item
…sVersionDropdown" navbar item
Hi @hrumhurum! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
…ration of "docsVersionDropdown" navbar item
…ion of "docsVersionDropdown" navbar item
…"docsVersionDropdown" navbar item
…"docsVersionDropdown" navbar item
…on docs of "docsVersionDropdown" navbar item
…gurations in "docsVersionDropdown" navbar item
…ions in "docsVersionDropdown" navbar item
…navbar item: code refactoring
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.
The feature works thanks 👍
But I'd like a few things changed
configuration?: VersionConfiguration; | ||
}; | ||
|
||
function configureVersions( |
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.
Hmmm that looks a bit complicated to me.
Here's some pseudo-code I'd write to normalize the 3 cases under a single one:
type VersionConfig = {
label?: string
}
type VersionItem = {
version: GlobalVersion,
config?: VersionConfig
}
function getDropdownVersions({versions,item)}): VersionItem[] {
const versionMap = new Map<string, GlobalVersion>(
versions.map((version) => [version.name, version]),
);
if ( item.versions ) {
// Maybe fail-fast if the user provide version names that do not exist
// But it's preferable to do this earlier in Node.js side, if possible
if (Array.isArray(item.versions)) {
return item.versions.map(name => ({
version: versionMap[name],
config: undefined;
}));
}
else {
// pseudo code: in practice, we don't want to import Lodash in theme code
return _.mapValues(item.versions,(config,name) => ({
version: versionMap[name],
config,
}));
}
}
else {
return versions.map(v => ({version, config: undefined})
}
}
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.
The reason why the code is built like that is to keep the complexity in m + n
domain instead of m * n
. There are two actual phases:
- Getting configuration from 2 types of sources (
string[]
andPropVersionItems
). This gives usn
complexity - Applying configuration to versions. This gives us
m
complexity
If I refactor the code the way you suggest (mesh up two phases in m * n
fashion), I clearly hit the problem at the // Maybe fail-fast if the user provide version names that do not exist
stage, because I would need to duplicate that logic for two different types of configuration sources: string[]
and PropVersionItems
.
I know why you made this suggestion, it actually represents my first implementation prototype. But when I did hit a code duplication problem I had to split the logic into two clean phases to avoid m * n
complexity.
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'm not sure exactly what you mean here but I'm pretty sure I'll be able to simplify your code before merging while keeping the same behavior. If you don't find a way, I'll work on it.
packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx
Outdated
Show resolved
Hide resolved
versions
attribute to docsVersionDropdown
navbar item
versions
attribute to docsVersionDropdown
navbar itemversions
attribute to docsVersionDropdown
navbar item
…m: inline options schema
… the versioning guide
…m: cleaned up reference docs
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.
Still think we shouldn't include the "version name/label shortcut" in this PR, and discuss it independently in another proposal.
Let me know if you can simplify your code, otherwise I'll do it
packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx
Outdated
Show resolved
Hide resolved
configuration?: VersionConfiguration; | ||
}; | ||
|
||
function configureVersions( |
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'm not sure exactly what you mean here but I'm pretty sure I'll be able to simplify your code before merging while keeping the same behavior. If you don't find a way, I'll work on it.
…m: changed title of the added section
…m: use version names only
…m: tests for new options
Motivation
Fix #10833
The
docsVersionDropdown
navbar item supports a newversions
attribute to filter/whitelist displayed versions. Only the provided versions will be displayed.Example:
Also gives the ability to override version attributes (for now, only display
label
) by providing an object.Test Plan
Test links
Deploy preview: https://gp-temp-docusaurus-app1.netlify.app/eazfuscator.net