Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add bulk sale delete
dominik-zeglen62f509a682d3
diff --git a/saleor/static/dashboard-next/discounts/components/SaleList/SaleList.tsx b/saleor/static/dashboard-next/discounts/components/SaleList/SaleList.tsxindex 02c36356a6..60a9f8c2ba 100644--- a/saleor/static/dashboard-next/discounts/components/SaleList/SaleList.tsx+++ b/saleor/static/dashboard-next/discounts/components/SaleList/SaleList.tsx@@ -1,10 +1,10 @@import Card from "@material-ui/core/Card";+import Checkbox from "@material-ui/core/Checkbox";import { createStyles, 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 * as React from "react";@@ -12,14 +12,15 @@ import Date from "../../../components/Date";import Money from "../../../components/Money";import Percent from "../../../components/Percent";import Skeleton from "../../../components/Skeleton";+import TableHead from "../../../components/TableHead";import TablePagination from "../../../components/TablePagination";import i18n from "../../../i18n";import { maybe, renderCollection } from "../../../misc";-import { ListProps } from "../../../types";+import { ListActions, ListProps } from "../../../types";import { SaleType } from "../../../types/globalTypes";import { SaleList_sales_edges_node } from "../../types/SaleList";-export interface SaleListProps extends ListProps {+export interface SaleListProps extends ListProps, ListActions {defaultCurrency: string;sales: SaleList_sales_edges_node[];}@@ -47,12 +48,17 @@ const SaleList = withStyles(styles, {onPreviousPage,onRowClick,pageInfo,- sales+ sales,+ isChecked,+ selected,+ toggle,+ toolbar}: SaleListProps & WithStyles<typeof styles>) => (<Card><Table>- <TableHead>+ <TableHead selected={selected} toolbar={toolbar}><TableRow>+ <TableCell /><TableCell className={classes.wideColumn}>{i18n.t("Name", {context: "sale list table header"@@ -78,7 +84,7 @@ const SaleList = withStyles(styles, {<TableFooter><TableRow><TablePagination- colSpan={4}+ colSpan={5}hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}onNextPage={onNextPage}hasPreviousPage={@@ -91,58 +97,72 @@ const SaleList = withStyles(styles, {<TableBody>{renderCollection(sales,- sale => (- <TableRow- className={!!sale ? classes.tableRow : undefined}- hover={!!sale}- key={sale ? sale.id : "skeleton"}- >- <TableCell- className={classes.textRight}- onClick={sale ? onRowClick(sale.id) : undefined}- >- {maybe<React.ReactNode>(() => sale.name, <Skeleton />)}- </TableCell>- <TableCell className={classes.textRight}>- {sale && sale.startDate ? (- <Date date={sale.startDate} />- ) : (- <Skeleton />- )}- </TableCell>- <TableCell className={classes.textRight}>- {sale && sale.endDate ? (- <Date date={sale.endDate} />- ) : sale && sale.endDate === null ? (- "-"- ) : (- <Skeleton />- )}- </TableCell>- <TableCell- className={classes.textRight}+ sale => {+ const isSelected = sale ? isChecked(sale.id) : false;++ return (+ <TableRow+ className={!!sale ? classes.tableRow : undefined}+ hover={!!sale}+ key={sale ? sale.id : "skeleton"}onClick={sale ? onRowClick(sale.id) : undefined}+ selected={isSelected}>- {sale && sale.type && sale.value ? (- sale.type === SaleType.FIXED ? (- <Money- money={{- amount: sale.value,- currency: defaultCurrency- }}- />+ <TableCell padding="checkbox">+ <Checkbox+ color="primary"+ checked={isSelected}+ disabled={disabled}+ onClick={event => {+ toggle(sale.id);+ event.stopPropagation();+ }}+ />+ </TableCell>+ <TableCell>+ {maybe<React.ReactNode>(() => sale.name, <Skeleton />)}+ </TableCell>+ <TableCell className={classes.textRight}>+ {sale && sale.startDate ? (+ <Date date={sale.startDate} />) : (- <Percent amount={sale.value} />- )- ) : (- <Skeleton />- )}- </TableCell>- </TableRow>- ),+ <Skeleton />+ )}+ </TableCell>+ <TableCell className={classes.textRight}>+ {sale && sale.endDate ? (+ <Date date={sale.endDate} />+ ) : sale && sale.endDate === null ? (+ "-"+ ) : (+ <Skeleton />+ )}+ </TableCell>+ <TableCell+ className={classes.textRight}+ onClick={sale ? onRowClick(sale.id) : undefined}+ >+ {sale && sale.type && sale.value ? (+ sale.type === SaleType.FIXED ? (+ <Money+ money={{+ amount: sale.value,+ currency: defaultCurrency+ }}+ />+ ) : (+ <Percent amount={sale.value} />+ )+ ) : (+ <Skeleton />+ )}+ </TableCell>+ </TableRow>+ );+ },() => (<TableRow>- <TableCell colSpan={4}>{i18n.t("No sales found")}</TableCell>+ <TableCell colSpan={5}>{i18n.t("No sales found")}</TableCell></TableRow>))}diff --git a/saleor/static/dashboard-next/discounts/components/SaleListPage/SaleListPage.tsx b/saleor/static/dashboard-next/discounts/components/SaleListPage/SaleListPage.tsxindex cfcd4c81bd..3958967db4 100644--- a/saleor/static/dashboard-next/discounts/components/SaleListPage/SaleListPage.tsx+++ b/saleor/static/dashboard-next/discounts/components/SaleListPage/SaleListPage.tsx@@ -5,24 +5,18 @@ import * as React from "react";import Container from "../../../components/Container";import PageHeader from "../../../components/PageHeader";import i18n from "../../../i18n";-import { PageListProps } from "../../../types";+import { ListActions, PageListProps } from "../../../types";import { SaleList_sales_edges_node } from "../../types/SaleList";import SaleList from "../SaleList";-export interface SaleListPageProps extends PageListProps {+export interface SaleListPageProps extends PageListProps, ListActions {defaultCurrency: string;sales: SaleList_sales_edges_node[];}const SaleListPage: React.StatelessComponent<SaleListPageProps> = ({- defaultCurrency,- disabled,onAdd,- onNextPage,- onPreviousPage,- onRowClick,- pageInfo,- sales+ ...listProps}) => (<Container><PageHeader title={i18n.t("Sales")}>@@ -31,15 +25,7 @@ const SaleListPage: React.StatelessComponent<SaleListPageProps> = ({<AddIcon /></Button></PageHeader>- <SaleList- defaultCurrency={defaultCurrency}- disabled={disabled}- onNextPage={onNextPage}- onPreviousPage={onPreviousPage}- onRowClick={onRowClick}- pageInfo={pageInfo}- sales={sales}- />+ <SaleList {...listProps} /></Container>);SaleListPage.displayName = "SaleListPage";diff --git a/saleor/static/dashboard-next/discounts/views/SaleList.tsx b/saleor/static/dashboard-next/discounts/views/SaleList.tsxindex aa03bcf290..49eeec5ce8 100644--- a/saleor/static/dashboard-next/discounts/views/SaleList.tsx+++ b/saleor/static/dashboard-next/discounts/views/SaleList.tsx@@ -1,64 +1,143 @@+import DialogContentText from "@material-ui/core/DialogContentText";+import IconButton from "@material-ui/core/IconButton";+import DeleteIcon from "@material-ui/icons/Delete";import * as React from "react";-import Navigator from "../../components/Navigator";-import { createPaginationState, Paginator } from "../../components/Paginator";-import Shop from "../../components/Shop";+import ActionDialog from "../../components/ActionDialog";+import { createPaginationState } from "../../components/Paginator";import { WindowTitle } from "../../components/WindowTitle";+import useBulkActions from "../../hooks/useBulkActions";+import useNavigator from "../../hooks/useNavigator";+import useNotifier from "../../hooks/useNotifier";+import usePaginator from "../../hooks/usePaginator";+import useShop from "../../hooks/useShop";import i18n from "../../i18n";-import { maybe } from "../../misc";-import { Pagination } from "../../types";+import { getMutationState, maybe } from "../../misc";import SaleListPage from "../components/SaleListPage";+import { TypedSaleBulkDelete } from "../mutations";import { TypedSaleList } from "../queries";-import { saleAddUrl, saleUrl } from "../urls";+import { SaleBulkDelete } from "../types/SaleBulkDelete";+import {+ saleAddUrl,+ saleListUrl,+ SaleListUrlQueryParams,+ saleUrl+} from "../urls";const PAGINATE_BY = 20;-export type SaleListQueryParams = Pagination;-interface SaleListProps {- params: SaleListQueryParams;+ params: SaleListUrlQueryParams;}export const SaleList: React.StatelessComponent<SaleListProps> = ({params-}) => (- <>- <WindowTitle title={i18n.t("Sales")} />- <Shop>- {shop => (- <Navigator>- {navigate => {- const paginationState = createPaginationState(PAGINATE_BY, params);- return (- <TypedSaleList displayLoader variables={paginationState}>- {({ data, loading }) => (- <Paginator- pageInfo={maybe(() => data.sales.pageInfo)}- paginationState={paginationState}- queryString={params}+}) => {+ const navigate = useNavigator();+ const notify = useNotifier();+ const paginate = usePaginator();+ const shop = useShop();+ const { isSelected, listElements, reset, toggle } = useBulkActions();++ const closeModal = () => navigate(saleListUrl(), true);++ const paginationState = createPaginationState(PAGINATE_BY, params);++ return (+ <TypedSaleList displayLoader variables={paginationState}>+ {({ data, loading, refetch }) => {+ const { loadNextPage, loadPreviousPage, pageInfo } = paginate(+ maybe(() => data.sales.pageInfo),+ paginationState,+ params+ );++ const handleSaleBulkDelete = (data: SaleBulkDelete) => {+ if (data.saleBulkDelete.errors.length === 0) {+ notify({+ text: i18n.t("Removed sales")+ });+ reset();+ closeModal();+ refetch();+ }+ };++ return (+ <TypedSaleBulkDelete onCompleted={handleSaleBulkDelete}>+ {(saleBulkDelete, saleBulkDeleteOpts) => {+ const bulkRemoveTransitionState = getMutationState(+ saleBulkDeleteOpts.called,+ saleBulkDeleteOpts.loading,+ maybe(() => saleBulkDeleteOpts.data.saleBulkDelete.errors)+ );+ const onSaleBulkDelete = () =>+ saleBulkDelete({+ variables: {+ ids: params.ids+ }+ });++ return (+ <>+ <WindowTitle title={i18n.t("Sales")} />+ <SaleListPage+ defaultCurrency={maybe(() => shop.defaultCurrency)}+ sales={maybe(() => data.sales.edges.map(edge => edge.node))}+ disabled={loading}+ pageInfo={pageInfo}+ onAdd={() => navigate(saleAddUrl)}+ onNextPage={loadNextPage}+ onPreviousPage={loadPreviousPage}+ onRowClick={id => () => navigate(saleUrl(id))}+ isChecked={isSelected}+ selected={listElements.length}+ toggle={toggle}+ toolbar={+ <IconButton+ color="primary"+ onClick={() =>+ navigate(+ saleListUrl({+ action: "remove",+ ids: listElements+ })+ )+ }+ >+ <DeleteIcon />+ </IconButton>+ }+ />+ <ActionDialog+ confirmButtonState={bulkRemoveTransitionState}+ onClose={closeModal}+ onConfirm={onSaleBulkDelete}+ open={params.action === "remove"}+ title={i18n.t("Remove Sales")}+ variant="delete">- {({ loadNextPage, loadPreviousPage, pageInfo }) => (- <SaleListPage- defaultCurrency={maybe(() => shop.defaultCurrency)}- sales={maybe(() =>- data.sales.edges.map(edge => edge.node)- )}- disabled={loading}- pageInfo={pageInfo}- onAdd={() => navigate(saleAddUrl)}- onNextPage={loadNextPage}- onPreviousPage={loadPreviousPage}- onRowClick={id => () => navigate(saleUrl(id))}- />- )}- </Paginator>- )}- </TypedSaleList>- );- }}- </Navigator>- )}- </Shop>- </>-);+ <DialogContentText+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "Are you sure you want to remove <strong>{{ number }}</strong> sales?",+ {+ number: maybe(+ () => params.ids.length.toString(),+ "..."+ )+ }+ )+ }}+ />+ </ActionDialog>+ </>+ );+ }}+ </TypedSaleBulkDelete>+ );+ }}+ </TypedSaleList>+ );+};export default SaleList;