Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix crash when changing product's type
dominik-zeglen9495953a44cf
diff --git a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsxindex 33b2643371..1098c876dd 100644--- a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx+++ b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx@@ -98,15 +98,29 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(() => data.productType.value.productAttributes,[]);- const getAttributeName = (slug: string) =>- unrolledAttributes.filter(a => a.slug === slug)[0].name;+ const getAttributeName = (slug: string) => {+ const match = unrolledAttributes.find(a => a.slug === slug);+ if (!match) {+ return "";+ }+ return match.name;+ };const getAttributeValue = (slug: string) => {if (unrolledAttributes.length > 0) {- const value = data.attributes.filter(a => a.slug === slug)[0];- const matches = unrolledAttributes- .filter(a => a.slug === slug)[0]- .values.filter(v => v.slug === value.value);- const label = matches.length > 0 ? matches[0].name : value.value;+ const value = data.attributes.find(a => a.slug === slug);+ const attributeMatch = unrolledAttributes.find(a => a.slug === slug);+ if (!attributeMatch) {+ return {+ label: "",+ value: ""+ };+ }+ const attributeValueMatch = attributeMatch.values.find(+ v => v.slug === value.value+ );+ const label = !!attributeValueMatch+ ? attributeValueMatch.name+ : value.value;return {label,value@@ -117,8 +131,14 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(value: ""};};- const getAttributeValues = (slug: string) =>- unrolledAttributes.filter(a => a.slug === slug)[0].values;+ const getAttributeValues = (slug: string) => {+ const match = unrolledAttributes.find(a => a.slug === slug);+ if (match) {+ return match.values;+ }++ return [];+ };const handleProductTypeSelect = (event: React.ChangeEvent<{name: string;