Skip to content

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

Add bulk product unassign from collection

dominik-zeglen5bafc2a60fe4
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
index acaffb92f9..9ecb20cb22 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
@@ -12,7 +12,7 @@ import SaveButtonBar from "../../../components/SaveButtonBar";
import SeoForm from "../../../components/SeoForm";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
-import { PageListProps } from "../../../types";
+import { ListActions, PageListProps } from "../../../types";
import { CollectionDetails_collection } from "../../types/CollectionDetails";
import CollectionDetails from "../CollectionDetails/CollectionDetails";
import { CollectionImage } from "../CollectionImage/CollectionImage";
@@ -29,7 +29,7 @@ export interface CollectionDetailsPageFormData {
isPublished: boolean;
}
-export interface CollectionDetailsPageProps extends PageListProps {
+export interface CollectionDetailsPageProps extends PageListProps, ListActions {
collection: CollectionDetails_collection;
isFeatured: boolean;
saveButtonBarState: ConfirmButtonTransitionState;
diff --git a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
index 179fc60fbe..ba4d14fb0a 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
@@ -1,5 +1,6 @@
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,
@@ -11,7 +12,6 @@ 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";
@@ -20,10 +20,11 @@ import CardTitle from "../../../components/CardTitle";
import Skeleton from "../../../components/Skeleton";
import StatusLabel from "../../../components/StatusLabel";
import TableCellAvatar from "../../../components/TableCellAvatar";
+import TableHead from "../../../components/TableHead";
import TablePagination from "../../../components/TablePagination";
import i18n from "../../../i18n";
import { maybe, renderCollection } from "../../../misc";
-import { PageListProps } from "../../../types";
+import { ListActions, PageListProps } from "../../../types";
import { CollectionDetails_collection } from "../../types/CollectionDetails";
const styles = (theme: Theme) =>
@@ -41,6 +42,7 @@ const styles = (theme: Theme) =>
export interface CollectionProductsProps
extends PageListProps,
+ ListActions,
WithStyles<typeof styles> {
collection: CollectionDetails_collection;
onProductUnassign: (id: string, event: React.MouseEvent<any>) => void;
@@ -56,7 +58,11 @@ const CollectionProducts = withStyles(styles, { name: "CollectionProducts" })(
onPreviousPage,
onProductUnassign,
onRowClick,
- pageInfo
+ pageInfo,
+ isChecked,
+ selected,
+ toggle,
+ toolbar
}: CollectionProductsProps) => (
<Card>
<CardTitle
@@ -83,8 +89,9 @@ const CollectionProducts = withStyles(styles, { name: "CollectionProducts" })(
}
/>
<Table>
- <TableHead>
+ <TableHead selected={selected} toolbar={toolbar}>
<TableRow>
+ <TableCell />
<TableCell />
<TableCell>{i18n.t("Name", { context: "table header" })}</TableCell>
<TableCell>{i18n.t("Type", { context: "table header" })}</TableCell>
@@ -97,7 +104,7 @@ const CollectionProducts = withStyles(styles, { name: "CollectionProducts" })(
<TableFooter>
<TableRow>
<TablePagination
- colSpan={5}
+ colSpan={6}
hasNextPage={maybe(() => pageInfo.hasNextPage)}
onNextPage={onNextPage}
hasPreviousPage={maybe(() => pageInfo.hasPreviousPage)}
@@ -108,54 +115,69 @@ const CollectionProducts = withStyles(styles, { name: "CollectionProducts" })(
<TableBody>
{renderCollection(
maybe(() => collection.products.edges.map(edge => edge.node)),
- product => (
- <TableRow
- className={classes.tableRow}
- hover={!!product}
- onClick={!!product ? onRowClick(product.id) : undefined}
- key={product ? product.id : "skeleton"}
- >
- <TableCellAvatar
- thumbnail={maybe(() => product.thumbnail.url)}
- />
- <TableCell>
- {maybe<React.ReactNode>(() => product.name, <Skeleton />)}
- </TableCell>
- <TableCell>
- {maybe<React.ReactNode>(
- () => product.productType.name,
- <Skeleton />
- )}
- </TableCell>
- <TableCell>
- {maybe(
- () => (
- <StatusLabel
- label={
- product.isPublished
- ? i18n.t("Published")
- : i18n.t("Not published")
- }
- status={product.isPublished ? "success" : "error"}
- />
- ),
- <Skeleton />
- )}
- </TableCell>
- <TableCell className={classes.iconCell}>
- <IconButton
- disabled={!product}
- onClick={event => onProductUnassign(product.id, event)}
- >
- <DeleteIcon color="primary" />
- </IconButton>
- </TableCell>
- </TableRow>
- ),
+ product => {
+ const isSelected = product ? isChecked(product.id) : false;
+
+ return (
+ <TableRow
+ className={classes.tableRow}
+ hover={!!product}
+ onClick={!!product ? onRowClick(product.id) : undefined}
+ key={product ? product.id : "skeleton"}
+ >
+ <TableCell padding="checkbox">
+ <Checkbox
+ color="primary"
+ checked={isSelected}
+ disabled={disabled}
+ onClick={event => {
+ toggle(product.id);
+ event.stopPropagation();
+ }}
+ />
+ </TableCell>
+ <TableCellAvatar
+ thumbnail={maybe(() => product.thumbnail.url)}
+ />
+ <TableCell>
+ {maybe<React.ReactNode>(() => product.name, <Skeleton />)}
+ </TableCell>
+ <TableCell>
+ {maybe<React.ReactNode>(
+ () => product.productType.name,
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell>
+ {maybe(
+ () => (
+ <StatusLabel
+ label={
+ product.isPublished
+ ? i18n.t("Published")
+ : i18n.t("Not published")
+ }
+ status={product.isPublished ? "success" : "error"}
+ />
+ ),
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.iconCell}>
+ <IconButton
+ disabled={!product}
+ onClick={event => onProductUnassign(product.id, event)}
+ >
+ <DeleteIcon color="primary" />
+ </IconButton>
+ </TableCell>
+ </TableRow>
+ );
+ },
() => (
<TableRow>
<TableCell />
- <TableCell colSpan={5}>{i18n.t("No products found")}</TableCell>
+ <TableCell colSpan={6}>{i18n.t("No products found")}</TableCell>
</TableRow>
)
)}
diff --git a/saleor/static/dashboard-next/collections/mutations.ts b/saleor/static/dashboard-next/collections/mutations.ts
index 4997c7d81e..369a6c0992 100644
--- a/saleor/static/dashboard-next/collections/mutations.ts
+++ b/saleor/static/dashboard-next/collections/mutations.ts
@@ -163,7 +163,7 @@ export const TypedCollectionRemoveMutation = TypedMutation<
const unassignCollectionProduct = gql`
mutation UnassignCollectionProduct(
$collectionId: ID!
- $productId: ID!
+ $productIds: [ID]!
$first: Int
$after: String
$last: Int
@@ -171,7 +171,7 @@ const unassignCollectionProduct = gql`
) {
collectionRemoveProducts(
collectionId: $collectionId
- products: [$productId]
+ products: $productIds
) {
errors {
field
diff --git a/saleor/static/dashboard-next/collections/types/UnassignCollectionProduct.ts b/saleor/static/dashboard-next/collections/types/UnassignCollectionProduct.ts
index cf19ac584d..8501a0d0f3 100644
--- a/saleor/static/dashboard-next/collections/types/UnassignCollectionProduct.ts
+++ b/saleor/static/dashboard-next/collections/types/UnassignCollectionProduct.ts
@@ -64,7 +64,7 @@ export interface UnassignCollectionProduct {
export interface UnassignCollectionProductVariables {
collectionId: string;
- productId: string;
+ productIds: (string | null)[];
first?: number | null;
after?: string | null;
last?: number | null;
diff --git a/saleor/static/dashboard-next/collections/urls.ts b/saleor/static/dashboard-next/collections/urls.ts
index 2afe4a32d7..305fadbee1 100644
--- a/saleor/static/dashboard-next/collections/urls.ts
+++ b/saleor/static/dashboard-next/collections/urls.ts
@@ -14,8 +14,14 @@ export const collectionListUrl = (params?: CollectionListUrlQueryParams) =>
collectionSectionUrl + "?" + stringifyQs(params);
export const collectionPath = (id: string) => urlJoin(collectionSectionUrl, id);
-export type CollectionUrlDialog = "remove" | "removeImage" | "assign";
-export type CollectionUrlQueryParams = Pagination & Dialog<CollectionUrlDialog>;
+export type CollectionUrlDialog =
+ | "remove"
+ | "removeImage"
+ | "assign"
+ | "unassign";
+export type CollectionUrlQueryParams = BulkAction &
+ Pagination &
+ Dialog<CollectionUrlDialog>;
export const collectionUrl = (id: string, params?: CollectionUrlQueryParams) =>
collectionPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
diff --git a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
index 8497bc77fe..510e2935ae 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
@@ -1,13 +1,16 @@
+import Button from "@material-ui/core/Button";
import DialogContentText from "@material-ui/core/DialogContentText";
import * as React from "react";
import ActionDialog from "../../components/ActionDialog";
import AssignProductDialog from "../../components/AssignProductDialog";
-import { createPaginationState, Paginator } from "../../components/Paginator";
+import { createPaginationState } from "../../components/Paginator";
import { WindowTitle } from "../../components/WindowTitle";
import { SearchProductsProvider } from "../../containers/SearchProducts";
+import useBulkActions from "../../hooks/useBulkActions";
import useNavigator from "../../hooks/useNavigator";
import useNotifier from "../../hooks/useNotifier";
+import usePaginator from "../../hooks/usePaginator";
import i18n from "../../i18n";
import { getMutationState, maybe } from "../../misc";
import { productUrl } from "../../products/urls";
@@ -40,6 +43,8 @@ export const CollectionDetails: React.StatelessComponent<
> = ({ id, params }) => {
const navigate = useNavigator();
const notify = useNotifier();
+ const { isSelected, listElements, reset, toggle } = useBulkActions();
+ const paginate = usePaginator();
const closeModal = () =>
navigate(
@@ -106,6 +111,8 @@ export const CollectionDetails: React.StatelessComponent<
context: "notification"
})
});
+ reset();
+ closeModal();
}
};
@@ -188,6 +195,14 @@ export const CollectionDetails: React.StatelessComponent<
() => assignProduct.opts.data.collectionAddProducts.errors
)
);
+ const unassignTransitionState = getMutationState(
+ unassignProduct.opts.called,
+ unassignProduct.opts.loading,
+ maybe(
+ () =>
+ unassignProduct.opts.data.collectionRemoveProducts.errors
+ )
+ );
const removeTransitionState = getMutationState(
removeCollection.opts.called,
removeCollection.opts.loading,
@@ -199,53 +214,68 @@ export const CollectionDetails: React.StatelessComponent<
maybe(() => updateCollection.opts.data.collectionUpdate.errors)
);
+ const { loadNextPage, loadPreviousPage, pageInfo } = paginate(
+ maybe(() => data.collection.products.pageInfo),
+ paginationState,
+ params
+ );
+
return (
<>
<WindowTitle title={maybe(() => data.collection.name)} />
- <Paginator
- pageInfo={maybe(() => data.collection.products.pageInfo)}
- paginationState={paginationState}
- queryString={params}
- >
- {({ loadNextPage, loadPreviousPage, pageInfo }) => (
- <CollectionDetailsPage
- onAdd={() => openModal("assign")}
- onBack={() => navigate(collectionListUrl())}
- disabled={loading}
- collection={data.collection}
- isFeatured={maybe(
- () =>
- data.shop.homepageCollection.id ===
- data.collection.id,
- false
- )}
- onCollectionRemove={() => openModal("remove")}
- onImageDelete={() => openModal("removeImage")}
- onImageUpload={file =>
- updateCollection.mutate({
- id,
- input: {
- backgroundImage: file
- }
- })
- }
- onSubmit={handleSubmit}
- onNextPage={loadNextPage}
- onPreviousPage={loadPreviousPage}
- pageInfo={pageInfo}
- onProductUnassign={(productId, event) => {
- event.stopPropagation();
- unassignProduct.mutate({
- collectionId: id,
- productId,
- ...paginationState
- });
- }}
- onRowClick={id => () => navigate(productUrl(id))}
- saveButtonBarState={formTransitionState}
- />
+ <CollectionDetailsPage
+ onAdd={() => openModal("assign")}
+ onBack={() => navigate(collectionListUrl())}
+ disabled={loading}
+ collection={data.collection}
+ isFeatured={maybe(
+ () =>
+ data.shop.homepageCollection.id === data.collection.id,
+ false
)}
- </Paginator>
+ onCollectionRemove={() => openModal("remove")}
+ onImageDelete={() => openModal("removeImage")}
+ onImageUpload={file =>
+ updateCollection.mutate({
+ id,
+ input: {
+ backgroundImage: file
+ }
+ })
+ }
+ onSubmit={handleSubmit}
+ onNextPage={loadNextPage}
+ onPreviousPage={loadPreviousPage}
+ pageInfo={pageInfo}
+ onProductUnassign={(productId, event) => {
+ event.stopPropagation();
+ unassignProduct.mutate({
+ collectionId: id,
+ productIds: [productId],
+ ...paginationState
+ });
+ }}
+ onRowClick={id => () => navigate(productUrl(id))}
+ saveButtonBarState={formTransitionState}
+ toolbar={
+ <Button
+ color="primary"
+ onClick={() =>
+ navigate(
+ collectionUrl(id, {
+ action: "unassign",
+ ids: listElements
+ })
+ )
+ }
+ >
+ {i18n.t("Unassign")}
+ </Button>
+ }
+ isChecked={isSelected}
+ selected={listElements.length}
+ toggle={toggle}
+ />
<SearchProductsProvider>
{(searchProducts, searchProductsOpts) => (
<AssignProductDialog
@@ -296,6 +326,36 @@ export const CollectionDetails: React.StatelessComponent<
}}
/>
</ActionDialog>
+ <ActionDialog
+ confirmButtonState={unassignTransitionState}
+ onClose={closeModal}
+ onConfirm={() =>
+ unassignProduct.mutate({
+ ...paginationState,
+ collectionId: id,
+ productIds: params.ids
+ })
+ }
+ open={params.action === "unassign"}
+ title={i18n.t("Unassign products from collection", {
+ context: "modal title"
+ })}
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to unassign <strong>{{ number }}</strong> products?",
+ {
+ context: "modal",
+ number: maybe(
+ () => params.ids.length.toString(),
+ "..."
+ )
+ }
+ )
+ }}
+ />
+ </ActionDialog>
<ActionDialog
confirmButtonState={imageRemoveTransitionState}
onClose={closeModal}
diff --git a/saleor/static/dashboard-next/pages/components/PageList/PageList.tsx b/saleor/static/dashboard-next/pages/components/PageList/PageList.tsx
index 53b557cbb7..a0360dfefe 100644
--- a/saleor/static/dashboard-next/pages/components/PageList/PageList.tsx
+++ b/saleor/static/dashboard-next/pages/components/PageList/PageList.tsx
@@ -1,29 +1,23 @@
-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 { PageList_pages_edges_node } from "../../types/PageList";
-export interface PageListProps
- extends ListProps,
- ListActionProps<"onBulkDelete" | "onBulkPublish" | "onBulkUnpublish"> {
+export interface PageListProps extends ListProps, ListActions {
pages: PageList_pages_edges_node[];
}
@@ -37,131 +31,102 @@ const PageList = withStyles(styles, { name: "PageList" })(
classes,
pages,
disabled,
- onBulkDelete,
- onBulkPublish,
- onBulkUnpublish,
onNextPage,
pageInfo,
onRowClick,
- onPreviousPage
- }: PageListProps & WithStyles<typeof styles>) => {
- const { isMember, listElements, toggle } = useBulkActions(pages);
+ onPreviousPage,
+ isChecked,
+ selected,
+ toggle,
+ toolbar
+ }: PageListProps & WithStyles<typeof styles>) => (
+ <Card>
+ <Table>
+ <TableHead selected={selected} toolbar={toolbar}>
+ <TableRow>
+ <TableCell />
+ <TableCell padding="dense">
+ {i18n.t("Title", { context: "table header" })}
+ </TableCell>
+ <TableCell padding="dense">
+ {i18n.t("Slug", { context: "table header" })}
+ </TableCell>
+ <TableCell padding="dense">
+ {i18n.t("Visibility", { context: "table header" })}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableFooter>
+ <TableRow>
+ <TablePagination
+ colSpan={4}
+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
+ onNextPage={onNextPage}
+ hasPreviousPage={
+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false
+ }
+ onPreviousPage={onPreviousPage}
+ />
+ </TableRow>
+ </TableFooter>
+ <TableBody>
+ {renderCollection(
+ pages,
+ page => {
+ const isSelected = page ? isChecked(page.id) : false;
- return (
- <Card>
- <Table>
- <TableHead
- selected={listElements.length}
- toolbar={
- <>
- <Button
- color="primary"
- onClick={() => onBulkUnpublish(listElements)}
+ return (
+ <TableRow
+ hover={!!page}
+ className={!!page ? classes.link : undefined}
+ onClick={page ? onRowClick(page.id) : undefined}
+ key={page ? page.id : "skeleton"}
>
- {i18n.t("Unpublish")}
- </Button>
- <Button
- color="primary"
- onClick={() => onBulkPublish(listElements)}
- >
- {i18n.t("Publish")}
- </Button>
- <IconButton
- color="primary"
- onClick={() => onBulkDelete(listElements)}
- >
- <DeleteIcon />
- </IconButton>
- </>
- }
- >
- <TableRow>
- <TableCell />
- <TableCell padding="dense">
- {i18n.t("Title", { context: "table header" })}
- </TableCell>
- <TableCell padding="dense">
- {i18n.t("Slug", { context: "table header" })}
- </TableCell>
- <TableCell padding="dense">
- {i18n.t("Visibility", { context: "table header" })}
- </TableCell>
- </TableRow>
- </TableHead>
- <TableFooter>
- <TableRow>
- <TablePagination
- colSpan={4}
- hasNextPage={
- pageInfo && !disabled ? pageInfo.hasNextPage : false
- }
- onNextPage={onNextPage}
- hasPreviousPage={
- pageInfo && !disabled ? pageInfo.hasPreviousPage : false
- }
- onPreviousPage={onPreviousPage}
- />
- </TableRow>
- </TableFooter>
- <TableBody>
- {renderCollection(
- pages,
- page => {
- const isSelected = page ? isMember(page.id) : false;
-
- return (
- <TableRow
- hover={!!page}
- className={!!page ? classes.link : undefined}
- onClick={page ? onRowClick(page.id) : undefined}
- key={page ? page.id : "skeleton"}
- >
- <TableCell padding="checkbox">
- <Checkbox
- color="primary"
- checked={isSelected}
- disabled={disabled}
- onClick={event => {
- toggle(page.id);
- event.stopPropagation();
- }}
- />
- </TableCell>
- <TableCell>
- {maybe<React.ReactNode>(() => page.title, <Skeleton />)}
- </TableCell>
- <TableCell>
- {maybe<React.ReactNode>(() => page.slug, <Skeleton />)}
- </TableCell>
- <TableCell>
- {maybe<React.ReactNode>(
- () => (
- <StatusLabel
- label={
- page.isVisible
- ? i18n.t("Published")
- : i18n.t("Not Published")
- }
- status={page.isVisible ? "success" : "error"}
- />
- ),
- <Skeleton />
- )}
- </TableCell>
- </TableRow>
- );
- },
- () => (
- <TableRow>
- <TableCell colSpan={4}>{i18n.t("No pages found")}</TableCell>
+ <TableCell padding="checkbox">
+ <Checkbox
+ color="primary"
+ checked={isSelected}
+ disabled={disabled}
+ onClick={event => {
+ toggle(page.id);
+ event.stopPropagation();
+ }}
+ />
+ </TableCell>
+ <TableCell>
+ {maybe<React.ReactNode>(() => page.title, <Skeleton />)}
+ </TableCell>
+ <TableCell>
+ {maybe<React.ReactNode>(() => page.slug, <Skeleton />)}
+ </TableCell>
+ <TableCell>
+ {maybe<React.ReactNode>(
+ () => (
+ <StatusLabel
+ label={
+ page.isVisible
+ ? i18n.t("Published")
+ : i18n.t("Not Published")
+ }
+ status={page.isVisible ? "success" : "error"}
+ />
+ ),
+ <Skeleton />
+ )}
+ </TableCell>
</TableRow>
- )
- )}
- </TableBody>
- </Table>
- </Card>
- );
- }
+ );
+ },
+ () => (
+ <TableRow>
+ <TableCell colSpan={4}>{i18n.t("No pages found")}</TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
);
PageList.displayName = "PageList";
export default PageList;
diff --git a/saleor/static/dashboard-next/pages/components/PageListPage/PageListPage.tsx b/saleor/static/dashboard-next/pages/components/PageListPage/PageListPage.tsx
index 0f2cf24499..d8312b57ff 100644
--- a/saleor/static/dashboard-next/pages/components/PageListPage/PageListPage.tsx
+++ b/saleor/static/dashboard-next/pages/components/PageListPage/PageListPage.tsx
@@ -6,13 +6,11 @@ import AppHeader from "../../../components/AppHeader";
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 { PageList_pages_edges_node } from "../../types/PageList";
import PageList from "../PageList/PageList";
-export interface PageListPageProps
- extends PageListProps,
- ListActionProps<"onBulkPublish" | "onBulkUnpublish" | "onBulkDelete"> {
+export interface PageListPageProps extends PageListProps, ListActions {
pages: PageList_pages_edges_node[];
onBack: () => void;
}
@@ -21,14 +19,15 @@ const PageListPage: React.StatelessComponent<PageListPageProps> = ({
disabled,
onAdd,
onBack,
- onBulkDelete,
- onBulkPublish,
- onBulkUnpublish,
onNextPage,
onPreviousPage,
onRowClick,
pageInfo,
- pages
+ pages,
+ isChecked,
+ selected,
+ toggle,
+ toolbar
}) => (
<Container>
<AppHeader onBack={onBack}>{i18n.t("Configuration")}</AppHeader>
@@ -46,13 +45,14 @@ const PageListPage: React.StatelessComponent<PageListPageProps> = ({
<PageList
disabled={disabled}
pages={pages}
- onBulkDelete={onBulkDelete}
- onBulkPublish={onBulkPublish}
- onBulkUnpublish={onBulkUnpublish}
onNextPage={onNextPage}
onPreviousPage={onPreviousPage}
onRowClick={onRowClick}
pageInfo={pageInfo}
+ isChecked={isChecked}
+ selected={selected}
+ toggle={toggle}
+ toolbar={toolbar}
/>
</Container>
);
diff --git a/saleor/static/dashboard-next/pages/views/PageList.tsx b/saleor/static/dashboard-next/pages/views/PageList.tsx
index 10aea74192..23ecb77759 100644
--- a/saleor/static/dashboard-next/pages/views/PageList.tsx
+++ b/saleor/static/dashboard-next/pages/views/PageList.tsx
@@ -1,9 +1,13 @@
+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 { configurationMenuUrl } from "../../configuration";
+import useBulkActions from "../../hooks/useBulkActions";
import useNavigator from "../../hooks/useNavigator";
import useNotifier from "../../hooks/useNotifier";
import usePaginator from "../../hooks/usePaginator";
@@ -39,6 +43,7 @@ export const PageList: React.StatelessComponent<PageListProps> = ({
const navigate = useNavigator();
const notify = useNotifier();
const paginate = usePaginator();
+ const { isSelected, listElements, reset, toggle } = useBulkActions();
const paginationState = createPaginationState(PAGINATE_BY, params);
@@ -76,6 +81,7 @@ export const PageList: React.StatelessComponent<PageListProps> = ({
notify({
text: i18n.t("Published pages")
});
+ reset();
refetch();
}
};
@@ -86,6 +92,7 @@ export const PageList: React.StatelessComponent<PageListProps> = ({
notify({
text: i18n.t("Unpublished pages")
});
+ reset();
refetch();
}
};
@@ -101,6 +108,7 @@ export const PageList: React.StatelessComponent<PageListProps> = ({
notify({
text: i18n.t("Removed pages")
});
+ reset();
refetch();
}
};
@@ -147,12 +155,40 @@ export const PageList: React.StatelessComponent<PageListProps> = ({
pageInfo={pageInfo}
onAdd={() => navigate(pageCreateUrl)}
onBack={() => navigate(configurationMenuUrl)}
- onBulkDelete={ids => openModal("remove", ids)}
- onBulkPublish={ids => openModal("publish", ids)}
- onBulkUnpublish={ids => openModal("unpublish", ids)}
onNextPage={loadNextPage}
onPreviousPage={loadPreviousPage}
onRowClick={id => () => navigate(pageUrl(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}
/>
<ActionDialog
open={params.action === "publish"}