Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move bulk collection delete logic higher
dominik-zeglen055c851114c0
diff --git a/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsx b/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsxindex f8cb9e3e0b..6fa98cea70 100644--- a/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsx+++ b/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsx@@ -1,24 +1,20 @@-import Button from "@material-ui/core/Button";import Card from "@material-ui/core/Card";import Checkbox from "@material-ui/core/Checkbox";-import IconButton from "@material-ui/core/IconButton";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 TableRow from "@material-ui/core/TableRow";-import DeleteIcon from "@material-ui/icons/Delete";import * as React from "react";import Skeleton from "../../../components/Skeleton";import StatusLabel from "../../../components/StatusLabel";import TableHead from "../../../components/TableHead";import TablePagination from "../../../components/TablePagination";-import useBulkActions from "../../../hooks/useBulkActions";import i18n from "../../../i18n";import { maybe, renderCollection } from "../../../misc";-import { ListActionProps, ListProps } from "../../../types";+import { ListActions, ListProps } from "../../../types";import { CollectionList_collections_edges_node } from "../../types/CollectionList";const styles = createStyles({@@ -38,7 +34,7 @@ const styles = createStyles({interface CollectionListPropsextends ListProps,- ListActionProps<"onBulkPublish" | "onBulkUnpublish" | "onBulkDelete">,+ ListActions,WithStyles<typeof styles> {collections: CollectionList_collections_edges_node[];}@@ -48,142 +44,111 @@ const CollectionList = withStyles(styles, { name: "CollectionList" })(classes,collections,disabled,- onBulkDelete,- onBulkPublish,- onBulkUnpublish,onNextPage,onPreviousPage,onRowClick,- pageInfo- }: CollectionListProps) => {- const { isMember, listElements, toggle } = useBulkActions(collections);-- return (- <Card>- <Table>- <TableHead- selected={listElements.length}- toolbar={- <>- <Button- color="primary"- onClick={() => onBulkUnpublish(listElements)}- >- {i18n.t("Unpublish")}- </Button>- <Button- color="primary"- onClick={() => onBulkPublish(listElements)}+ pageInfo,+ isChecked,+ selected,+ toggle,+ toolbar+ }: CollectionListProps) => (+ <Card>+ <Table>+ <TableHead selected={selected} toolbar={toolbar}>+ <TableRow>+ <TableCell />+ <TableCell className={classes.name}>+ {i18n.t("Category Name", { context: "table cell" })}+ </TableCell>+ <TableCell className={classes.textCenter}>+ {i18n+ .t("No. Products", { context: "table cell" })+ .replace(" ", "\xa0")}+ </TableCell>+ <TableCell className={classes.textLeft}>+ {i18n.t("Availability", { context: "table cell" })}+ </TableCell>+ </TableRow>+ </TableHead>+ <TableFooter>+ <TableRow>+ <TablePagination+ colSpan={5}+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}+ onNextPage={onNextPage}+ hasPreviousPage={+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false+ }+ onPreviousPage={onPreviousPage}+ />+ </TableRow>+ </TableFooter>+ <TableBody>+ {renderCollection(+ collections,+ collection => {+ const isSelected = collection ? isChecked(collection.id) : false;+ return (+ <TableRow+ className={classes.tableRow}+ hover={!!collection}+ onClick={collection ? onRowClick(collection.id) : undefined}+ key={collection ? collection.id : "skeleton"}>- {i18n.t("Publish")}- </Button>- <IconButton- color="primary"- onClick={() => onBulkDelete(listElements)}- >- <DeleteIcon />- </IconButton>- </>- }- >- <TableRow>- <TableCell />- <TableCell className={classes.name}>- {i18n.t("Category Name", { context: "table cell" })}- </TableCell>- <TableCell className={classes.textCenter}>- {i18n- .t("No. Products", { context: "table cell" })- .replace(" ", "\xa0")}- </TableCell>- <TableCell className={classes.textLeft}>- {i18n.t("Availability", { context: "table cell" })}- </TableCell>- </TableRow>- </TableHead>- <TableFooter>- <TableRow>- <TablePagination- colSpan={5}- hasNextPage={- pageInfo && !disabled ? pageInfo.hasNextPage : false- }- onNextPage={onNextPage}- hasPreviousPage={- pageInfo && !disabled ? pageInfo.hasPreviousPage : false- }- onPreviousPage={onPreviousPage}- />- </TableRow>- </TableFooter>- <TableBody>- {renderCollection(- collections,- collection => {- const isSelected = collection ? isMember(collection.id) : false;- return (- <TableRow- className={classes.tableRow}- hover={!!collection}- onClick={collection ? onRowClick(collection.id) : undefined}- key={collection ? collection.id : "skeleton"}- >- <TableCell padding="checkbox">- <Checkbox- color="primary"- checked={isSelected}- disabled={disabled}- onClick={event => {- toggle(collection.id);- event.stopPropagation();- }}- />- </TableCell>- <TableCell>- {maybe<React.ReactNode>(- () => collection.name,- <Skeleton />- )}- </TableCell>- <TableCell className={classes.textCenter}>- {maybe<React.ReactNode>(- () => collection.products.totalCount,- <Skeleton />- )}- </TableCell>- <TableCell className={classes.textLeft}>- {maybe(- () => (- <StatusLabel- status={- collection.isPublished ? "success" : "error"- }- label={- collection.isPublished- ? i18n.t("Published")- : i18n.t("Not published")- }- />- ),- <Skeleton />- )}- </TableCell>- </TableRow>- );- },- () => (- <TableRow>- <TableCell colSpan={3}>- {i18n.t("No collections found")}+ <TableCell padding="checkbox">+ <Checkbox+ color="primary"+ checked={isSelected}+ disabled={disabled}+ onClick={event => {+ toggle(collection.id);+ event.stopPropagation();+ }}+ />+ </TableCell>+ <TableCell>+ {maybe<React.ReactNode>(+ () => collection.name,+ <Skeleton />+ )}+ </TableCell>+ <TableCell className={classes.textCenter}>+ {maybe<React.ReactNode>(+ () => collection.products.totalCount,+ <Skeleton />+ )}+ </TableCell>+ <TableCell className={classes.textLeft}>+ {maybe(+ () => (+ <StatusLabel+ status={collection.isPublished ? "success" : "error"}+ label={+ collection.isPublished+ ? i18n.t("Published")+ : i18n.t("Not published")+ }+ />+ ),+ <Skeleton />+ )}</TableCell></TableRow>- )- )}- </TableBody>- </Table>- </Card>- );- }+ );+ },+ () => (+ <TableRow>+ <TableCell colSpan={3}>+ {i18n.t("No collections found")}+ </TableCell>+ </TableRow>+ )+ )}+ </TableBody>+ </Table>+ </Card>+ ));CollectionList.displayName = "CollectionList";export default CollectionList;diff --git a/saleor/static/dashboard-next/collections/components/CollectionListPage/CollectionListPage.tsx b/saleor/static/dashboard-next/collections/components/CollectionListPage/CollectionListPage.tsxindex f1d7fc6f3c..9267008d57 100644--- a/saleor/static/dashboard-next/collections/components/CollectionListPage/CollectionListPage.tsx+++ b/saleor/static/dashboard-next/collections/components/CollectionListPage/CollectionListPage.tsx@@ -5,13 +5,11 @@ import * as React from "react";import { Container } from "../../../components/Container";import PageHeader from "../../../components/PageHeader";import i18n from "../../../i18n";-import { ListActionProps, PageListProps } from "../../../types";+import { ListActions, PageListProps } from "../../../types";import { CollectionList_collections_edges_node } from "../../types/CollectionList";import CollectionList from "../CollectionList/CollectionList";-export interface CollectionListPageProps- extends PageListProps,- ListActionProps<"onBulkPublish" | "onBulkUnpublish" | "onBulkDelete"> {+export interface CollectionListPageProps extends PageListProps, ListActions {collections: CollectionList_collections_edges_node[];}diff --git a/saleor/static/dashboard-next/collections/views/CollectionList.tsx b/saleor/static/dashboard-next/collections/views/CollectionList.tsxindex 3ab6bd19b3..ef4980aef6 100644--- a/saleor/static/dashboard-next/collections/views/CollectionList.tsx+++ b/saleor/static/dashboard-next/collections/views/CollectionList.tsx@@ -1,8 +1,12 @@+import Button from "@material-ui/core/Button";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 ActionDialog from "../../components/ActionDialog";import { createPaginationState } from "../../components/Paginator";+import useBulkActions from "../../hooks/useBulkActions";import useNavigator from "../../hooks/useNavigator";import useNotifier from "../../hooks/useNotifier";import usePaginator from "../../hooks/usePaginator";@@ -32,6 +36,7 @@ export const CollectionList: React.StatelessComponent<CollectionListProps> = ({const navigate = useNavigator();const notify = useNotifier();const paginate = usePaginator();+ const { isSelected, listElements, reset, toggle } = useBulkActions();const closeModal = () =>navigate(@@ -67,6 +72,7 @@ export const CollectionList: React.StatelessComponent<CollectionListProps> = ({text: i18n.t("Removed collections")});refetch();+ reset();navigate(collectionListUrl({...params,@@ -97,13 +103,35 @@ export const CollectionList: React.StatelessComponent<CollectionListProps> = ({collections={maybe(() =>data.collections.edges.map(edge => edge.node))}- onBulkDelete={ids => openModal("remove", ids)}- onBulkPublish={ids => openModal("publish", ids)}- onBulkUnpublish={ids => openModal("unpublish", ids)}onNextPage={loadNextPage}onPreviousPage={loadPreviousPage}pageInfo={pageInfo}onRowClick={id => () => navigate(collectionUrl(id))}+ toolbar={+ <>+ <Button+ color="primary"+ onClick={() => openModal("unpublish", listElements)}+ >+ {i18n.t("Unpublish")}+ </Button>+ <Button+ color="primary"+ onClick={() => openModal("publish", listElements)}+ >+ {i18n.t("Publish")}+ </Button>+ <IconButton+ color="primary"+ onClick={() => openModal("remove", listElements)}+ >+ <DeleteIcon />+ </IconButton>+ </>+ }+ isChecked={isSelected}+ selected={listElements.length}+ toggle={toggle}/><ActionDialogopen={params.action === "publish"}