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 - Add shipping method description - #1058 by @jwm0
- Fix voucher and sales sorting errors - #1063 by @orzechdev - Fix voucher and sales sorting errors - #1063 by @orzechdev
- Fix custom currency formatting - #1067 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 # 2.11.1

View file

@ -80,6 +80,9 @@ export function getSelectedAttributeValues(
if (attribute.attribute.inputType === AttributeInputTypeEnum.REFERENCE) { if (attribute.attribute.inputType === AttributeInputTypeEnum.REFERENCE) {
return attribute.values.map(value => value.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); return attribute.values.map(value => value.slug);
} }

View file

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

View file

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

View file

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