Skip to content

Commit

Permalink
storybookjs#11: fix Bug: use addon-contexts without param specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Y. Li committed Apr 18, 2019
1 parent db4536e commit 6c49f9c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion addons/addon-contexts/src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export declare type RenderAggregatedComponents = (
export declare type RenderAggregatedContexts = (
...arg: [ContextNode[], Exclude<GenericProps, null>]
) => GenericFnWithReturn<ReactElement>;
export declare type MergeSettings = (...args: Partial<AddonSetting>[]) => ContextNode;
export declare type MergeSettings = (
...args: [Partial<AddonSetting>, Partial<AddonSetting>]
) => ContextNode;
export declare type GetNodes = (settings: WrapperSettings) => ContextNode[];
export declare type UseChannel = (
event: string,
Expand Down
8 changes: 5 additions & 3 deletions addons/addon-contexts/src/components/ToolBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export const ToolBar: TToolBar = React.memo(({ nodes, setSelect }) =>
nodes.length ? (
<>
<Separator />
{nodes.map(({ components, ...rest }) => (
<MenuController {...rest} key={rest.nodeId} setSelect={setSelect} />
))}
{nodes.map(({ components, ...props }) =>
props.params.length > 1 ? (
<MenuController {...props} key={props.nodeId} setSelect={setSelect} />
) : null
)}
</>
) : null
);
8 changes: 5 additions & 3 deletions addons/addon-contexts/src/libs/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@ export const renderAggregatedContexts: RenderAggregatedContexts = (nodes, propsT

export const mergeSettings: MergeSettings = (
{ icon = '', title = '', components = [], params = [], options = {} },
{ params: additionalParams = [], options: localOptions = {} }
{ params: storyParams = [], options: storyOptions = {} }
) => ({
nodeId: title,
icon: icon,
title: title,
components: components,
params: params.concat(additionalParams),
params: !(params.length || storyParams.length)
? params.concat(storyParams)
: [{ name: '', props: {} }],
options: Object.assign(
{
deep: false,
disable: false,
cancelable: false,
},
options,
localOptions
storyOptions
),
});

Expand Down

0 comments on commit 6c49f9c

Please sign in to comment.