mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 03:17:11 +00:00
Add formattedValues in order to handle create behaviour
This commit is contained in:
parent
c9018e2b42
commit
ff1f63ccd9
@ -34,7 +34,7 @@ const ActionRow = ({
|
|||||||
return [...arr, obj];
|
return [...arr, obj];
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// output: ['value1', 'value2']
|
// Output: ['value1', 'value2']
|
||||||
const values = Object.values(value)
|
const values = Object.values(value)
|
||||||
.map(x =>
|
.map(x =>
|
||||||
Object.entries(x)
|
Object.entries(x)
|
||||||
@ -43,6 +43,16 @@ const ActionRow = ({
|
|||||||
)
|
)
|
||||||
.flat();
|
.flat();
|
||||||
|
|
||||||
|
// ! Only expects arrayOfOpt to be [['default', obj]] - might break in future changes
|
||||||
|
const handleChange = val => {
|
||||||
|
const [[, values]] = arrayOfOptionsGroupedByCategory;
|
||||||
|
const formattedValues = values.reduce(
|
||||||
|
(acc, curr) => ({ [curr.id]: val.includes(curr.id), ...acc }),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
onChange(name, formattedValues);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RowWrapper as="li" background={isGrey ? 'neutral100' : 'neutral0'}>
|
<RowWrapper as="li" background={isGrey ? 'neutral100' : 'neutral0'}>
|
||||||
<Row paddingLeft={6} style={{ width: 180 }}>
|
<Row paddingLeft={6} style={{ width: 180 }}>
|
||||||
@ -81,7 +91,7 @@ const ActionRow = ({
|
|||||||
id={name}
|
id={name}
|
||||||
placeholder="Your example"
|
placeholder="Your example"
|
||||||
customizeContent={values => `${values.length} currently selected`}
|
customizeContent={values => `${values.length} currently selected`}
|
||||||
onChange={value => onChange(name, value)}
|
onChange={handleChange}
|
||||||
value={values}
|
value={values}
|
||||||
options={options}
|
options={options}
|
||||||
disabled={isFormDisabled}
|
disabled={isFormDisabled}
|
||||||
|
|||||||
@ -53,9 +53,11 @@ const ConditionsModal = ({
|
|||||||
const handleChange = (name, values) => {
|
const handleChange = (name, values) => {
|
||||||
setState(
|
setState(
|
||||||
produce(draft => {
|
produce(draft => {
|
||||||
Object.entries(draft[name].default).forEach(([key]) => {
|
if (!draft[name]) draft[name] = {};
|
||||||
draft[name].default[key] = values.includes(key);
|
|
||||||
});
|
if (!draft[name].default) draft[name].default = {};
|
||||||
|
|
||||||
|
draft[name].default = values;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user