Rich text, multiselect, useFormset fixes (#1077)

* Rich text field fix

* Fix useFormset setItemValue

* Update changelog
This commit is contained in:
Piotr Grundas 2021-04-23 14:27:31 +02:00 committed by GitHub
parent 6395aa16a3
commit d48c0087e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 12 deletions

View file

@ -36,6 +36,10 @@ All notable, unreleased changes to this project will be documented in this file.
- Add shipping method description - #1058 by @jwm0
- Fix voucher and sales sorting errors - #1063 by @orzechdev
- Fix custom currency formatting - #1067 by @orzechdev
- Fixes - #1077 by @piotrgrundas:
- rich text field updates,
- multiselect empty chip upon creation of a product/variant,
- useFormset.setItemValue wrong updates,
# 2.11.1

View file

@ -80,6 +80,9 @@ export function getSelectedAttributeValues(
if (attribute.attribute.inputType === AttributeInputTypeEnum.REFERENCE) {
return attribute.values.map(value => value.reference);
}
if (attribute.attribute.inputType === AttributeInputTypeEnum.RICH_TEXT) {
return [attribute.values[0]?.richText];
}
return attribute.values.map(value => value.slug);
}

View file

@ -46,15 +46,17 @@ function useFormset<TData = {}, TValue = any>(
}
function setItemValue(id: string, value: TValue) {
const itemIndex = data.findIndex(item => item.id === id);
setData([
...data.slice(0, itemIndex),
{
...data[itemIndex],
value
},
...data.slice(itemIndex + 1)
]);
setData(data => {
const itemIndex = data.findIndex(item => item.id === id);
return [
...data.slice(0, itemIndex),
{
...data[itemIndex],
value
},
...data.slice(itemIndex + 1)
];
});
}
return {

View file

@ -135,8 +135,6 @@ function useProductVariantUpdateForm(
makeChangeHandler: makeMetadataChangeHandler
} = useMetadataChangeTrigger();
// console.log({ attributes, initial });
const handleChange: FormChange = (event, cb) => {
form.change(event, cb);
triggerChange();

View file

@ -92,7 +92,7 @@ export function getAttributeInputFromAttributes(
},
id: attribute.id,
label: attribute.name,
value: [""]
value: []
}));
}