From ac6d2e009a40a2e620180d1fd4f97da803c6cb54 Mon Sep 17 00:00:00 2001 From: atanasster Date: Thu, 13 May 2021 08:51:43 +0300 Subject: [PATCH] fix: smart marked as false --- core/core/src/controls-utils.ts | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/core/core/src/controls-utils.ts b/core/core/src/controls-utils.ts index d57b2e89b..e8c1a78ed 100644 --- a/core/core/src/controls-utils.ts +++ b/core/core/src/controls-utils.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import escape from 'escape-html'; -import { deepmerge, deepMergeReplaceArrays } from './deepMerge'; +import { deepmerge } from './deepMerge'; import { Components, getComponentName } from './components'; import { Story, Document } from './document'; import { SmartControls } from './common'; @@ -351,18 +351,22 @@ const controlShortcuts = ( export const transformControls = ( controls?: ComponentControls, propControls?: ComponentControls, + smart = true, ): ComponentControls | undefined => { return controls - ? Object.keys({ ...propControls, ...controls }).reduce((acc, key) => { - const control = controlShortcuts(key, controls, propControls); - if (control.defaultValue === undefined) { - const defaultValue = getControlValue(control); - if (typeof defaultValue !== 'function') { - control.defaultValue = defaultValue; + ? Object.keys(smart ? { ...propControls, ...controls } : controls).reduce( + (acc, key) => { + const control = controlShortcuts(key, controls, propControls); + if (control.defaultValue === undefined) { + const defaultValue = getControlValue(control); + if (typeof defaultValue !== 'function') { + control.defaultValue = defaultValue; + } } - } - return { ...acc, [key]: control }; - }, {}) + return { ...acc, [key]: control }; + }, + {}, + ) : undefined; }; @@ -445,14 +449,10 @@ export const getStoryControls = ( return true; }) .reduce((acc, key) => ({ ...acc, [key]: newControls[key] }), {}); - const transformed = transformControls(storyControls, filteredControls); const { smart = true } = smartControls; - if (!story.component || !smart || story.smartControls === false) { - return transformControls(storyControls, filteredControls); - } - return transformed - ? deepMergeReplaceArrays(filteredControls, transformed) - : filteredControls; + const isSmart: boolean = story.smartControls !== false && smart; + + return transformControls(storyControls, filteredControls, isSmart); } } return transformControls(storyControls);