diff --git a/lib/api/src/lib/stories.ts b/lib/api/src/lib/stories.ts index e0eb19a65605..602ec4d75541 100644 --- a/lib/api/src/lib/stories.ts +++ b/lib/api/src/lib/stories.ts @@ -19,11 +19,6 @@ export interface Root { isComponent: false; isRoot: true; isLeaf: false; - // MDX stories are "Group" type - parameters?: { - docsOnly?: boolean; - [k: string]: any; - }; } export interface Group { @@ -36,11 +31,10 @@ export interface Group { isComponent: boolean; isRoot: false; isLeaf: false; - // MDX stories are "Group" type + // MDX docs-only stories are "Group" type parameters?: { docsOnly?: boolean; viewMode?: ViewMode; - [parameterName: string]: any; }; } @@ -203,7 +197,6 @@ export const transformStoriesRawToStoriesHash = ( isComponent: false, isLeaf: false, isRoot: true, - parameters, }; return soFar.concat([result]); } @@ -216,7 +209,10 @@ export const transformStoriesRawToStoriesHash = ( isComponent: false, isLeaf: false, isRoot: false, - parameters, + parameters: { + docsOnly: parameters?.docsOnly, + viewMode: parameters?.viewMode, + }, }; return soFar.concat([result]); }, [] as GroupsList); diff --git a/lib/api/src/modules/addons.ts b/lib/api/src/modules/addons.ts index bd4e4ea6289d..dd71d081b458 100644 --- a/lib/api/src/modules/addons.ts +++ b/lib/api/src/modules/addons.ts @@ -3,6 +3,7 @@ import { ReactElement } from 'react'; import { WindowLocation } from '@reach/router'; import { ModuleFn } from '../index'; import { Options } from '../store'; +import { isStory } from '../lib/stories'; export type ViewMode = 'story' | 'info' | 'settings' | 'page' | undefined | string; @@ -94,7 +95,7 @@ export const init: ModuleFn = ({ provider, store, fullAPI }) => { const { storyId } = store.getState(); const story = fullAPI.getData(storyId); - if (!allPanels || !story) { + if (!allPanels || !story || !isStory(story)) { return allPanels; } diff --git a/lib/api/src/modules/stories.ts b/lib/api/src/modules/stories.ts index e5275dee7e0c..6d02345b8cf6 100644 --- a/lib/api/src/modules/stories.ts +++ b/lib/api/src/modules/stories.ts @@ -260,7 +260,7 @@ export const init: ModuleFn = ({ // eslint-disable-next-line no-nested-ternary const id = s ? (s.children ? s.children[0] : s.id) : kindOrId; let viewMode = - viewModeFromArgs || (s && s.parameters.viewMode) + s && !isRoot(s) && (viewModeFromArgs || s.parameters.viewMode) ? s.parameters.viewMode : viewModeFromState; diff --git a/lib/api/src/tests/addons.test.js b/lib/api/src/tests/addons.test.js index 7caadc058631..c5eae08f7c6c 100644 --- a/lib/api/src/tests/addons.test.js +++ b/lib/api/src/tests/addons.test.js @@ -75,6 +75,7 @@ describe('Addons API', () => { const storyId = 'story 1'; const storiesHash = { [storyId]: { + isLeaf: true, parameters: { a11y: { disabled: true }, }, diff --git a/lib/ui/src/components/preview/preview.tsx b/lib/ui/src/components/preview/preview.tsx index 5fec02f3797e..64d5cde34cb9 100644 --- a/lib/ui/src/components/preview/preview.tsx +++ b/lib/ui/src/components/preview/preview.tsx @@ -124,7 +124,7 @@ const useTabs = ( }, [getElements]); return useMemo(() => { - if (story && story.parameters) { + if (story?.parameters) { return filterTabs([canvas, ...tabsFromConfig], story.parameters); } diff --git a/lib/ui/src/components/sidebar/Tree/ListItem.stories.tsx b/lib/ui/src/components/sidebar/Tree/ListItem.stories.tsx index f82838c7e772..b5aeb0a0697f 100644 --- a/lib/ui/src/components/sidebar/Tree/ListItem.stories.tsx +++ b/lib/ui/src/components/sidebar/Tree/ListItem.stories.tsx @@ -17,7 +17,6 @@ const baseProps: ComponentProps = { isSelected: false, kind: 'foo', name: 'bar', - parameters: {}, refId: '', }; diff --git a/lib/ui/src/components/sidebar/Tree/ListItem.tsx b/lib/ui/src/components/sidebar/Tree/ListItem.tsx index c0aba9002724..2bbd82baa139 100644 --- a/lib/ui/src/components/sidebar/Tree/ListItem.tsx +++ b/lib/ui/src/components/sidebar/Tree/ListItem.tsx @@ -118,7 +118,6 @@ export type ListItemProps = ComponentProps & { kind: string; refId?: string; depth: number; - parameters: Record; }; export const ListItem: FunctionComponent = ({