-
-
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
packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx
Show resolved
Hide resolved
// that's why we use 'version.label' as a secondary version identifier | ||
// that can be referenced in configuration | ||
const label = version.label; | ||
if (!versionMap.has(label)) versionMap.set(label, version); |
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.
Not super fan of this logic.
We don't do this kind of thing anywhere else in the codebase so I'd prefer not introduce this here
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 am not a fan of that too but it's a workaround for a serious usability omission. Without that logic, a user faces a specifically annoying inconvenience.
Suppose a user wants to restrict the displayed versions to:
versions: ['2024.3','2024.2','2024.1','2023.4']
But without that logic, that aforementioned statement will not work. The user will be forced to specify something hacky like:
versions: ['current','2024.2','2024.1','2023.4']
or even:
versions: ['next','current','2024.1','2023.4']
This is technically ok, but it breaks mental expectations of the user. It can be clearly seen in the guide: it is simple now, but if we try to communicate "you cannot specify the current version by its true name, you must use the special keyword name 'current' because we have particular internals XXX in our code". Well, it will look inconvenient and broken to the user.
The right way to overcome that is to add the original name property to the GlobalVersion
type:
export type GlobalVersion = {
name: string;
+ /** The true version name as defined in the config */
+ canonicalName: string;
label: string;
isLast: boolean;
path: string;
/** The doc with `slug: /`, or first doc in first sidebar */
mainDocId: string;
docs: GlobalDoc[];
/** Unversioned IDs. In development, this list is empty. */
draftIds: string[];
sidebars?: {[sidebarId: string]: GlobalSidebar};
};
and then use it as a secondary (or primary) version identifier.
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 understand the usability concern.
However, introducing this "shortcut" only there also introduces inconsistencies. If we add such a shortcut, we add it globally, in a consistent way, in every single place affected.
I'd prefer if this PR omits the shortcut, and that we discuss it independently, in another dedicated proposal and PR.
Note that there are various places where we have to document next/current version names already. Unless we find a way to remove these "magic identifiers" from everywhere, we can't escape from educating users about it.
https://docusaurus.io/docs/next/versioning
https://docusaurus.io/docs/next/api/plugins/@docusaurus/plugin-content-docs
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
versions: Joi.alternatives().try( | ||
Joi.array().items(Joi.string().min(1)), | ||
Joi.object<PropVersionItems>().pattern( | ||
Joi.string().min(1), | ||
Joi.object<PropVersionItem>({ | ||
label: Joi.string().min(1), | ||
}), | ||
), | ||
), |
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 you add some basic tests in packages/docusaurus-theme-classic/src/__tests__/options.test.ts
?
We are not covering everything properly but adding tests for Joi schema is good. Joi often has surprisingly weird behaviors.
// that's why we use 'version.label' as a secondary version identifier | ||
// that can be referenced in configuration | ||
const label = version.label; | ||
if (!versionMap.has(label)) versionMap.set(label, version); |
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 understand the usability concern.
However, introducing this "shortcut" only there also introduces inconsistencies. If we add such a shortcut, we add it globally, in a consistent way, in every single place affected.
I'd prefer if this PR omits the shortcut, and that we discuss it independently, in another dedicated proposal and PR.
Note that there are various places where we have to document next/current version names already. Unless we find a way to remove these "magic identifiers" from everywhere, we can't escape from educating users about it.
https://docusaurus.io/docs/next/versioning
https://docusaurus.io/docs/next/api/plugins/@docusaurus/plugin-content-docs
packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx
Show resolved
Hide resolved
@@ -271,6 +271,78 @@ These links would all look for an appropriate version to link to, in the followi | |||
2. **Preferred version**: the version that the user last viewed. If there's no history, fall back to... | |||
3. **Latest version**: the default version that we navigate to, configured by the `lastVersion` option. | |||
|
|||
## Configuring representation of versions {#configuring-representation} |
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 to like this docs heading. What does "representation" means.
This PR is only affecting one specific navbar item, not the "global representation of a specific version" (we have options.versions
for that). I'd prefer if it was a subheading such as:
## Navbar items
previous text
### `docsVersionDropdown`
Eventually, we'll want one subheading per navbar item with more details and examples. But that can be done in another docs PR.
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