Skip to content

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

Add bulk publish products

dominik-zeglen0d2e829d1d6c
diff --git a/saleor/static/dashboard-next/products/mutations.ts b/saleor/static/dashboard-next/products/mutations.ts
index bd817bcdc3..a2e5b0c9fd 100644
--- a/saleor/static/dashboard-next/products/mutations.ts
+++ b/saleor/static/dashboard-next/products/mutations.ts
@@ -41,6 +41,10 @@ import {
productBulkDelete,
productBulkDeleteVariables
} from "./types/productBulkDelete";
+import {
+ productBulkPublish,
+ productBulkPublishVariables
+} from "./types/productBulkPublish";
import {
ProductVariantBulkDelete,
ProductVariantBulkDeleteVariables
@@ -433,6 +437,21 @@ export const TypedProductBulkDeleteMutation = TypedMutation<
productBulkDeleteVariables
>(productBulkDeleteMutation);
+export const productBulkPublishMutation = gql`
+ mutation productBulkPublish($ids: [ID!]!, $isPublished: Boolean!) {
+ productBulkPublish(ids: $ids, isPublished: $isPublished) {
+ errors {
+ field
+ message
+ }
+ }
+ }
+`;
+export const TypedProductBulkPublishMutation = TypedMutation<
+ productBulkPublish,
+ productBulkPublishVariables
+>(productBulkPublishMutation);
+
export const ProductVariantBulkDeleteMutation = gql`
mutation ProductVariantBulkDelete($ids: [ID!]!) {
productVariantBulkDelete(ids: $ids) {
diff --git a/saleor/static/dashboard-next/products/types/productBulkPublish.ts b/saleor/static/dashboard-next/products/types/productBulkPublish.ts
new file mode 100644
index 0000000000..2fc3585887
--- /dev/null
+++ b/saleor/static/dashboard-next/products/types/productBulkPublish.ts
@@ -0,0 +1,27 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL mutation operation: productBulkPublish
+// ====================================================
+
+export interface productBulkPublish_productBulkPublish_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface productBulkPublish_productBulkPublish {
+ __typename: "ProductBulkPublish";
+ errors: productBulkPublish_productBulkPublish_errors[] | null;
+}
+
+export interface productBulkPublish {
+ productBulkPublish: productBulkPublish_productBulkPublish | null;
+}
+
+export interface productBulkPublishVariables {
+ ids: string[];
+ isPublished: boolean;
+}
diff --git a/saleor/static/dashboard-next/products/views/ProductList.tsx b/saleor/static/dashboard-next/products/views/ProductList.tsx
index 0aa71e0b2c..3ea2f4ab2b 100644
--- a/saleor/static/dashboard-next/products/views/ProductList.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductList.tsx
@@ -15,9 +15,13 @@ import { getMutationState, maybe } from "../../misc";
import { StockAvailability } from "../../types/globalTypes";
import ProductListCard from "../components/ProductListCard";
import { getTabName } from "../misc";
-import { TypedProductBulkDeleteMutation } from "../mutations";
+import {
+ TypedProductBulkDeleteMutation,
+ TypedProductBulkPublishMutation
+} from "../mutations";
import { TypedProductListQuery } from "../queries";
import { productBulkDelete } from "../types/productBulkDelete";
+import { productBulkPublish } from "../types/productBulkPublish";
import {
productAddUrl,
productListUrl,
@@ -96,144 +100,186 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
}
};
+ const handleBulkPublish = (data: productBulkPublish) => {
+ if (data.productBulkPublish.errors.length === 0) {
+ closeModal();
+ notify({
+ text: i18n.t("Changed publication status")
+ });
+ reset();
+ refetch();
+ }
+ };
+
return (
<TypedProductBulkDeleteMutation onCompleted={handleBulkDelete}>
- {(productBulkDelete, productBulkDeleteOpts) => {
- const bulkDeleteMutationState = getMutationState(
- productBulkDeleteOpts.called,
- productBulkDeleteOpts.loading,
- maybe(() => productBulkDeleteOpts.data.productBulkDelete.errors)
- );
+ {(productBulkDelete, productBulkDeleteOpts) => (
+ <TypedProductBulkPublishMutation onCompleted={handleBulkPublish}>
+ {(productBulkPublish, productBulkPublishOpts) => {
+ const bulkDeleteMutationState = getMutationState(
+ productBulkDeleteOpts.called,
+ productBulkDeleteOpts.loading,
+ maybe(
+ () => productBulkDeleteOpts.data.productBulkDelete.errors
+ )
+ );
+
+ const bulkPublishMutationState = getMutationState(
+ productBulkPublishOpts.called,
+ productBulkPublishOpts.loading,
+ maybe(
+ () =>
+ productBulkPublishOpts.data.productBulkPublish.errors
+ )
+ );
- return (
- <>
- <ProductListCard
- currentTab={currentTab}
- filtersList={[]}
- onAdd={() => navigate(productAddUrl)}
- disabled={loading}
- products={
- data &&
- data.products !== undefined &&
- data.products !== null
- ? data.products.edges.map(p => p.node)
- : undefined
- }
- onNextPage={loadNextPage}
- onPreviousPage={loadPreviousPage}
- pageInfo={pageInfo}
- onRowClick={id => () => navigate(productUrl(id))}
- onAllProducts={() =>
- changeFilters({
- status: undefined
- })
- }
- onCustomFilter={() => undefined}
- onAvailable={() =>
- changeFilters({
- status: StockAvailability.IN_STOCK
- })
- }
- onOfStock={() =>
- changeFilters({
- status: StockAvailability.OUT_OF_STOCK
- })
- }
- 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("delete", listElements)}
- >
- <DeleteIcon />
- </IconButton>
- </>
- }
- isChecked={isSelected}
- selected={listElements.length}
- toggle={toggle}
- />
- <ActionDialog
- open={params.action === "delete"}
- 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(),
- "..."
+ return (
+ <>
+ <ProductListCard
+ currentTab={currentTab}
+ filtersList={[]}
+ onAdd={() => navigate(productAddUrl)}
+ disabled={loading}
+ products={
+ data &&
+ data.products !== undefined &&
+ data.products !== null
+ ? data.products.edges.map(p => p.node)
+ : undefined
+ }
+ onNextPage={loadNextPage}
+ onPreviousPage={loadPreviousPage}
+ pageInfo={pageInfo}
+ onRowClick={id => () => navigate(productUrl(id))}
+ onAllProducts={() =>
+ changeFilters({
+ status: undefined
+ })
+ }
+ onCustomFilter={() => undefined}
+ onAvailable={() =>
+ changeFilters({
+ status: StockAvailability.IN_STOCK
+ })
+ }
+ onOfStock={() =>
+ changeFilters({
+ status: StockAvailability.OUT_OF_STOCK
+ })
+ }
+ 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("delete", listElements)}
+ >
+ <DeleteIcon />
+ </IconButton>
+ </>
+ }
+ isChecked={isSelected}
+ selected={listElements.length}
+ toggle={toggle}
+ />
+ <ActionDialog
+ open={params.action === "delete"}
+ 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(),
+ "..."
+ )
+ }
)
- }
- )
- }}
- />
- </ActionDialog>
- <ActionDialog
- open={params.action === "publish"}
- confirmButtonState={"default"}
- onClose={closeModal}
- onConfirm={() => console.log(params.ids)}
- title={i18n.t("Publish products")}
- >
- <DialogContentText
- dangerouslySetInnerHTML={{
- __html: i18n.t(
- "Are you sure you want to publish <strong>{{ number }}</strong> products?",
- {
- number: maybe(
- () => params.ids.length.toString(),
- "..."
+ }}
+ />
+ </ActionDialog>
+ <ActionDialog
+ open={params.action === "publish"}
+ confirmButtonState={bulkPublishMutationState}
+ onClose={closeModal}
+ onConfirm={() =>
+ productBulkPublish({
+ variables: {
+ ids: params.ids,
+ isPublished: true
+ }
+ })
+ }
+ title={i18n.t("Publish products")}
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to publish <strong>{{ number }}</strong> products?",
+ {
+ number: maybe(
+ () => params.ids.length.toString(),
+ "..."
+ )
+ }
)
- }
- )
- }}
- />
- </ActionDialog>
- <ActionDialog
- open={params.action === "unpublish"}
- confirmButtonState={"default"}
- onClose={closeModal}
- onConfirm={() => console.log(params.ids)}
- title={i18n.t("Unpublish products")}
- >
- <DialogContentText
- dangerouslySetInnerHTML={{
- __html: i18n.t(
- "Are you sure you want to unpublish <strong>{{ number }}</strong> products?",
- {
- number: maybe(
- () => params.ids.length.toString(),
- "..."
+ }}
+ />
+ </ActionDialog>
+ <ActionDialog
+ open={params.action === "unpublish"}
+ confirmButtonState={bulkPublishMutationState}
+ onClose={closeModal}
+ onConfirm={() =>
+ productBulkPublish({
+ variables: {
+ ids: params.ids,
+ isPublished: false
+ }
+ })
+ }
+ title={i18n.t("Unpublish products")}
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to unpublish <strong>{{ number }}</strong> products?",
+ {
+ number: maybe(
+ () => params.ids.length.toString(),
+ "..."
+ )
+ }
)
- }
- )
- }}
- />
- </ActionDialog>
- </>
- );
- }}
+ }}
+ />
+ </ActionDialog>
+ </>
+ );
+ }}
+ </TypedProductBulkPublishMutation>
+ )}
</TypedProductBulkDeleteMutation>
);
}}