Fix can not edit non-required attribute on a variant that has other required attributes (#3966)
* Resend current values of all not-updated attributes Fix variant editor can not save due to requirement of receiving values of all required attributes from API * add changeset
This commit is contained in:
parent
931be66667
commit
f6fa909696
2 changed files with 35 additions and 2 deletions
5
.changeset/slimy-mangos-refuse.md
Normal file
5
.changeset/slimy-mangos-refuse.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"saleor-dashboard": patch
|
||||
---
|
||||
|
||||
Fix can not edit non-required attribute on a variant that has other required attributes
|
|
@ -141,9 +141,12 @@ export function getBulkVariantUpdateInputs(
|
|||
|
||||
const createToUpdateInput =
|
||||
(data: DatagridChangeOpts) =>
|
||||
(variant, variantIndex): ProductVariantBulkUpdateInput => ({
|
||||
(
|
||||
variant: ProductFragment["variants"][number],
|
||||
variantIndex: number,
|
||||
): ProductVariantBulkUpdateInput => ({
|
||||
id: variant.id,
|
||||
attributes: getAttributeData(data.updates, variantIndex, data.removed),
|
||||
attributes: getVariantAttributesForUpdate(data, variantIndex, variant),
|
||||
sku: getSkuData(data.updates, variantIndex, data.removed),
|
||||
name: getNameData(data.updates, variantIndex, data.removed),
|
||||
stocks: getVaraintUpdateStockData(
|
||||
|
@ -155,6 +158,31 @@ const createToUpdateInput =
|
|||
channelListings: getUpdateVariantChannelInputs(data, variantIndex, variant),
|
||||
});
|
||||
|
||||
const getVariantAttributesForUpdate = (
|
||||
data: DatagridChangeOpts,
|
||||
variantIndex: number,
|
||||
variant: ProductFragment["variants"][number],
|
||||
) => {
|
||||
const updatedAttributes = getAttributeData(
|
||||
data.updates,
|
||||
variantIndex,
|
||||
data.removed,
|
||||
);
|
||||
// Re-send current values for all not-updated attributes, in case some of them were required
|
||||
const notUpdatedAttributes: ReturnType<typeof getAttributeData> =
|
||||
variant.attributes
|
||||
.filter(attribute =>
|
||||
updatedAttributes.find(
|
||||
updatedAttribute => updatedAttribute.id !== attribute.attribute.id,
|
||||
),
|
||||
)
|
||||
.map(attribute => ({
|
||||
id: attribute.attribute.id,
|
||||
values: attribute.values.map(({ name }) => name),
|
||||
}));
|
||||
return [...updatedAttributes, ...notUpdatedAttributes];
|
||||
};
|
||||
|
||||
const byAvailability = (variant: ProductVariantBulkUpdateInput): boolean =>
|
||||
variant.name !== undefined ||
|
||||
variant.sku !== undefined ||
|
||||
|
|
Loading…
Reference in a new issue