Fix label names in reference attributes (#1184)

* Fix label names in reference attributes

* Update changelog
This commit is contained in:
Dawid Tarasiuk 2021-06-22 10:00:00 +02:00 committed by GitHub
parent fb0e05538e
commit 8703c8d3c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 6 deletions

View file

@ -52,6 +52,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix attribute values input display - #1156 by @orzechdev
- Fix product type translations - #1163 by @orzechdev
- Support staff only voucher - #1174 by @orzechdev
- Fix label names in reference attributes - #1184 by @orzechdev
# 2.11.1

View file

@ -16,7 +16,11 @@ import {
AttributeInputTypeEnum,
AttributeValueInput
} from "@saleor/types/globalTypes";
import { mapNodeToChoice, mapPagesToChoices } from "@saleor/utils/maps";
import {
mapEdgesToItems,
mapNodeToChoice,
mapPagesToChoices
} from "@saleor/utils/maps";
import { MutationFetchResult } from "react-apollo";
import { AttributePageFormData } from "../components/AttributePage";
@ -144,6 +148,20 @@ export const mergeAttributeValueDeleteErrors = (
return errors;
}, []);
export const mergeChoicesWithValues = (
attribute:
| ProductDetails_product_attributes
| PageDetails_page_attributes
| SelectedVariantAttributeFragment
) => {
const choices = mapEdgesToItems(attribute.attribute.choices);
const valuesToConcat = attribute.values.filter(
value => !choices.some(choice => choice.id === value.id)
);
return choices.concat(valuesToConcat);
};
export const mergeAttributeValues = (
attributeId: string,
attributeValues: string[],

View file

@ -1,4 +1,7 @@
import { getSelectedAttributeValues } from "@saleor/attributes/utils/data";
import {
getSelectedAttributeValues,
mergeChoicesWithValues
} from "@saleor/attributes/utils/data";
import { AttributeInput } from "@saleor/components/Attributes";
import { mapEdgesToItems } from "@saleor/utils/maps";
@ -16,7 +19,7 @@ export function getAttributeInputFromPage(
inputType: attribute.attribute.inputType,
isRequired: attribute.attribute.valueRequired,
selectedValues: attribute.values,
values: mapEdgesToItems(attribute.attribute.choices),
values: mergeChoicesWithValues(attribute),
unit: attribute.attribute.unit
},
id: attribute.attribute.id,

View file

@ -1,4 +1,7 @@
import { getSelectedAttributeValues } from "@saleor/attributes/utils/data";
import {
getSelectedAttributeValues,
mergeChoicesWithValues
} from "@saleor/attributes/utils/data";
import { ChannelData } from "@saleor/channels/utils";
import {
AttributeInput,
@ -52,7 +55,7 @@ export function getAttributeInputFromProduct(
inputType: attribute.attribute.inputType,
isRequired: attribute.attribute.valueRequired,
selectedValues: attribute.values,
values: mapEdgesToItems(attribute.attribute.choices),
values: mergeChoicesWithValues(attribute),
unit: attribute.attribute.unit
},
id: attribute.attribute.id,
@ -109,7 +112,7 @@ export function getAttributeInputFromSelectedAttributes(
inputType: attribute.attribute.inputType,
isRequired: attribute.attribute.valueRequired,
selectedValues: attribute.values,
values: mapEdgesToItems(attribute.attribute.choices),
values: mergeChoicesWithValues(attribute),
unit: attribute.attribute.unit,
variantAttributeScope
},