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): update swizzle command to suggest component/theme #3021

Merged
merged 25 commits into from Aug 6, 2020

Conversation

anshulrgoyal
Copy link
Contributor

@anshulrgoyal anshulrgoyal commented Jul 2, 2020

Motivation

Better user experience for swizzle cli. Based on #2984

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

image
image
image
image
image

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jul 2, 2020
@anshulrgoyal anshulrgoyal changed the title update swizzle command Feat(v2):update swizzle command to suggest component/theme Jul 2, 2020
@anshulrgoyal anshulrgoyal changed the title Feat(v2):update swizzle command to suggest component/theme feat(v2):update swizzle command to suggest component/theme Jul 2, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Jul 2, 2020

Deploy preview for docusaurus-2 ready!

Built with commit 3aad5f3

https://deploy-preview-3021--docusaurus-2.netlify.app

@slorber
Copy link
Collaborator

slorber commented Jul 3, 2020

That looks like a nice improvement.

What about making the message clearer like "this is the list of available themes you can swizzle" or something?

@anshulrgoyal
Copy link
Contributor Author

That looks like a nice improvement.

What about making the message clearer like "this is the list of available themes you can swizzle" or something?

image

Something like this?

@slorber
Copy link
Collaborator

slorber commented Jul 3, 2020

yes, that looks fine thanks

@slorber
Copy link
Collaborator

slorber commented Jul 8, 2020

Thanks @anshulrgoyal that looks like a first version.

Here are a few suggestions to improve:

  • When component/theme not found, and no suggestion, show again the list of available components
  • Show components to swizzle in subfolders too (for example, it's a bit weird to suggest hooks, user is more likely to swizzle a single hook instead of the whole folder, and the following is actually working: yarn swizzle @docusaurus/theme-classic hooks/useAnnouncementBar)

@slorber
Copy link
Collaborator

slorber commented Jul 8, 2020

I wonder if also the theme should not explicitly define the component list to swizzle.

Because currently, some theme components are considered "implementation details", and we don't necessarily want to encourage the users to swizzle those, as this would implicitly expand the api surface of a theme.

What about exploring the idea of defining, at the theme level, a list of swizzle suggestions?

We could allow the user to swizzle values out of the suggestions, with a flag like --danger or something, so that they know that they are swizzling internal comp, and they may have to handle breaking changes

@anshulrgoyal
Copy link
Contributor Author

Thanks @anshulrgoyal that looks like a first version.

Here are a few suggestions to improve:

* When component/theme not found, and no suggestion, show again the list of available components

* Show components to swizzle in subfolders too (for example, it's a bit weird to suggest `hooks`, user is more likely to swizzle a single hook instead of the whole folder, and the following is actually working: `yarn swizzle @docusaurus/theme-classic hooks/useAnnouncementBar`)

I will add a tree-like listing for components and idea of theme defining swizzle component is nice but It would be a breaking change :), we can let user export a list of swizzle component.

@anshulrgoyal
Copy link
Contributor Author

Or we can let the theme define a list of dangerous component

@anshulrgoyal
Copy link
Contributor Author

Something like this works @slorber?
image

@anshulrgoyal
Copy link
Contributor Author

For component not found:
image
If no suggestion:
image

@slorber
Copy link
Collaborator

slorber commented Jul 9, 2020

thanks that looks better

I will add a tree-like listing for components and idea of theme defining swizzle component is nice but It would be a breaking change :), we can let user export a list of swizzle component.

Not sure what you mean by breaking changes? it's just a list of suggestions displayed, it should not forbid the user to swizzle a component that is internal, just not suggest to swizzle it. This feature should not affect current swizzle behavior. Anyway even if we did forbid the user to swizzle with the cli, he would still be able to copy the files manually if he really wants to, and that would work.

Or we can let the theme define a list of dangerous component

I'd rather have the opposite instead. By default comps are considered as internal code, unless we explicitly add them to the list, is less risky than having them being recommended for swizzling by default. Devs will likely forget to add comps to that list. If this happens, it's not a big deal, the comp won't be suggested in the list but the swizzle command on this comp will still work anyway.

@slorber
Copy link
Collaborator

slorber commented Jul 9, 2020

Maybe we should add a method like isSwizzleRecommendation(compName: string): boolean or something, and let the theme decide if it wants to do a allow/denylist or whatever?

I think the classic theme should rather be an allow list to avoid recommending to swizzle impl details, but for other smaller themes we might as well want to suggest all comps by default, and avoid annoying the user to manually craft a list of allowed comps to swizzle

@anshulrgoyal
Copy link
Contributor Author

thanks that looks better

I will add a tree-like listing for components and idea of theme defining swizzle component is nice but It would be a breaking change :), we can let user export a list of swizzle component.

Not sure what you mean by breaking changes? it's just a list of suggestions displayed, it should not forbid the user to swizzle a component that is internal, just not suggest to swizzle it. This feature should not affect current swizzle behavior. Anyway even if we did forbid the user to swizzle with the cli, he would still be able to copy the files manually if he really wants to, and that would work.

Or we can let the theme define a list of dangerous component

I'd rather have the opposite instead. By default comps are considered as internal code, unless we explicitly add them to the list, is less risky than having them being recommended for swizzling by default. Devs will likely forget to add comps to that list. If this happens, it's not a big deal, the comp won't be suggested in the list but the swizzle command on this comp will still work anyway.

I thought u meant to not allow swizzle of certain component in a theme.

@anshulrgoyal
Copy link
Contributor Author

Maybe we should add a method like isSwizzleRecommendation(compName: string): boolean or something, and let the theme decide if it wants to do a allow/denylist or whatever?

I think the classic theme should rather be an allow list to avoid recommending to swizzle impl details, but for other smaller themes we might as well want to suggest all comps by default, and avoid annoying the user to manually craft a list of allowed comps to swizzle

I am more inclined to list of allowed component because it will give more control to @docusaurus/core which can handle it in a more uniform method. If we go with isSwizzleRecommendation we have to call it with every component to generate a list.

@anshulrgoyal
Copy link
Contributor Author

image
image
image

@slorber something like this?

@anshulrgoyal
Copy link
Contributor Author

const components=[  // 'AnnouncementBar',
  // 'BlogListPage',
  // 'BlogListPaginator',
  // 'BlogPostItem',
  // 'BlogPostPage',
  // 'BlogPostPaginator',
  // 'BlogTagsListPage',
  // 'BlogTagsPostsPage',
  'CodeBlock',
  // 'DocItem',
  // 'DocPage',
  // 'DocPaginator',
  'DocSidebar',
  'Footer',
  // 'Heading',
  // 'Layout',
  // 'MDXComponents',
  // 'Navbar',
  'NotFound',
  'SearchBar',
  // 'TabItem',
  // 'Tabs',
  // 'ThemeContext',
  // 'ThemeProvider',
  // 'Toggle',
  // 'UserPreferencesContext',
  // 'UserPreferencesProvider',
  // 'hooks/useAnnouncementBar',
  // 'hooks/useHideableNavbar',
  // 'hooks/useLocationHash',
  // 'hooks/useLockBodyScroll',
  // 'hooks/useLogo',
  // 'hooks/usePrismTheme',
  // 'hooks/useScrollPosition',
  // 'hooks/useTOCHighlight',
  // 'hooks/useTabGroupChoice',
  'hooks/useTheme',
  // 'hooks/useThemeContext',
  // 'hooks/useUserPreferencesContext',
  // 'hooks/useWindowSize',
  'prism-include-languages',]

@anshulrgoyal anshulrgoyal requested a review from lex111 as a code owner July 9, 2020 18:33
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.

That looks good!

Will test this soon and merge it for the next release

website/src/theme/hooks/useTheme.js Outdated Show resolved Hide resolved
@teikjun
Copy link
Contributor

teikjun commented Aug 5, 2020

@anshulrgoyal btw, there's a merge conflict here

@anshulrgoyal
Copy link
Contributor Author

@anshulrgoyal btw, there's a merge conflict here

Thanks. I will resolve them

@yangshun yangshun changed the title feat(v2):update swizzle command to suggest component/theme feat(v2): update swizzle command to suggest component/theme Aug 5, 2020
@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Aug 6, 2020
@slorber
Copy link
Collaborator

slorber commented Aug 6, 2020

that looks good thanks

@slorber slorber merged commit ef9314e into facebook:master Aug 6, 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.

None yet

5 participants