Skip to content

Added onlyShowOnActiveDoc property to DocsVersionDropdownNavbarItem - #5756

Closed
Leander-van-Boven wants to merge 5 commits into
meta:mainfrom
Leander-van-Boven:main
Closed

Leander-van-Boven wants to merge 5 commits into
meta:mainfrom
Leander-van-Boven:main

Conversation

@Leander-van-Boven

Copy link
Copy Markdown

Motivation

When using a multi-instanced, versioned docs website with DocsVersionDropdowns, these are always displayed throughout the whole website (even on normal/static pages that aren't part of the docs). My proposed changes will cause the DocsVersionDropdowns to only be shown when browsing its associated docs-plugin path.

Not only makes this more sense, and does it look prettier. It may also speed up initial page loading, as those dropdowns that don't need to be displayed are never generated.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

I am already using the proposed changes in staging, soon to be production.

How to use this feature:

  1. Create website with two versioned docs.
  2. Add two DocsVersionDropdowns to config.js with the new property set to true:
{
  type: 'docsVersionDropdown',
  docsPluginId: 'docs-1',
  position: 'right',
  onlyShowOnActiveDoc: true,
},
{
  type: 'docsVersionDropdown',
  docsPluginId: 'docs-2',
  position: 'right',
  onlyShowOnActiveDoc: true,
},

When browsing docs-1 only the first dropdown should be displayed, idem dito for docs-2 and the second dropdown.

Related PRs

#5360 was mentioned by Josh-Cena when discussing this PR.

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)
This PR might require some documentation updates (config.js, doc multi-instancing/versioning pages), which I am willing to do if this PR gets approved.

The newly added property, when set to `true` in the config, will only show this `DocsVersionDropdownNavbarItem` on the doc pages of its associated docs plugin.
Added onlyShowOnActiveDoc property
@facebook-github-bot

Copy link
Copy Markdown
Contributor

Hi @Leander-van-Boven!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 21, 2021
@facebook-github-bot

Copy link
Copy Markdown
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@slorber

slorber commented Oct 21, 2021 •

Copy link
Copy Markdown
Collaborator

Hi @Leander-van-Boven, I understand this use-case

We already plan to add a system of "navbar activation strategy", so that all pages do not share the same navbar items.

#4389

We also plan to provide the ability to create your own custom navbar items in the future.

Considering we plan a better API for this feature, I'd rather not add such a temporary option.

Note, you should be able to achieve what you want in the meantime thanks to swizzle / wrapping the original element, as suggested here:

#3930 (comment)

I'm also not a big fan of having the navbar item returning null.
We may want to wrap each navbar item is a navbar item container in the future, and it would be odd if the navbar item container would be rendered, but empty: the filtering of navbar items should rather be done before, upper in the React tree

@Josh-Cena

Copy link
Copy Markdown
Collaborator

Note, you should be able to achieve what you want in the meantime thanks to swizzle / wrapping the original element, as suggested here:

They're already swizzling the comp, they just felt like it's worth contributing to the original code base🧐

Also, I think this does look like an intuitive API without going too much into the impl details?

@slorber

slorber commented Oct 21, 2021

Copy link
Copy Markdown
Collaborator

Also, I think this does look like an intuitive API without going too much into the impl details?

It is intuitive but I'd rather have something more general, and also composable.

{when: "pluginInstanceIsActive"} => could work for all navbar items, also blog ones if we create one later?

{when: ["pluginInstanceIsActive",{type: "routeMatch",path: "/api/ios"}]} => composition

A boolean wouldn't allow any composition, and we'll need to add support for this everywhere.

I'd rather first add a generic low-level API to solve this problem in general, and only then, if it is not intuitive enough, add a shortcut for convenience

@Josh-Cena

Copy link
Copy Markdown
Collaborator

Ah, makes sense. So we should turn back to #5360 one day? We should ship category index pages soon :P

@slorber

slorber commented Oct 21, 2021

Copy link
Copy Markdown
Collaborator

Yes we'll get back to it later, probably after v2.0.

We need to think about the big picture and make something consistent: navbar, doc sidebar, blog sidebar, footer... all could technically benefit from this kind of behavior

@Leander-van-Boven

Copy link
Copy Markdown
Author

I'd rather first add a generic low-level API to solve this problem in general, and only then, if it is not intuitive enough, add a shortcut for convenience

I can see the argument, and I'm fine with that. As @Josh-Cena mentioned, we will use the swizzled version for now, so we at least have the preferred behaviour until it will be officially supported.

I'll keep my eye out for that.

Thanks for the effort anyways! :)

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.

4 participants