Skip to content

Commit

Permalink
fix: object merge values
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Aug 3, 2020
1 parent ccb3f6f commit 477809f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
45 changes: 25 additions & 20 deletions core/core/src/controls-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import { Story } from './document';

const mergeValue = (control: ComponentControl, value: any): any => {
if (control && control.type === ControlTypes.OBJECT) {
const objValue = mergeControlValues(
control.value as ComponentControls,
undefined,
value,
);
return {
...control,
value: mergeControlValues(
control.value as ComponentControls,
undefined,
value,
),
value: objValue,
};
}
return {
Expand All @@ -32,21 +33,25 @@ export const mergeControlValues = (
controlName: string | undefined,
value: any,
): ComponentControls => {
return controlName
? {
...controls,
[controlName]: mergeValue(controls[controlName], value),
}
: Object.keys(controls).reduce(
(acc, key) => ({
...acc,
[key]: mergeValue(
controls[key],
value[key] === undefined ? controls[key].value : value[key],
),
}),
{},
);
if (controlName) {
return {
...controls,
[controlName]: mergeValue(controls[controlName], value),
};
}

return Object.keys(controls).reduce(
(acc, key) => ({
...acc,
[key]: mergeValue(
controls[key],
value[key] === undefined
? controls[key].value
: value[key].value || value[key],
),
}),
{},
);
};

export const resetControlValues = (
Expand Down
2 changes: 1 addition & 1 deletion ui/editors/src/ColorEditor/ColorEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const ColorEditor: PropertyEditor = ({ name }) => {
borderRadius: '1rem',
}}
/>
{control.value && control.value.toUpperCase()}
{typeof control.value === 'string' && control.value.toUpperCase()}
{displayColorPicker ? (
<Box
css={{
Expand Down

0 comments on commit 477809f

Please sign in to comment.