Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extract data if object is checked to its own variable
dominik-zeglen7891834ae4fe
diff --git a/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx b/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsxindex 3133de1432..b8a92b914f 100644--- a/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx+++ b/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx@@ -109,47 +109,47 @@ const AssignCategoriesDialog = withStyles(styles, {<Table><TableBody>{categories &&- categories.map(category => (- <TableRow key={category.id}>- <TableCell- padding="checkbox"- className={classes.checkboxCell}- >- <Checkbox- checked={- !!data.categories.find(- selectedCategories =>- selectedCategories.id === category.id- )- }- onChange={() =>- data.categories.find(- selectedCategories =>- selectedCategories.id === category.id- )- ? change({- target: {- name: "categories",- value: data.categories.filter(- selectedCategories =>- selectedCategories.id !== category.id- )- }- } as any)- : change({- target: {- name: "categories",- value: [...data.categories, category]- }- } as any)- }- />- </TableCell>- <TableCell className={classes.wideCell}>- {category.name}- </TableCell>- </TableRow>- ))}+ categories.map(category => {+ const isChecked = !!data.categories.find(+ selectedCategories =>+ selectedCategories.id === category.id+ );++ return (+ <TableRow key={category.id}>+ <TableCell+ padding="checkbox"+ className={classes.checkboxCell}+ >+ <Checkbox+ checked={isChecked}+ onChange={() =>+ isChecked+ ? change({+ target: {+ name: "categories",+ value: data.categories.filter(+ selectedCategories =>+ selectedCategories.id !==+ category.id+ )+ }+ } as any)+ : change({+ target: {+ name: "categories",+ value: [...data.categories, category]+ }+ } as any)+ }+ />+ </TableCell>+ <TableCell className={classes.wideCell}>+ {category.name}+ </TableCell>+ </TableRow>+ );+ })}</TableBody></Table></DialogContent>diff --git a/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx b/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsxindex a8f061f007..3431a23587 100644--- a/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx+++ b/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx@@ -109,47 +109,47 @@ const AssignCollectionDialog = withStyles(styles, {<Table><TableBody>{collections &&- collections.map(category => (- <TableRow key={category.id}>- <TableCell- padding="checkbox"- className={classes.checkboxCell}- >- <Checkbox- checked={- !!data.collections.find(- selectedCollection =>- selectedCollection.id === category.id- )- }- onChange={() =>- data.collections.find(- selectedCollection =>- selectedCollection.id === category.id- )- ? change({- target: {- name: "collections",- value: data.collections.filter(- selectedCollection =>- selectedCollection.id !== category.id- )- }- } as any)- : change({- target: {- name: "collections",- value: [...data.collections, category]- }- } as any)- }- />- </TableCell>- <TableCell className={classes.wideCell}>- {category.name}- </TableCell>- </TableRow>- ))}+ collections.map(category => {+ const isChecked = !!data.collections.find(+ selectedCollection =>+ selectedCollection.id === category.id+ );++ return (+ <TableRow key={category.id}>+ <TableCell+ padding="checkbox"+ className={classes.checkboxCell}+ >+ <Checkbox+ checked={isChecked}+ onChange={() =>+ isChecked+ ? change({+ target: {+ name: "collections",+ value: data.collections.filter(+ selectedCollection =>+ selectedCollection.id !==+ category.id+ )+ }+ } as any)+ : change({+ target: {+ name: "collections",+ value: [...data.collections, category]+ }+ } as any)+ }+ />+ </TableCell>+ <TableCell className={classes.wideCell}>+ {category.name}+ </TableCell>+ </TableRow>+ );+ })}</TableBody></Table></DialogContent>diff --git a/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx b/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsxindex 6dfaee8069..a86974d3d3 100644--- a/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx+++ b/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx@@ -110,51 +110,49 @@ const AssignProductDialog = withStyles(styles, {<Table><TableBody>{products &&- products.map(product => (- <TableRow key={product.id}>- <TableCellAvatar- className={classes.avatar}- thumbnail={product.thumbnail.url}- />- <TableCell className={classes.wideCell}>- {product.name}- </TableCell>- <TableCell- padding="checkbox"- className={classes.checkboxCell}- >- <Checkbox- checked={- !!data.products.find(- selectedProduct =>- selectedProduct.id === product.id- )- }- onChange={() =>- data.products.find(- selectedProduct =>- selectedProduct.id === product.id- )- ? change({- target: {- name: "products",- value: data.products.filter(- selectedProduct =>- selectedProduct.id !== product.id- )- }- } as any)- : change({- target: {- name: "products",- value: [...data.products, product]- }- } as any)- }+ products.map(product => {+ const isChecked = !!data.products.find(+ selectedProduct => selectedProduct.id === product.id+ );++ return (+ <TableRow key={product.id}>+ <TableCellAvatar+ className={classes.avatar}+ thumbnail={product.thumbnail.url}/>- </TableCell>- </TableRow>- ))}+ <TableCell className={classes.wideCell}>+ {product.name}+ </TableCell>+ <TableCell+ padding="checkbox"+ className={classes.checkboxCell}+ >+ <Checkbox+ checked={isChecked}+ onChange={() =>+ isChecked+ ? change({+ target: {+ name: "products",+ value: data.products.filter(+ selectedProduct =>+ selectedProduct.id !== product.id+ )+ }+ } as any)+ : change({+ target: {+ name: "products",+ value: [...data.products, product]+ }+ } as any)+ }+ />+ </TableCell>+ </TableRow>+ );+ })}</TableBody></Table></DialogContent>diff --git a/saleor/static/dashboard-next/discounts/components/DiscountCountrySelectDialog/DiscountCountrySelectDialog.tsx b/saleor/static/dashboard-next/discounts/components/DiscountCountrySelectDialog/DiscountCountrySelectDialog.tsxindex e4f7c84fcf..641274f103 100644--- a/saleor/static/dashboard-next/discounts/components/DiscountCountrySelectDialog/DiscountCountrySelectDialog.tsx+++ b/saleor/static/dashboard-next/discounts/components/DiscountCountrySelectDialog/DiscountCountrySelectDialog.tsx@@ -96,47 +96,45 @@ const DiscountCountrySelectDialog = withStyles(styles, {<TableBody>{filter(countries, data.query, {key: "country"- }).map(country => (- <TableRow key={country.code}>- <TableCell className={classes.wideCell}>- {country.country}- </TableCell>- <TableCell- padding="checkbox"- className={classes.checkboxCell}- >- <Checkbox- checked={- !!data.countries.find(- selectedCountries =>- selectedCountries === country.code- )- }- onChange={() =>- data.countries.find(- selectedCountries =>- selectedCountries === country.code- )- ? change({- target: {- name: "countries" as keyof FormData,- value: data.countries.filter(- selectedCountries =>- selectedCountries !== country.code- )- }- } as any)- : change({- target: {- name: "countries" as keyof FormData,- value: [...data.countries, country.code]- }- } as any)- }- />- </TableCell>- </TableRow>- ))}+ }).map(country => {+ const isChecked = !!data.countries.find(+ selectedCountries => selectedCountries === country.code+ );++ return (+ <TableRow key={country.code}>+ <TableCell className={classes.wideCell}>+ {country.country}+ </TableCell>+ <TableCell+ padding="checkbox"+ className={classes.checkboxCell}+ >+ <Checkbox+ checked={isChecked}+ onChange={() =>+ isChecked+ ? change({+ target: {+ name: "countries" as keyof FormData,+ value: data.countries.filter(+ selectedCountries =>+ selectedCountries !== country.code+ )+ }+ } as any)+ : change({+ target: {+ name: "countries" as keyof FormData,+ value: [...data.countries, country.code]+ }+ } as any)+ }+ />+ </TableCell>+ </TableRow>+ );+ })}</TableBody></Table></DialogContent>