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

Core: Optimize storiesHash by removing unused parameters #11624

Merged
merged 3 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lib/api/src/lib/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
};
}

Expand Down Expand Up @@ -203,7 +197,6 @@ export const transformStoriesRawToStoriesHash = (
isComponent: false,
isLeaf: false,
isRoot: true,
parameters,
};
return soFar.concat([result]);
}
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/api/src/modules/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/modules/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions lib/api/src/tests/addons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('Addons API', () => {
const storyId = 'story 1';
const storiesHash = {
[storyId]: {
isLeaf: true,
parameters: {
a11y: { disabled: true },
},
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/src/components/preview/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const useTabs = (
}, [getElements]);

return useMemo(() => {
if (story && story.parameters) {
if (story?.parameters) {
return filterTabs([canvas, ...tabsFromConfig], story.parameters);
}

Expand Down
1 change: 0 additions & 1 deletion lib/ui/src/components/sidebar/Tree/ListItem.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const baseProps: ComponentProps<typeof ListItem> = {
isSelected: false,
kind: 'foo',
name: 'bar',
parameters: {},
refId: '',
};

Expand Down
1 change: 0 additions & 1 deletion lib/ui/src/components/sidebar/Tree/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export type ListItemProps = ComponentProps<typeof Item> & {
kind: string;
refId?: string;
depth: number;
parameters: Record<string, any>;
};

export const ListItem: FunctionComponent<ListItemProps> = ({
Expand Down