mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 10:23:34 +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];
|
||||
}, []);
|
||||
|
||||
// output: ['value1', 'value2']
|
||||
// Output: ['value1', 'value2']
|
||||
const values = Object.values(value)
|
||||
.map(x =>
|
||||
Object.entries(x)
|
||||
@ -43,6 +43,16 @@ const ActionRow = ({
|
||||
)
|
||||
.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 (
|
||||
<RowWrapper as="li" background={isGrey ? 'neutral100' : 'neutral0'}>
|
||||
<Row paddingLeft={6} style={{ width: 180 }}>
|
||||
@ -81,7 +91,7 @@ const ActionRow = ({
|
||||
id={name}
|
||||
placeholder="Your example"
|
||||
customizeContent={values => `${values.length} currently selected`}
|
||||
onChange={value => onChange(name, value)}
|
||||
onChange={handleChange}
|
||||
value={values}
|
||||
options={options}
|
||||
disabled={isFormDisabled}
|
||||
|
||||
@ -53,9 +53,11 @@ const ConditionsModal = ({
|
||||
const handleChange = (name, values) => {
|
||||
setState(
|
||||
produce(draft => {
|
||||
Object.entries(draft[name].default).forEach(([key]) => {
|
||||
draft[name].default[key] = values.includes(key);
|
||||
});
|
||||
if (!draft[name]) draft[name] = {};
|
||||
|
||||
if (!draft[name].default) draft[name].default = {};
|
||||
|
||||
draft[name].default = values;
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user