From 6c49f9c692d530565907d0d94e605fc6c710320b Mon Sep 17 00:00:00 2001 From: "Leo Y. Li" Date: Sun, 31 Mar 2019 19:00:40 -0400 Subject: [PATCH] #11: fix Bug: use addon-contexts without param specified --- addons/addon-contexts/src/@types/index.ts | 4 +++- addons/addon-contexts/src/components/ToolBar.tsx | 8 +++++--- addons/addon-contexts/src/libs/helpers.ts | 8 +++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/addons/addon-contexts/src/@types/index.ts b/addons/addon-contexts/src/@types/index.ts index 28264f9f72a6..eba96b7c2b98 100644 --- a/addons/addon-contexts/src/@types/index.ts +++ b/addons/addon-contexts/src/@types/index.ts @@ -57,7 +57,9 @@ export declare type RenderAggregatedComponents = ( export declare type RenderAggregatedContexts = ( ...arg: [ContextNode[], Exclude] ) => GenericFnWithReturn; -export declare type MergeSettings = (...args: Partial[]) => ContextNode; +export declare type MergeSettings = ( + ...args: [Partial, Partial] +) => ContextNode; export declare type GetNodes = (settings: WrapperSettings) => ContextNode[]; export declare type UseChannel = ( event: string, diff --git a/addons/addon-contexts/src/components/ToolBar.tsx b/addons/addon-contexts/src/components/ToolBar.tsx index b186362f6ec2..88cc9e993953 100644 --- a/addons/addon-contexts/src/components/ToolBar.tsx +++ b/addons/addon-contexts/src/components/ToolBar.tsx @@ -7,9 +7,11 @@ export const ToolBar: TToolBar = React.memo(({ nodes, setSelect }) => nodes.length ? ( <> - {nodes.map(({ components, ...rest }) => ( - - ))} + {nodes.map(({ components, ...props }) => + props.params.length > 1 ? ( + + ) : null + )} ) : null ); diff --git a/addons/addon-contexts/src/libs/helpers.ts b/addons/addon-contexts/src/libs/helpers.ts index 1604a7b4421e..ef72c70b6178 100644 --- a/addons/addon-contexts/src/libs/helpers.ts +++ b/addons/addon-contexts/src/libs/helpers.ts @@ -35,13 +35,15 @@ 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, @@ -49,7 +51,7 @@ export const mergeSettings: MergeSettings = ( cancelable: false, }, options, - localOptions + storyOptions ), });