Skip to content

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

Add unassigning

dominik-zeglena3b6dbce5473
diff --git a/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx b/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx
index 938a0d7f17..05c739c0c1 100644
--- a/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx
+++ b/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx
@@ -1,12 +1,19 @@
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
-import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
+import IconButton from "@material-ui/core/IconButton";
+import {
+ createStyles,
+ Theme,
+ withStyles,
+ 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 TableFooter from "@material-ui/core/TableFooter";
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";
@@ -21,19 +28,27 @@ import { VoucherDetails_voucher } from "../../types/VoucherDetails";
export interface DiscountCategoriesProps extends ListProps {
discount: SaleDetails_sale | VoucherDetails_voucher;
onCategoryAssign: () => void;
+ onCategoryUnassign: (id: string) => void;
}
-const styles = createStyles({
- tableRow: {
- cursor: "pointer"
- },
- textRight: {
- textAlign: "right"
- },
- wideColumn: {
- width: "60%"
- }
-});
+const styles = (theme: Theme) =>
+ createStyles({
+ iconCell: {
+ "&:last-child": {
+ paddingRight: 0
+ },
+ width: 48 + theme.spacing.unit / 2
+ },
+ tableRow: {
+ cursor: "pointer"
+ },
+ textRight: {
+ textAlign: "right"
+ },
+ wideColumn: {
+ width: "60%"
+ }
+ });
const DiscountCategories = withStyles(styles, {
name: "DiscountCategories"
})(
@@ -43,6 +58,7 @@ const DiscountCategories = withStyles(styles, {
disabled,
pageInfo,
onCategoryAssign,
+ onCategoryUnassign,
onRowClick,
onPreviousPage,
onNextPage
@@ -67,12 +83,13 @@ const DiscountCategories = withStyles(styles, {
<TableCell className={classes.textRight}>
{i18n.t("Products")}
</TableCell>
+ <TableCell />
</TableRow>
</TableHead>
<TableFooter>
<TableRow>
<TablePagination
- colSpan={5}
+ colSpan={3}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
hasPreviousPage={
@@ -101,11 +118,22 @@ const DiscountCategories = withStyles(styles, {
<Skeleton />
)}
</TableCell>
+ <TableCell className={classes.iconCell}>
+ <IconButton
+ disabled={!category || disabled}
+ onClick={event => {
+ event.stopPropagation();
+ onCategoryUnassign(category.id);
+ }}
+ >
+ <DeleteIcon color="secondary" />
+ </IconButton>
+ </TableCell>
</TableRow>
),
() => (
<TableRow>
- <TableCell colSpan={2}>
+ <TableCell colSpan={3}>
{i18n.t("No categories found")}
</TableCell>
</TableRow>
diff --git a/saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsx b/saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsx
index 07c95f60e0..429f7bf13a 100644
--- a/saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsx
+++ b/saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsx
@@ -1,12 +1,19 @@
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
-import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
+import IconButton from "@material-ui/core/IconButton";
+import {
+ createStyles,
+ Theme,
+ withStyles,
+ 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 TableFooter from "@material-ui/core/TableFooter";
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";
@@ -21,19 +28,27 @@ import { VoucherDetails_voucher } from "../../types/VoucherDetails";
export interface DiscountCollectionsProps extends ListProps {
discount: SaleDetails_sale | VoucherDetails_voucher;
onCollectionAssign: () => void;
+ onCollectionUnassign: (id: string) => void;
}
-const styles = createStyles({
- tableRow: {
- cursor: "pointer"
- },
- textRight: {
- textAlign: "right"
- },
- wideColumn: {
- width: "60%"
- }
-});
+const styles = (theme: Theme) =>
+ createStyles({
+ iconCell: {
+ "&:last-child": {
+ paddingRight: 0
+ },
+ width: 48 + theme.spacing.unit / 2
+ },
+ tableRow: {
+ cursor: "pointer"
+ },
+ textRight: {
+ textAlign: "right"
+ },
+ wideColumn: {
+ width: "60%"
+ }
+ });
const DiscountCollections = withStyles(styles, {
name: "DiscountCollections"
})(
@@ -43,6 +58,7 @@ const DiscountCollections = withStyles(styles, {
disabled,
pageInfo,
onCollectionAssign,
+ onCollectionUnassign,
onRowClick,
onPreviousPage,
onNextPage
@@ -67,12 +83,13 @@ const DiscountCollections = withStyles(styles, {
<TableCell className={classes.textRight}>
{i18n.t("Products")}
</TableCell>
+ <TableCell />
</TableRow>
</TableHead>
<TableFooter>
<TableRow>
<TablePagination
- colSpan={5}
+ colSpan={3}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
hasPreviousPage={
@@ -101,11 +118,22 @@ const DiscountCollections = withStyles(styles, {
<Skeleton />
)}
</TableCell>
+ <TableCell className={classes.iconCell}>
+ <IconButton
+ disabled={!collection || disabled}
+ onClick={event => {
+ event.stopPropagation();
+ onCollectionUnassign(collection.id);
+ }}
+ >
+ <DeleteIcon color="secondary" />
+ </IconButton>
+ </TableCell>
</TableRow>
),
() => (
<TableRow>
- <TableCell colSpan={2}>
+ <TableCell colSpan={3}>
{i18n.t("No collections found")}
</TableCell>
</TableRow>
diff --git a/saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsx b/saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsx
index dbc01ede1a..df86837cdf 100644
--- a/saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsx
+++ b/saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsx
@@ -95,7 +95,7 @@ const DiscountProducts = withStyles(styles, {
<TableFooter>
<TableRow>
<TablePagination
- colSpan={4}
+ colSpan={5}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
hasPreviousPage={
@@ -158,7 +158,7 @@ const DiscountProducts = withStyles(styles, {
),
() => (
<TableRow>
- <TableCell colSpan={4}>{i18n.t("No products found")}</TableCell>
+ <TableCell colSpan={5}>{i18n.t("No products found")}</TableCell>
</TableRow>
)
)}
diff --git a/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx b/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
index 27368ea033..031714ebeb 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
@@ -51,11 +51,13 @@ export interface SaleDetailsPageProps
saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void;
onCategoryAssign: () => void;
+ onCategoryUnassign: (id: string) => void;
onCategoryClick: (id: string) => () => void;
onCollectionAssign: () => void;
- onProductUnassign: (id: string) => void;
+ onCollectionUnassign: (id: string) => void;
onCollectionClick: (id: string) => () => void;
onProductAssign: () => void;
+ onProductUnassign: (id: string) => void;
onProductClick: (id: string) => () => void;
onRemove: () => void;
onSubmit: (data: FormData) => void;
@@ -79,8 +81,10 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
saveButtonBarState,
onBack,
onCategoryAssign,
+ onCategoryUnassign,
onCategoryClick,
onCollectionAssign,
+ onCollectionUnassign,
onCollectionClick,
onNextPage,
onPreviousPage,
@@ -157,6 +161,7 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
<DiscountCategories
disabled={disabled}
onCategoryAssign={onCategoryAssign}
+ onCategoryUnassign={onCategoryUnassign}
onNextPage={onNextPage}
onPreviousPage={onPreviousPage}
onRowClick={onCategoryClick}
@@ -167,6 +172,7 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
<DiscountCollections
disabled={disabled}
onCollectionAssign={onCollectionAssign}
+ onCollectionUnassign={onCollectionUnassign}
onNextPage={onNextPage}
onPreviousPage={onPreviousPage}
onRowClick={onCollectionClick}
diff --git a/saleor/static/dashboard-next/discounts/views/SaleDetails/index.tsx b/saleor/static/dashboard-next/discounts/views/SaleDetails/index.tsx
index 805f03ec99..aded8428a7 100644
--- a/saleor/static/dashboard-next/discounts/views/SaleDetails/index.tsx
+++ b/saleor/static/dashboard-next/discounts/views/SaleDetails/index.tsx
@@ -184,6 +184,28 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
true
)
}
+ onCollectionUnassign={collectionId =>
+ saleCataloguesRemove({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ collections: [collectionId]
+ }
+ }
+ })
+ }
+ onCategoryUnassign={categoryId =>
+ saleCataloguesRemove({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ categories: [categoryId]
+ }
+ }
+ })
+ }
onCollectionClick={id => () =>
navigate(collectionUrl(id))}
onProductAssign={() =>