Skip to content

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

Add category bulk delete

dominik-zeglen02e8bd994324
diff --git a/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx b/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx
index ffb5f34e10..3c0b92b8ae 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx
@@ -1,20 +1,24 @@
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 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";
import Skeleton from "../../../components/Skeleton";
+import TableHead from "../../../components/TableHead";
import TablePagination from "../../../components/TablePagination";
+import useBulkActions from "../../../hooks/useBulkActions";
import i18n from "../../../i18n";
import { renderCollection } from "../../../misc";
-import { ListProps } from "../../../types";
+import { ListActionProps, ListProps } from "../../../types";
const styles = createStyles({
centerText: {
@@ -28,7 +32,10 @@ const styles = createStyles({
}
});
-interface CategoryListProps extends ListProps, WithStyles<typeof styles> {
+interface CategoryListProps
+ extends ListProps,
+ ListActionProps<"onBulkDelete">,
+ WithStyles<typeof styles> {
categories?: Array<{
id: string;
name: string;
@@ -48,100 +55,135 @@ const CategoryList = withStyles(styles, { name: "CategoryList" })(
categories,
classes,
disabled,
+ isRoot,
pageInfo,
+ onAdd,
+ onBulkDelete,
onNextPage,
onPreviousPage,
- isRoot,
- onAdd,
onRowClick
- }: CategoryListProps) => (
- <Card>
- {!isRoot && (
- <CardTitle
- title={i18n.t("All Subcategories")}
- toolbar={
- <Button color="primary" variant="text" onClick={onAdd}>
- {i18n.t("Add subcategory")}
- </Button>
- }
- />
- )}
- <Table>
- <TableHead>
- <TableRow>
- <TableCell className={classes.wideColumn}>
- {i18n.t("Category Name", { context: "object" })}
- </TableCell>
- <TableCell className={classes.centerText}>
- {i18n.t("Subcategories", { context: "object" })}
- </TableCell>
- <TableCell className={classes.centerText}>
- {i18n
- .t("No. Products", { context: "object" })
- .replace(" ", "\xa0")}
- </TableCell>
- </TableRow>
- </TableHead>
- <TableFooter>
- <TableRow>
- <TablePagination
- colSpan={3}
- hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
- onNextPage={onNextPage}
- hasPreviousPage={
- pageInfo && !disabled ? pageInfo.hasPreviousPage : false
- }
- onPreviousPage={onPreviousPage}
- />
- </TableRow>
- </TableFooter>
- <TableBody>
- {renderCollection(
- categories,
- category => (
- <TableRow
- className={classes.tableRow}
- hover={!!category}
- onClick={category ? onRowClick(category.id) : undefined}
- key={category ? category.id : "skeleton"}
+ }: CategoryListProps) => {
+ const { isMember: isChecked, listElements, toggle } = useBulkActions(
+ categories
+ );
+
+ return (
+ <Card>
+ {!isRoot && (
+ <CardTitle
+ title={i18n.t("All Subcategories")}
+ toolbar={
+ <Button color="primary" variant="text" onClick={onAdd}>
+ {i18n.t("Add subcategory")}
+ </Button>
+ }
+ />
+ )}
+ <Table>
+ <TableHead
+ selected={listElements.length}
+ toolbar={
+ <IconButton
+ color="primary"
+ onClick={() => onBulkDelete(listElements)}
>
- <TableCell>
- {category && category.name ? category.name : <Skeleton />}
- </TableCell>
- <TableCell className={classes.centerText}>
- {category &&
- category.children &&
- category.children.totalCount !== undefined ? (
- category.children.totalCount
- ) : (
- <Skeleton />
- )}
- </TableCell>
- <TableCell className={classes.centerText}>
- {category &&
- category.products &&
- category.products.totalCount !== undefined ? (
- category.products.totalCount
- ) : (
- <Skeleton />
- )}
- </TableCell>
- </TableRow>
- ),
- () => (
- <TableRow>
- <TableCell colSpan={3}>
- {isRoot
- ? i18n.t("No categories found")
- : i18n.t("No subcategories found")}
- </TableCell>
- </TableRow>
- )
- )}
- </TableBody>
- </Table>
- </Card>
- )
+ <DeleteIcon />
+ </IconButton>
+ }
+ >
+ <TableRow>
+ <TableCell />
+ <TableCell className={classes.wideColumn}>
+ {i18n.t("Category Name", { context: "object" })}
+ </TableCell>
+ <TableCell className={classes.centerText}>
+ {i18n.t("Subcategories", { context: "object" })}
+ </TableCell>
+ <TableCell className={classes.centerText}>
+ {i18n
+ .t("No. Products", { context: "object" })
+ .replace(" ", "\xa0")}
+ </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(
+ categories,
+ category => {
+ const isSelected = category ? isChecked(category.id) : false;
+
+ return (
+ <TableRow
+ className={classes.tableRow}
+ hover={!!category}
+ onClick={category ? onRowClick(category.id) : undefined}
+ key={category ? category.id : "skeleton"}
+ >
+ <TableCell padding="checkbox">
+ <Checkbox
+ color="primary"
+ checked={isSelected}
+ disabled={disabled}
+ onClick={event => {
+ toggle(category.id);
+ event.stopPropagation();
+ }}
+ />
+ </TableCell>
+ <TableCell className={classes.wideColumn}>
+ {category && category.name ? category.name : <Skeleton />}
+ </TableCell>
+ <TableCell className={classes.centerText}>
+ {category &&
+ category.children &&
+ category.children.totalCount !== undefined ? (
+ category.children.totalCount
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.centerText}>
+ {category &&
+ category.products &&
+ category.products.totalCount !== undefined ? (
+ category.products.totalCount
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ );
+ },
+ () => (
+ <TableRow>
+ <TableCell colSpan={4}>
+ {isRoot
+ ? i18n.t("No categories found")
+ : i18n.t("No subcategories found")}
+ </TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ );
+ }
);
CategoryList.displayName = "CategoryList";
export default CategoryList;
diff --git a/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsx b/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsx
index 82b8a758de..b91e30544b 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsx
@@ -5,10 +5,12 @@ import * as React from "react";
import Container from "../../../components/Container";
import PageHeader from "../../../components/PageHeader";
import i18n from "../../../i18n";
-import { PageListProps } from "../../../types";
+import { ListActionProps, PageListProps } from "../../../types";
import CategoryList from "../CategoryList";
-export interface CategoryTableProps extends PageListProps {
+export interface CategoryTableProps
+ extends PageListProps,
+ ListActionProps<"onBulkDelete"> {
categories: Array<{
id: string;
name: string;
@@ -25,13 +27,14 @@ export const CategoryListPage: React.StatelessComponent<CategoryTableProps> = ({
categories,
disabled,
onAdd,
+ onBulkDelete,
onNextPage,
onPreviousPage,
onRowClick,
pageInfo
}) => (
<Container>
- <PageHeader title={i18n.t("Category")}>
+ <PageHeader title={i18n.t("Categories")}>
<Button color="primary" variant="contained" onClick={onAdd}>
{i18n.t("Add category")} <AddIcon />
</Button>
@@ -39,6 +42,7 @@ export const CategoryListPage: React.StatelessComponent<CategoryTableProps> = ({
<CategoryList
categories={categories}
onAdd={onAdd}
+ onBulkDelete={onBulkDelete}
onRowClick={onRowClick}
disabled={disabled}
isRoot={true}
diff --git a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
index 818976394a..aed6536ac2 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
@@ -13,7 +13,7 @@ import { Tab } from "../../../components/Tab";
import TabContainer from "../../../components/Tab/TabContainer";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
-import { UserError, ListActionProps } from "../../../types";
+import { ListActionProps, UserError } from "../../../types";
import CategoryDetailsForm from "../../components/CategoryDetailsForm";
import CategoryList from "../../components/CategoryList";
import {
@@ -38,7 +38,7 @@ export enum CategoryPageTab {
}
export interface CategoryUpdatePageProps
- extends ListActionProps<"onBulkProductDelete"> {
+ extends ListActionProps<"onBulkCategoryDelete" | "onBulkProductDelete"> {
changeTab: (index: CategoryPageTab) => void;
currentTab: CategoryPageTab;
errors: UserError[];
@@ -82,6 +82,7 @@ export const CategoryUpdatePage: React.StatelessComponent<
onAddCategory,
onAddProduct,
onBack,
+ onBulkCategoryDelete,
onBulkProductDelete,
onCategoryClick,
onDelete,
@@ -168,6 +169,7 @@ export const CategoryUpdatePage: React.StatelessComponent<
isRoot={false}
categories={subcategories}
onAdd={onAddCategory}
+ onBulkDelete={onBulkCategoryDelete}
onRowClick={onCategoryClick}
onNextPage={onNextPage}
onPreviousPage={onPreviousPage}
diff --git a/saleor/static/dashboard-next/categories/index.tsx b/saleor/static/dashboard-next/categories/index.tsx
index 100593eccb..12af20f0a9 100644
--- a/saleor/static/dashboard-next/categories/index.tsx
+++ b/saleor/static/dashboard-next/categories/index.tsx
@@ -6,14 +6,13 @@ import i18n from "../i18n";
import {
categoryAddPath,
categoryListPath,
+ CategoryListUrlQueryParams,
categoryPath,
CategoryUrlQueryParams
} from "./urls";
import { CategoryCreateView } from "./views/CategoryCreate";
import CategoryDetailsView, { getActiveTab } from "./views/CategoryDetails";
-import CategoryListComponent, {
- CategoryListQueryParams
-} from "./views/CategoryList";
+import CategoryListComponent from "./views/CategoryList";
interface CategoryDetailsRouteParams {
id: string;
@@ -53,10 +52,7 @@ const CategoryList: React.StatelessComponent<RouteComponentProps<{}>> = ({
location
}) => {
const qs = parseQs(location.search.substr(1));
- const params: CategoryListQueryParams = {
- after: qs.after,
- before: qs.before
- };
+ const params: CategoryListUrlQueryParams = qs;
return <CategoryListComponent params={params} />;
};
diff --git a/saleor/static/dashboard-next/categories/mutations.ts b/saleor/static/dashboard-next/categories/mutations.ts
index 89c8f9379f..715aa4bbfe 100644
--- a/saleor/static/dashboard-next/categories/mutations.ts
+++ b/saleor/static/dashboard-next/categories/mutations.ts
@@ -2,6 +2,10 @@ import gql from "graphql-tag";
import { TypedMutation } from "../mutations";
import { categoryDetailsFragment } from "./queries";
+import {
+ CategoryBulkDelete,
+ CategoryBulkDeleteVariables
+} from "./types/CategoryBulkDelete";
import {
CategoryCreate,
CategoryCreateVariables
@@ -67,3 +71,18 @@ export const TypedCategoryUpdateMutation = TypedMutation<
CategoryUpdate,
CategoryUpdateVariables
>(categoryUpdateMutation);
+
+export const categoryBulkDeleteMutation = gql`
+ mutation CategoryBulkDelete($ids: [ID]!) {
+ categoryBulkDelete(ids: $ids) {
+ errors {
+ field
+ message
+ }
+ }
+ }
+`;
+export const TypedCategoryBulkDeleteMutation = TypedMutation<
+ CategoryBulkDelete,
+ CategoryBulkDeleteVariables
+>(categoryBulkDeleteMutation);
diff --git a/saleor/static/dashboard-next/categories/types/CategoryBulkDelete.ts b/saleor/static/dashboard-next/categories/types/CategoryBulkDelete.ts
new file mode 100644
index 0000000000..7824cbe3fc
--- /dev/null
+++ b/saleor/static/dashboard-next/categories/types/CategoryBulkDelete.ts
@@ -0,0 +1,26 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL mutation operation: CategoryBulkDelete
+// ====================================================
+
+export interface CategoryBulkDelete_categoryBulkDelete_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface CategoryBulkDelete_categoryBulkDelete {
+ __typename: "CategoryBulkDelete";
+ errors: CategoryBulkDelete_categoryBulkDelete_errors[] | null;
+}
+
+export interface CategoryBulkDelete {
+ categoryBulkDelete: CategoryBulkDelete_categoryBulkDelete | null;
+}
+
+export interface CategoryBulkDeleteVariables {
+ ids: (string | null)[];
+}
diff --git a/saleor/static/dashboard-next/categories/urls.ts b/saleor/static/dashboard-next/categories/urls.ts
index abc6a6ab8d..09c92f9d22 100644
--- a/saleor/static/dashboard-next/categories/urls.ts
+++ b/saleor/static/dashboard-next/categories/urls.ts
@@ -7,7 +7,12 @@ import { CategoryPageTab } from "./components/CategoryUpdatePage";
const categorySectionUrl = "/categories/";
export const categoryListPath = categorySectionUrl;
-export const categoryListUrl = categorySectionUrl;
+export type CategoryListUrlDialog = "delete";
+export type CategoryListUrlQueryParams = BulkAction &
+ Dialog<CategoryListUrlDialog> &
+ Pagination;
+export const categoryListUrl = (params?: CategoryListUrlQueryParams) =>
+ categorySectionUrl + "?" + stringifyQs(params);
export const categoryPath = (id: string) => urlJoin(categorySectionUrl, id);
export type CategoryUrlDialog =
diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails.tsx b/saleor/static/dashboard-next/categories/views/CategoryDetails.tsx
index 32697fb264..b43a32e03c 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryDetails.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails.tsx
@@ -18,10 +18,12 @@ import {
CategoryUpdatePage
} from "../components/CategoryUpdatePage/CategoryUpdatePage";
import {
+ TypedCategoryBulkDeleteMutation,
TypedCategoryDeleteMutation,
TypedCategoryUpdateMutation
} from "../mutations";
import { TypedCategoryDetailsQuery } from "../queries";
+import { CategoryBulkDelete } from "../types/CategoryBulkDelete";
import { CategoryDelete } from "../types/CategoryDelete";
import { CategoryUpdate } from "../types/CategoryUpdate";
import {
@@ -124,6 +126,18 @@ export const CategoryDetails: React.StatelessComponent<
require={["category"]}
>
{({ data, loading, refetch }) => {
+ const handleBulkCategoryDelete = (
+ data: CategoryBulkDelete
+ ) => {
+ if (data.categoryBulkDelete.errors.length === 0) {
+ closeModal();
+ notify({
+ text: i18n.t("Categories removed")
+ });
+ refetch();
+ }
+ };
+
const handleBulkProductDelete = (data: productBulkDelete) => {
if (data.productBulkDelete.errors.length === 0) {
closeModal();
@@ -143,161 +157,217 @@ export const CategoryDetails: React.StatelessComponent<
return (
<>
<WindowTitle title={maybe(() => data.category.name)} />
- <TypedProductBulkDeleteMutation
- onCompleted={handleBulkProductDelete}
+ <TypedCategoryBulkDeleteMutation
+ onCompleted={handleBulkCategoryDelete}
>
- {(productBulkDelete, productBulkDeleteOpts) => {
- const bulkDeleteMutationState = getMutationState(
- productBulkDeleteOpts.called,
- productBulkDeleteOpts.loading,
- maybe(
- () =>
- productBulkDeleteOpts.data.productBulkDelete
- .errors
- )
- );
+ {(categoryBulkDelete, categoryBulkDeleteOpts) => (
+ <TypedProductBulkDeleteMutation
+ onCompleted={handleBulkProductDelete}
+ >
+ {(productBulkDelete, productBulkDeleteOpts) => {
+ const categoryBulkDeleteMutationState = getMutationState(
+ categoryBulkDeleteOpts.called,
+ categoryBulkDeleteOpts.loading,
+ maybe(
+ () =>
+ categoryBulkDeleteOpts.data
+ .categoryBulkDelete.errors
+ )
+ );
+ const productBulkDeleteMutationState = getMutationState(
+ productBulkDeleteOpts.called,
+ productBulkDeleteOpts.loading,
+ maybe(
+ () =>
+ productBulkDeleteOpts.data.productBulkDelete
+ .errors
+ )
+ );
- return (
- <>
- <CategoryUpdatePage
- changeTab={changeTab}
- currentTab={params.activeTab}
- category={maybe(() => data.category)}
- disabled={loading}
- errors={maybe(
- () => updateResult.data.categoryUpdate.errors
- )}
- onAddCategory={() =>
- navigate(categoryAddUrl(id))
- }
- onAddProduct={() => navigate(productAddUrl)}
- onBack={() =>
- navigate(
- maybe(
+ return (
+ <>
+ <CategoryUpdatePage
+ changeTab={changeTab}
+ currentTab={params.activeTab}
+ category={maybe(() => data.category)}
+ disabled={loading}
+ errors={maybe(
() =>
- categoryUrl(data.category.parent.id),
- categoryListUrl
- )
- )
- }
- onBulkProductDelete={ids =>
- openModal("delete-products", ids)
- }
- onCategoryClick={id => () =>
- navigate(categoryUrl(id))}
- onDelete={() => openModal("delete")}
- onImageDelete={() =>
- updateCategory({
- variables: {
- id,
- input: {
- backgroundImage: null
- }
+ updateResult.data.categoryUpdate.errors
+ )}
+ onAddCategory={() =>
+ navigate(categoryAddUrl(id))
+ }
+ onAddProduct={() => navigate(productAddUrl)}
+ onBack={() =>
+ navigate(
+ maybe(
+ () =>
+ categoryUrl(
+ data.category.parent.id
+ ),
+ categoryListUrl()
+ )
+ )
+ }
+ onBulkCategoryDelete={ids =>
+ openModal("delete-categories", ids)
+ }
+ onBulkProductDelete={ids =>
+ openModal("delete-products", ids)
}
- })
- }
- onImageUpload={file =>
- updateCategory({
- variables: {
- id,
- input: {
- backgroundImage: file
- }
+ onCategoryClick={id => () =>
+ navigate(categoryUrl(id))}
+ onDelete={() => openModal("delete")}
+ onImageDelete={() =>
+ updateCategory({
+ variables: {
+ id,
+ input: {
+ backgroundImage: null
+ }
+ }
+ })
+ }
+ onImageUpload={file =>
+ updateCategory({
+ variables: {
+ id,
+ input: {
+ backgroundImage: file
+ }
+ }
+ })
}
- })
- }
- onNextPage={loadNextPage}
- onPreviousPage={loadPreviousPage}
- pageInfo={pageInfo}
- onProductClick={id => () =>
- navigate(productUrl(id))}
- onSubmit={formData =>
- updateCategory({
- variables: {
- id,
- input: {
- backgroundImageAlt:
- formData.backgroundImageAlt,
- descriptionJson: JSON.stringify(
- formData.description
- ),
- name: formData.name,
- seo: {
- description: formData.seoDescription,
- title: formData.seoTitle
+ onNextPage={loadNextPage}
+ onPreviousPage={loadPreviousPage}
+ pageInfo={pageInfo}
+ onProductClick={id => () =>
+ navigate(productUrl(id))}
+ onSubmit={formData =>
+ updateCategory({
+ variables: {
+ id,
+ input: {
+ backgroundImageAlt:
+ formData.backgroundImageAlt,
+ descriptionJson: JSON.stringify(
+ formData.description
+ ),
+ name: formData.name,
+ seo: {
+ description:
+ formData.seoDescription,
+ title: formData.seoTitle
+ }
+ }
}
- }
+ })
+ }
+ products={maybe(() =>
+ data.category.products.edges.map(
+ edge => edge.node
+ )
+ )}
+ saveButtonBarState={formTransitionState}
+ subcategories={maybe(() =>
+ data.category.children.edges.map(
+ edge => edge.node
+ )
+ )}
+ />
+ <ActionDialog
+ confirmButtonState={
+ removeDialogTransitionState
+ }
+ onClose={() => closeModal}
+ onConfirm={() =>
+ deleteCategory({ variables: { id } })
+ }
+ open={params.action === "delete"}
+ title={i18n.t("Delete category", {
+ context: "modal title"
+ })}
+ variant="delete"
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ categoryName }}</strong>?",
+ {
+ categoryName: maybe(
+ () => data.category.name
+ ),
+ context: "modal message"
+ }
+ )
+ }}
+ />
+ </ActionDialog>
+ <ActionDialog
+ open={params.action === "delete-categories"}
+ confirmButtonState={
+ categoryBulkDeleteMutationState
+ }
+ onClose={closeModal}
+ onConfirm={() =>
+ categoryBulkDelete({
+ variables: { ids: params.ids }
+ })
+ }
+ title={i18n.t("Remove categories")}
+ variant="delete"
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ number }}</strong> categories?",
+ {
+ number: maybe(
+ () =>
+ params.ids.length.toString(),
+ "..."
+ )
+ }
+ )
+ }}
+ />
+ </ActionDialog>
+ <ActionDialog
+ open={params.action === "delete-products"}
+ confirmButtonState={
+ productBulkDeleteMutationState
+ }
+ onClose={closeModal}
+ onConfirm={() =>
+ productBulkDelete({
+ variables: { ids: params.ids }
+ })
}
- })
- }
- products={maybe(() =>
- data.category.products.edges.map(
- edge => edge.node
- )
- )}
- saveButtonBarState={formTransitionState}
- subcategories={maybe(() =>
- data.category.children.edges.map(
- edge => edge.node
- )
- )}
- />
- <ActionDialog
- confirmButtonState={removeDialogTransitionState}
- onClose={() => closeModal}
- onConfirm={() =>
- deleteCategory({ variables: { id } })
- }
- open={params.action === "delete"}
- title={i18n.t("Delete category", {
- context: "modal title"
- })}
- variant="delete"
- >
- <DialogContentText
- dangerouslySetInnerHTML={{
- __html: i18n.t(
- "Are you sure you want to remove <strong>{{ categoryName }}</strong>?",
- {
- categoryName: maybe(
- () => data.category.name
- ),
- context: "modal message"
- }
- )
- }}
- />
- </ActionDialog>
- <ActionDialog
- open={params.action === "delete-products"}
- confirmButtonState={bulkDeleteMutationState}
- onClose={closeModal}
- onConfirm={() =>
- productBulkDelete({
- variables: { ids: params.ids }
- })
- }
- title={i18n.t("Remove products")}
- variant="delete"
- >
- <DialogContentText
- dangerouslySetInnerHTML={{
- __html: i18n.t(
- "Are you sure you want to remove <strong>{{ number }}</strong> products?",
- {
- number: maybe(
- () => params.ids.length.toString(),
- "..."
+ title={i18n.t("Remove products")}
+ variant="delete"
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ number }}</strong> products?",
+ {
+ number: maybe(
+ () =>
+ params.ids.length.toString(),
+ "..."
+ )
+ }
)
- }
- )
- }}
- />
- </ActionDialog>
- </>
- );
- }}
- </TypedProductBulkDeleteMutation>
+ }}
+ />
+ </ActionDialog>
+ </>
+ );
+ }}
+ </TypedProductBulkDeleteMutation>
+ )}
+ </TypedCategoryBulkDeleteMutation>
</>
);
}}
diff --git a/saleor/static/dashboard-next/categories/views/CategoryList.tsx b/saleor/static/dashboard-next/categories/views/CategoryList.tsx
index 8f49619656..86795300f5 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryList.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryList.tsx
@@ -1,54 +1,130 @@
+import DialogContentText from "@material-ui/core/DialogContentText";
import * as React from "react";
-import Navigator from "../../components/Navigator";
-import { createPaginationState, Paginator } from "../../components/Paginator";
-import { maybe } from "../../misc";
-import { Pagination } from "../../types";
+import ActionDialog from "../../components/ActionDialog";
+import { createPaginationState } from "../../components/Paginator";
+import useNavigator from "../../hooks/useNavigator";
+import usePaginator from "../../hooks/usePaginator";
+import i18n from "../../i18n";
+import { getMutationState, maybe } from "../../misc";
import { CategoryListPage } from "../components/CategoryListPage/CategoryListPage";
+import { TypedCategoryBulkDeleteMutation } from "../mutations";
import { TypedRootCategoriesQuery } from "../queries";
-import { categoryAddUrl, categoryUrl } from "../urls";
-
-export type CategoryListQueryParams = Pagination;
+import { CategoryBulkDelete } from "../types/CategoryBulkDelete";
+import {
+ categoryAddUrl,
+ categoryListUrl,
+ CategoryListUrlQueryParams,
+ categoryUrl
+} from "../urls";
interface CategoryListProps {
- params: CategoryListQueryParams;
+ params: CategoryListUrlQueryParams;
}
const PAGINATE_BY = 20;
export const CategoryList: React.StatelessComponent<CategoryListProps> = ({
params
-}) => (
- <Navigator>
- {navigate => {
- const paginationState = createPaginationState(PAGINATE_BY, params);
- return (
- <TypedRootCategoriesQuery displayLoader variables={paginationState}>
- {({ data, loading }) => (
- <Paginator
- pageInfo={maybe(() => data.categories.pageInfo)}
- paginationState={paginationState}
- queryString={params}
- >
- {({ loadNextPage, loadPreviousPage, pageInfo }) => (
- <CategoryListPage
- categories={maybe(
- () => data.categories.edges.map(edge => edge.node),
- []
- )}
- onAdd={() => navigate(categoryAddUrl())}
- onRowClick={id => () => navigate(categoryUrl(id))}
- disabled={loading}
- onNextPage={loadNextPage}
- onPreviousPage={loadPreviousPage}
- pageInfo={pageInfo}
- />
- )}
- </Paginator>
- )}
- </TypedRootCategoriesQuery>
- );
- }}
- </Navigator>
-);
+}) => {
+ const navigate = useNavigator();
+ const paginate = usePaginator();
+
+ const paginationState = createPaginationState(PAGINATE_BY, params);
+ return (
+ <TypedRootCategoriesQuery displayLoader variables={paginationState}>
+ {({ data, loading, refetch }) => {
+ const { loadNextPage, loadPreviousPage, pageInfo } = paginate(
+ maybe(() => data.categories.pageInfo),
+ paginationState,
+ params
+ );
+
+ const handleCategoryBulkDelete = (data: CategoryBulkDelete) => {
+ if (data.categoryBulkDelete.errors.length === 0) {
+ navigate(categoryListUrl(), true);
+ refetch();
+ }
+ };
+ return (
+ <TypedCategoryBulkDeleteMutation
+ onCompleted={handleCategoryBulkDelete}
+ >
+ {(categoryBulkDelete, categoryBulkDeleteOpts) => {
+ const bulkDeleteState = getMutationState(
+ categoryBulkDeleteOpts.called,
+ categoryBulkDeleteOpts.loading,
+ maybe(
+ () => categoryBulkDeleteOpts.data.categoryBulkDelete.errors
+ )
+ );
+
+ return (
+ <>
+ <CategoryListPage
+ categories={maybe(
+ () => data.categories.edges.map(edge => edge.node),
+ []
+ )}
+ onAdd={() => navigate(categoryAddUrl())}
+ onBulkDelete={ids =>
+ navigate(
+ categoryListUrl({
+ ...params,
+ action: "delete",
+ ids
+ })
+ )
+ }
+ onRowClick={id => () => navigate(categoryUrl(id))}
+ disabled={loading}
+ onNextPage={loadNextPage}
+ onPreviousPage={loadPreviousPage}
+ pageInfo={pageInfo}
+ />
+ <ActionDialog
+ confirmButtonState={bulkDeleteState}
+ onClose={() =>
+ navigate(
+ categoryListUrl({
+ ...params,
+ action: undefined,
+ ids: undefined
+ })
+ )
+ }
+ onConfirm={() =>
+ categoryBulkDelete({
+ variables: {
+ ids: params.ids
+ }
+ })
+ }
+ open={params.action === "delete"}
+ title={i18n.t("Remove categories")}
+ variant="delete"
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ number }}</strong> categories?",
+ {
+ number: maybe(
+ () => params.ids.length.toString(),
+ "..."
+ )
+ }
+ )
+ }}
+ />
+ </ActionDialog>
+ </>
+ );
+ }}
+ </TypedCategoryBulkDeleteMutation>
+ );
+ }}
+ </TypedRootCategoriesQuery>
+ );
+};
export default CategoryList;
diff --git a/saleor/static/dashboard-next/components/AppLayout/menuStructure.ts b/saleor/static/dashboard-next/components/AppLayout/menuStructure.ts
index c222ae8b6e..a7c8b5fb19 100644
--- a/saleor/static/dashboard-next/components/AppLayout/menuStructure.ts
+++ b/saleor/static/dashboard-next/components/AppLayout/menuStructure.ts
@@ -33,7 +33,7 @@ const menuStructure: IMenuItem[] = [
{
ariaLabel: "categories",
label: i18n.t("Categories", { context: "Menu label" }),
- url: categoryListUrl
+ url: categoryListUrl()
},
{
ariaLabel: "collections",
diff --git a/saleor/static/dashboard-next/components/TableActions/TableActions.tsx b/saleor/static/dashboard-next/components/TableActions/TableActions.tsx
index 3c97b1dac2..822970ce62 100644
--- a/saleor/static/dashboard-next/components/TableActions/TableActions.tsx
+++ b/saleor/static/dashboard-next/components/TableActions/TableActions.tsx
@@ -8,11 +8,14 @@ import { fade } from "@material-ui/core/styles/colorManipulator";
import TableCell from "@material-ui/core/TableCell";
import TableRow from "@material-ui/core/TableRow";
import Typography from "@material-ui/core/Typography";
+import * as classNames from "classnames";
import * as React from "react";
+
import i18n from "../../i18n";
export interface TableActionsProps {
children: React.ReactNode;
+ className?: string;
selected?: number;
}
@@ -42,10 +45,11 @@ const styles = (theme: Theme) =>
const TableActions = withStyles(styles, { name: "TableActions" })(
({
classes,
+ className,
children,
selected
}: TableActionsProps & WithStyles<typeof styles>) => (
- <TableRow className={classes.root}>
+ <TableRow className={classNames(classes.root, className)}>
<TableCell className={classes.cell} colSpan={9999}>
<div className={classes.container}>
{selected && (
diff --git a/saleor/static/dashboard-next/components/TableHead/TableHead.tsx b/saleor/static/dashboard-next/components/TableHead/TableHead.tsx
index 2f610ddb66..f4a0ff0279 100644
--- a/saleor/static/dashboard-next/components/TableHead/TableHead.tsx
+++ b/saleor/static/dashboard-next/components/TableHead/TableHead.tsx
@@ -1,3 +1,4 @@
+import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
import MuiTableHead, {
TableHeadProps as MuiTableHeadProps
} from "@material-ui/core/TableHead";
@@ -10,19 +11,28 @@ export interface TableHeadProps extends MuiTableHeadProps {
toolbar: React.ReactNode | React.ReactNodeArray;
}
-const TableHead: React.StatelessComponent<TableHeadProps> = ({
- children,
- selected,
- toolbar,
- ...muiTableHeadProps
-}) => (
- <MuiTableHead {...muiTableHeadProps}>
- {selected ? (
- <TableActions selected={selected}>{toolbar}</TableActions>
- ) : (
- children
- )}
- </MuiTableHead>
+const styles = createStyles({
+ shrink: {}
+});
+
+const TableHead = withStyles(styles, {
+ name: "TableHead"
+})(
+ ({
+ children,
+ classes,
+ selected,
+ toolbar,
+ ...muiTableHeadProps
+ }: TableHeadProps & WithStyles<typeof styles>) => (
+ <MuiTableHead {...muiTableHeadProps}>
+ {selected ? (
+ <TableActions selected={selected}>{toolbar}</TableActions>
+ ) : (
+ children
+ )}
+ </MuiTableHead>
+ )
);
TableHead.displayName = "TableHead";
export default TableHead;
diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.ts
index b042d07ee3..c896431dfd 100644
--- a/saleor/static/dashboard-next/types/globalTypes.ts
+++ b/saleor/static/dashboard-next/types/globalTypes.ts
@@ -47,6 +47,7 @@ export enum LanguageCodeEnum {
FR = "FR",
HI = "HI",
HU = "HU",
+ HY = "HY",
ID = "ID",
IT = "IT",
JA = "JA",
@@ -55,6 +56,7 @@ export enum LanguageCodeEnum {
NB = "NB",
NL = "NL",
PL = "PL",
+ PT = "PT",
PT_BR = "PT_BR",
RO = "RO",
RU = "RU",