Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add attribute deleting

dominik-zeglenf044a38b1fc2
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
index b69cdd9c7f..c1c00d1e4d 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
@@ -1,11 +1,13 @@
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
+import IconButton from "@material-ui/core/IconButton";
import { withStyles } from "@material-ui/core/styles";
import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
+import DeleteIcon from "@material-ui/icons/Delete";
import * as React from "react";
import CardTitle from "../../../components/CardTitle";
@@ -31,22 +33,36 @@ interface ProductTypeAttributesProps {
data: ProductTypeAttributeEditDialogFormData,
type: AttributeTypeEnum
) => void;
+ onAttributeDelete: (id: string, event: React.MouseEvent<any>) => void;
onAttributeUpdate: (
id: string,
data: ProductTypeAttributeEditDialogFormData
) => void;
}
-const decorate = withStyles({
+const decorate = withStyles(theme => ({
+ iconCell: {
+ "&:last-child": {
+ paddingRight: 0
+ },
+ width: 48 + theme.spacing.unit / 2
+ },
link: {
cursor: "pointer" as "pointer"
},
textLeft: {
textAlign: "left" as "left"
}
-});
+}));
const ProductTypeAttributes = decorate<ProductTypeAttributesProps>(
- ({ attributes, classes, type, onAttributeAdd, onAttributeUpdate }) => (
+ ({
+ attributes,
+ classes,
+ type,
+ onAttributeAdd,
+ onAttributeDelete,
+ onAttributeUpdate
+ }) => (
<Toggle>
{(openedAttributeAddDialog, { toggle: toggleAttributeAddDialog }) => (
<>
@@ -74,6 +90,7 @@ const ProductTypeAttributes = decorate<ProductTypeAttributesProps>(
<TableCell className={classes.textLeft}>
{i18n.t("Values")}
</TableCell>
+ <TableCell />
</TableRow>
</TableHead>
<TableBody>
@@ -108,6 +125,15 @@ const ProductTypeAttributes = decorate<ProductTypeAttributesProps>(
<Skeleton />
)}
</TableCell>
+ <TableCell className={classes.iconCell}>
+ <IconButton
+ onClick={event =>
+ onAttributeDelete(attribute.id, event)
+ }
+ >
+ <DeleteIcon color="secondary" />
+ </IconButton>
+ </TableCell>
</TableRow>
<ProductTypeAttributeEditDialog
name={maybe(() => attribute.name)}
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
index 31da2c67e7..901b58534e 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
@@ -52,6 +52,7 @@ interface ProductTypeDetailsPageProps {
data: ProductTypeAttributeEditDialogFormData,
type: AttributeTypeEnum
) => void;
+ onAttributeDelete: (id: string, event: React.MouseEvent<any>) => void;
onAttributeUpdate: (
id: string,
data: ProductTypeAttributeEditDialogFormData
@@ -81,6 +82,7 @@ const ProductTypeDetailsPage = decorate<ProductTypeDetailsPageProps>(
productType,
saveButtonBarState,
onAttributeAdd,
+ onAttributeDelete,
onAttributeUpdate,
onBack,
onDelete,
@@ -143,6 +145,7 @@ const ProductTypeDetailsPage = decorate<ProductTypeDetailsPageProps>(
)}
type={AttributeTypeEnum.PRODUCT}
onAttributeAdd={onAttributeAdd}
+ onAttributeDelete={onAttributeDelete}
onAttributeUpdate={onAttributeUpdate}
/>
</div>
@@ -163,6 +166,7 @@ const ProductTypeDetailsPage = decorate<ProductTypeDetailsPageProps>(
)}
type={AttributeTypeEnum.VARIANT}
onAttributeAdd={onAttributeAdd}
+ onAttributeDelete={onAttributeDelete}
onAttributeUpdate={onAttributeUpdate}
/>
</div>
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
index c938a71ac0..ebc4356ec4 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
@@ -93,7 +93,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
>
{({
attributeCreate,
- // deleteAttribute,
+ deleteAttribute,
deleteProductType,
errors,
loading: mutationLoading,
@@ -137,8 +137,13 @@ export const ProductTypeUpdate: React.StatelessComponent<
},
type
});
- // const handleAttributeDelete = (id: string) =>
- // deleteAttribute.mutate({ id });
+ const handleAttributeDelete = (
+ id: string,
+ event: React.MouseEvent<any>
+ ) => {
+ event.stopPropagation();
+ deleteAttribute.mutate({ id });
+ };
const handleAttributeUpdate = (
id: string,
formData: AttributeForm
@@ -184,6 +189,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
productType={maybe(() => data.productType)}
saveButtonBarState={loading ? "loading" : "default"}
onAttributeAdd={handleAttributeCreate}
+ onAttributeDelete={handleAttributeDelete}
onAttributeUpdate={handleAttributeUpdate}
onBack={() => navigate(productTypeListUrl)}
onDelete={handleProductTypeDelete}