Skip to content

Commit

Permalink
Fix label names in reference attributes (#1184)
Browse files Browse the repository at this point in the history
* Fix label names in reference attributes

* Update changelog
  • Loading branch information
orzechdev authored and jwm0 committed Jun 22, 2021
1 parent a2c8935 commit 3dfd0ed
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Add product / page delete warning - #1095 by @mmarkusik
- Channels per plugin - #1093 by @mmarkusik
- Support staff only voucher - #1174 by @orzechdev
- Fix label names in reference attributes - #1184 by @orzechdev

# 2.11.1

Expand Down
20 changes: 19 additions & 1 deletion src/attributes/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -134,6 +138,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[],
Expand Down
7 changes: 5 additions & 2 deletions src/pages/utils/data.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -15,7 +18,7 @@ export function getAttributeInputFromPage(
inputType: attribute.attribute.inputType,
isRequired: attribute.attribute.valueRequired,
selectedValues: attribute.values,
values: attribute.attribute.values,
values: mergeChoicesWithValues(attribute),
unit: attribute.attribute.unit
},
id: attribute.attribute.id,
Expand Down
9 changes: 6 additions & 3 deletions src/products/utils/data.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -52,7 +55,7 @@ export function getAttributeInputFromProduct(
inputType: attribute.attribute.inputType,
isRequired: attribute.attribute.valueRequired,
selectedValues: attribute.values,
values: attribute.attribute.values,
values: mergeChoicesWithValues(attribute),
unit: attribute.attribute.unit
},
id: attribute.attribute.id,
Expand Down Expand Up @@ -109,7 +112,7 @@ export function getAttributeInputFromSelectedAttributes(
inputType: attribute.attribute.inputType,
isRequired: attribute.attribute.valueRequired,
selectedValues: attribute.values,
values: attribute.attribute.values,
values: mergeChoicesWithValues(attribute),
unit: attribute.attribute.unit,
variantAttributeScope
},
Expand Down

0 comments on commit 3dfd0ed

Please sign in to comment.