saleor-dashboard/src/pages/utils/data.ts
Dawid Tarasiuk 11bddd3d1b
Product reference attributes (#948)
* Update changelog with product reference attributes

* 2068 - Add product reference type to attributes (#949)

* 2069 - Add product reference attribute search implementation (#951)
2021-01-20 17:37:36 +01:00

40 lines
1.1 KiB
TypeScript

import { getSelectedAttributeValues } from "@saleor/attributes/utils/data";
import { AttributeInput } from "@saleor/components/Attributes";
import {
PageDetails_page,
PageDetails_page_pageType
} from "../types/PageDetails";
export function getAttributeInputFromPage(
page: PageDetails_page
): AttributeInput[] {
return page?.attributes.map(attribute => ({
data: {
entityType: attribute.attribute.entityType,
inputType: attribute.attribute.inputType,
isRequired: attribute.attribute.valueRequired,
selectedValues: attribute.values,
values: attribute.attribute.values
},
id: attribute.attribute.id,
label: attribute.attribute.name,
value: getSelectedAttributeValues(attribute)
}));
}
export function getAttributeInputFromPageType(
pageType: PageDetails_page_pageType
): AttributeInput[] {
return pageType?.attributes.map(attribute => ({
data: {
entityType: attribute.entityType,
inputType: attribute.inputType,
isRequired: attribute.valueRequired,
values: attribute.values
},
id: attribute.id,
label: attribute.name,
value: []
}));
}