Skip to content

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

Add dialog to save filters

dominik-zeglen345e015eecbe
diff --git a/saleor/static/dashboard-next/components/SaveFilterTabDialog/SaveFilterTabDialog.tsx b/saleor/static/dashboard-next/components/SaveFilterTabDialog/SaveFilterTabDialog.tsx
new file mode 100644
index 0000000000..33b947ebdf
--- /dev/null
+++ b/saleor/static/dashboard-next/components/SaveFilterTabDialog/SaveFilterTabDialog.tsx
@@ -0,0 +1,73 @@
+import Button from "@material-ui/core/Button";
+import Dialog from "@material-ui/core/Dialog";
+import DialogActions from "@material-ui/core/DialogActions";
+import DialogContent from "@material-ui/core/DialogContent";
+import DialogTitle from "@material-ui/core/DialogTitle";
+import TextField from "@material-ui/core/TextField";
+import * as React from "react";
+
+import i18n from "../../i18n";
+import ConfirmButton, { ConfirmButtonTransitionState } from "../ConfirmButton";
+import Form from "../Form";
+
+export interface SaveFilterTabDialogFormData {
+ name: string;
+}
+
+const initialForm: SaveFilterTabDialogFormData = {
+ name: ""
+};
+
+export interface SaveFilterTabDialogProps {
+ confirmButtonState: ConfirmButtonTransitionState;
+ open: boolean;
+ onClose: () => void;
+ onSubmit: (data: SaveFilterTabDialogFormData) => void;
+}
+
+const SaveFilterTabDialog: React.FC<SaveFilterTabDialogProps> = ({
+ confirmButtonState,
+ onClose,
+ onSubmit,
+ open
+}) => (
+ <Dialog open={open} fullWidth maxWidth="sm">
+ <DialogTitle>
+ {i18n.t("Save Custom Search", {
+ context: "save filter tab"
+ })}
+ </DialogTitle>
+ <Form initial={initialForm} onSubmit={onSubmit}>
+ {({ change, data, submit }) => (
+ <>
+ <DialogContent>
+ <TextField
+ fullWidth
+ label={i18n.t("Search Name", {
+ context: "save search"
+ })}
+ name={"name" as keyof SaveFilterTabDialogFormData}
+ value={data.name}
+ onChange={change}
+ />
+ </DialogContent>
+ <DialogActions>
+ <Button onClick={onClose}>
+ {i18n.t("Cancel", { context: "button" })}
+ </Button>
+ <ConfirmButton
+ transitionState={confirmButtonState}
+ color="primary"
+ variant="contained"
+ onClick={submit}
+ >
+ {i18n.t("Save")}
+ </ConfirmButton>
+ </DialogActions>
+ </>
+ )}
+ </Form>
+ </Dialog>
+);
+SaveFilterTabDialog.displayName = "SaveFilterTabDialog";
+export default SaveFilterTabDialog;
diff --git a/saleor/static/dashboard-next/components/SaveFilterTabDialog/index.ts b/saleor/static/dashboard-next/components/SaveFilterTabDialog/index.ts
new file mode 100644
index 0000000000..8b281bdd21
--- /dev/null
+++ b/saleor/static/dashboard-next/components/SaveFilterTabDialog/index.ts
@@ -0,0 +1,2 @@
+export { default } from './SaveFilterTabDialog';
+export * from './SaveFilterTabDialog';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/products/urls.ts b/saleor/static/dashboard-next/products/urls.ts
index 62c09f1e47..5e6d41ebcf 100644
--- a/saleor/static/dashboard-next/products/urls.ts
+++ b/saleor/static/dashboard-next/products/urls.ts
@@ -10,7 +10,11 @@ export const productAddPath = urlJoin(productSection, "add");
export const productAddUrl = productAddPath;
export const productListPath = productSection;
-export type ProductListUrlDialog = "publish" | "unpublish" | "delete";
+export type ProductListUrlDialog =
+ | "publish"
+ | "unpublish"
+ | "delete"
+ | "save-search";
export type ProductListUrlFilters = Partial<{
isPublished: string;
priceFrom: string;
diff --git a/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx b/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx
index ac94979902..db65910016 100644
--- a/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx
@@ -5,6 +5,7 @@ import DeleteIcon from "@material-ui/icons/Delete";
import * as React from "react";
import ActionDialog from "../../../components/ActionDialog";
+import SaveFilterTabDialog from "../../../components/SaveFilterTabDialog";
import useBulkActions from "../../../hooks/useBulkActions";
import useLocale from "../../../hooks/useLocale";
import useNavigator from "../../../hooks/useNavigator";
@@ -15,7 +16,6 @@ import usePaginator, {
import useShop from "../../../hooks/useShop";
import i18n from "../../../i18n";
import { getMutationState, maybe } from "../../../misc";
-import { StockAvailability } from "../../../types/globalTypes";
import ProductListCard from "../../components/ProductListCard";
import {
TypedProductBulkDeleteMutation,
@@ -85,7 +85,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
);
};
- const openModal = (action: ProductListUrlDialog, ids: string[]) =>
+ const openModal = (action: ProductListUrlDialog, ids?: string[]) =>
navigate(
productListUrl({
...params,
@@ -239,11 +239,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
onFilterAdd={filter =>
changeFilterField(createFilter(filter))
}
- onFilterSave={() => {
- const name = prompt("Tab name");
- saveFilterTab(name, getActiveFilters(params));
- handleTabChange(getFilterTabs().length);
- }}
+ onFilterSave={() => openModal("save-search")}
onTabChange={handleTabChange}
/>
<ActionDialog
@@ -326,6 +322,15 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
}}
/>
</ActionDialog>
+ <SaveFilterTabDialog
+ open={params.action === "save-search"}
+ confirmButtonState="default"
+ onClose={closeModal}
+ onSubmit={data => {
+ saveFilterTab(data.name, getActiveFilters(params));
+ handleTabChange(getFilterTabs().length);
+ }}
+ />
</>
);
}}
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 9805f04ff2..46fdfe02dd 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -28,6 +28,7 @@ function loadStories() {
require("./stories/components/PriceField");
require("./stories/components/RichTextEditor");
require("./stories/components/SaveButtonBar");
+ require("./stories/components/SaveFilterTabDialog");
require("./stories/components/SingleAutocompleteSelectField");
require("./stories/components/SingleSelectField");
require("./stories/components/Skeleton");
diff --git a/saleor/static/dashboard-next/storybook/stories/components/SaveFilterTabDialog.tsx b/saleor/static/dashboard-next/storybook/stories/components/SaveFilterTabDialog.tsx
new file mode 100644
index 0000000000..938f00716e
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/components/SaveFilterTabDialog.tsx
@@ -0,0 +1,18 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import SaveFilterTabDialog, {
+ SaveFilterTabDialogProps
+} from "../../../components/SaveFilterTabDialog";
+import Decorator from "../../Decorator";
+
+const props: SaveFilterTabDialogProps = {
+ confirmButtonState: "default",
+ onClose: () => undefined,
+ onSubmit: () => undefined,
+ open: true
+};
+
+storiesOf("Generics / Save filter tab", module)
+ .addDecorator(Decorator)
+ .add("default", () => <SaveFilterTabDialog {...props} />);