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(v2): add custom props for consumption by swizzled sidebar #3888

Merged
merged 1 commit into from
Dec 10, 2020

Conversation

oriooctopus
Copy link
Contributor

@oriooctopus oriooctopus commented Dec 6, 2020

Motivation

-I want to pass in custom props for consumption by my swizzled DocSidebar component

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

I modified a test within docusaurus-plugin-content/src/__tests__/sidebars.test.ts

Related PRs

#3868

@facebook-github-bot
Copy link
Contributor

Hi @oriooctopus!

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.

In order for us to review and merge your code, 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.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@github-actions
Copy link

github-actions bot commented Dec 6, 2020

Size Change: +16 B (0%)

Total Size: 154 kB

ℹ️ View Unchanged
Filename Size Change
website/build/blog/2017/12/14/introducing-docusaurus/index.html 20.7 kB -3 B (0%)
website/build/docs/introduction/index.html 180 B 0 B
website/build/index.html 5.82 kB 0 B
website/build/main.********.js 109 kB +19 B (0%)
website/build/styles.********.css 17.5 kB 0 B

compressed-size-action

@netlify
Copy link

netlify bot commented Dec 6, 2020

✔️ Deploy preview for docusaurus-2 ready!
Built without sensitive environment variables

🔨 Explore the source changes: 708b9da

🔍 Inspect the deploy logs: https://app.netlify.com/sites/docusaurus-2/deploys/5fd264ae8c351500070b0a2a

😎 Browse the preview: https://deploy-preview-3888--docusaurus-2.netlify.app

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Dec 6, 2020
@facebook-github-bot
Copy link
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 added the pr: new feature This PR adds a new API or behavior. label Dec 7, 2020
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.

The implementation looks fine, but please avoid refactoring types unnecessarily, that's outside the scope of this feature request and should rather be decided separately

@@ -39,6 +39,7 @@ Available document ids=
type: 'link',
label: sidebar_label || title,
href: permalink,
extra: item.extra,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally, I like "data" more for the name of this attribute, but no strong opinion

@ReginaLiang what's your opinion?

Choose a reason for hiding this comment

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

@slorber,
Actually, I think any one will be fine. ^v^, a little little thought, How about customFields? It is consistent with DocusaurusConfig object, I guess customFields more meaningful. But any one is OK for me.

@slorber, @oriooctopus ,
Thanks for your guys great work! I believe docusaurus is getting better and better.

@@ -165,6 +165,8 @@ As the name implies, `SidebarItem` is an item defined in a Sidebar. There are a
- [Ref](#ref)
- [Category](#category)

**Note**: If you would like to pass in custom props to a swizzled sidebar, an optional object called `extra` can be added to any of the items:
Copy link
Collaborator

Choose a reason for hiding this comment

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

That does not seem good enough to me, it looks like you forgot to add an example after the : ?

@oriooctopus
Copy link
Contributor Author

@slorber would you like an additional commit with the changes or would you prefer them squashed/amended?

@slorber
Copy link
Collaborator

slorber commented Dec 8, 2020

@oriooctopus it's not needed to squash because we squash all prs when merging, so we don't care about your local history 😉

@github-actions
Copy link

github-actions bot commented Dec 8, 2020

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 59
🟢 Accessibility 99
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

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

@oriooctopus
Copy link
Contributor Author

@slorber does this look good to you?

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.

Still some type->interface refactorings

  • "extra" still there after the renaming.

Otherwise LGTM.
Not sure customProps is the best name, but let's merge this. We'll see later if anyone can come with a better name 😅

@@ -20,7 +21,7 @@ import {
import {mapValues, flatten, difference} from 'lodash';
import {getElementsAround} from '@docusaurus/utils';

type SidebarItemCategoryJSON = {
export type SidebarItemCategoryJSON = SidebarItemBase & {
Copy link
Collaborator

Choose a reason for hiding this comment

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

does it need an export? I don't see it imported anywhere, why this change?


export type SidebarItemLink = {
export interface SidebarItemLink extends SidebarItemBase {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as before: use type aliases instead of refactoring to interface

@@ -21,13 +21,17 @@ declare module '@docusaurus/plugin-content-docs-types' {
permalinkToSidebar: PermalinkToSidebar;
};

export type PropSidebarItemLink = {
export type PropsSidebarItemBase = {
extra?: object;
Copy link
Collaborator

Choose a reason for hiding this comment

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

now renamed to customProps?

@oriooctopus
Copy link
Contributor Author

Just updated it, sorry about the changes I missed last time.
Question: what's the reason for not importing types in plugin-content-docs.d.ts but importing them in sidebars.ts? Excuse me if this is a simple question, I'm new to typescript

@slorber
Copy link
Collaborator

slorber commented Dec 10, 2020

thanks, LGTM 👍

@oriooctopus the TS setup is a bit messy currently, not sure to have a good answer for that, but we'll try to improve it over time :)
Initially the codebase was mostly JS so it's an incremental upgrade

@slorber slorber merged commit b11c24b into facebook:master Dec 10, 2020
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.

4 participants