-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
UI: Fix settings page route (about, shortcuts) #7241
Conversation
This pull request is automatically deployed with Now. Latest deployment for this branch: https://monorepo-git-fork-lonyele-fix-settings-page-route.storybook.now.sh |
Hm... I merged lastest |
or... it went fine. Now CI looks fine and chromatic also looks fine. Would anyone review this one? |
oh wait... I'll write a test for this |
…fix/settings-page-route
…fix/settings-page-route
@lonyele I'm not thrilled with the idea of adding a new API for this. In general it's better to keep API surface area smaller unless it's needed. That said, the code all looks pretty good to me. @ndelangen what do you think? |
@shilman Yeah... I really didn't want to use |
OH.... wait I found it. |
Yesss! I've been having this feeling that I almost found it but couldn't really confirm it. What about now! |
lib/ui/src/containers/nav.js
Outdated
@@ -82,14 +82,14 @@ const createMenu = memoize(1)((api, shortcutKeys, isFullscreen, showPanel, showN | |||
{ | |||
id: 'about', | |||
title: 'About your Storybook', | |||
onClick: () => api.showSettingsPage('about'), | |||
onClick: () => api.navigate('/settings/about'), |
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.
@lonyele Doesn't this change fail to change the viewMode?
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.
No! I made the new api because I wasn't sure the place where assigning value to viewMode
. However I confirmed that parsePath is the very first place where assigning value to viewMode
The reason why this bug happened is because settings
viewMode was excluded from assigning value thus always return undefined
which makes viewMode at the component level always become a story
. At the end, url is /settings/about
but viewMode is story
thus showing both story preview component and settings page component.
const knownNonViewModesRegex = /(settings)/;
export const parsePath: (path?: string) => StoryData = memoize(1000)(
(path: string | undefined | null) => {
const result: StoryData = {
viewMode: undefined,
storyId: undefined,
};
if (path) {
const [, viewMode, storyId] = path.match(splitPathRegex) || [undefined, undefined, undefined];
if (viewMode && !viewMode.match(knownNonViewModesRegex)) {
Object.assign(result, {
viewMode,
storyId,
});
}
}
return result;
}
);
While I was trying to change different parts of the code, I got lost on the real cause of this problem. It's good that I finally found it! Please check now deployment!
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.
Awesome. Thanks for seeing this through!! Great fix 👏
Issue: #6741
Summary
Make settings page route properly by changing
viewMode
state so that only settings page is rendered.What I did
viewMode
state tosettings
by introducing new apishowSettingsPage
when it is routed to settings pages(about, shortcuts, and more in the future)setStories
settings
toPropTypes
temporarily for making console warnings silent(see TODO section below)More context
Problem
As this was implemented,
viewMode
has to be changed tosettings
for rendering only settings page component.What is missing here(TODO)
I think the following PR is needed to resolve this issue of
PropType
warnings by getting the lists of possibleviewMode
from all the registered addons and others for strongly typeviewMode
.