Skip to content

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

Add filter tab delete dialog

dominik-zeglen0c3a350c71a6
diff --git a/saleor/static/dashboard-next/components/DeleteFilterTabDialog/DeleteFilterTabDialog.tsx b/saleor/static/dashboard-next/components/DeleteFilterTabDialog/DeleteFilterTabDialog.tsx
new file mode 100644
index 0000000000..aa4fb9125d
--- /dev/null
+++ b/saleor/static/dashboard-next/components/DeleteFilterTabDialog/DeleteFilterTabDialog.tsx
@@ -0,0 +1,46 @@
+import DialogContentText from "@material-ui/core/DialogContentText";
+import * as React from "react";
+
+import i18n from "../../i18n";
+import ActionDialog from "../ActionDialog";
+import { ConfirmButtonTransitionState } from "../ConfirmButton";
+
+export interface DeleteFilterTabDialogProps {
+ confirmButtonState: ConfirmButtonTransitionState;
+ open: boolean;
+ tabName: string;
+ onClose: () => void;
+ onSubmit: () => void;
+}
+
+const DeleteFilterTabDialog: React.FC<DeleteFilterTabDialogProps> = ({
+ confirmButtonState,
+ onClose,
+ onSubmit,
+ open,
+ tabName
+}) => (
+ <ActionDialog
+ open={open}
+ confirmButtonState={confirmButtonState}
+ onClose={onClose}
+ onConfirm={onSubmit}
+ title={i18n.t("Delete Search", {
+ context: "modal title custom search delete"
+ })}
+ variant="delete"
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to delete <strong>{{ name }}</strong> search tab?",
+ {
+ name: tabName
+ }
+ )
+ }}
+ />
+ </ActionDialog>
+);
+DeleteFilterTabDialog.displayName = "DeleteFilterTabDialog";
+export default DeleteFilterTabDialog;
diff --git a/saleor/static/dashboard-next/components/DeleteFilterTabDialog/index.ts b/saleor/static/dashboard-next/components/DeleteFilterTabDialog/index.ts
new file mode 100644
index 0000000000..3f4ef0d56c
--- /dev/null
+++ b/saleor/static/dashboard-next/components/DeleteFilterTabDialog/index.ts
@@ -0,0 +1,2 @@
+export { default } from './DeleteFilterTabDialog';
+export * from './DeleteFilterTabDialog';
\ 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 5e6d41ebcf..3cca0a810a 100644
--- a/saleor/static/dashboard-next/products/urls.ts
+++ b/saleor/static/dashboard-next/products/urls.ts
@@ -14,7 +14,8 @@ export type ProductListUrlDialog =
| "publish"
| "unpublish"
| "delete"
- | "save-search";
+ | "save-search"
+ | "delete-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 28ef788c98..ba43b9e852 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 DeleteFilterTabDialog from "../../../components/DeleteFilterTabDialog";
import SaveFilterTabDialog, {
SaveFilterTabDialogFormData
} from "../../../components/SaveFilterTabDialog";
@@ -63,10 +64,12 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
params.ids
);
+ const tabs = getFilterTabs();
+
const currentTab =
params.activeTab === undefined
? areFiltersApplied(params)
- ? getFilterTabs().length + 1
+ ? tabs.length + 1
: 0
: parseInt(params.activeTab, 0);
@@ -111,16 +114,14 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
})
);
- const handleTabChange = (tab: number) => {
- const tabs = getFilterTabs();
+ const handleTabChange = (tab: number) =>
navigate(
productListUrl({
activeTab: tab.toString(),
- ...tabs[tab - 1].data,
+ ...getFilterTabs()[tab - 1].data,
query: params.query
})
);
- };
const handleFilterTabDelete = () => {
deleteFilterTab(currentTab);
@@ -130,7 +131,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
const handleFilterTabSave = (data: SaveFilterTabDialogFormData) => {
saveFilterTab(data.name, getActiveFilters(params));
- handleTabChange(getFilterTabs().length);
+ handleTabChange(tabs.length);
};
const paginationState = createPaginationState(PAGINATE_BY, params);
@@ -263,7 +264,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
changeFilterField(createFilter(filter))
}
onFilterSave={() => openModal("save-search")}
- onFilterDelete={handleFilterTabDelete}
+ onFilterDelete={() => openModal("delete-search")}
onTabChange={handleTabChange}
initialSearch={params.query || ""}
/>
@@ -353,6 +354,13 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
onClose={closeModal}
onSubmit={handleFilterTabSave}
/>
+ <DeleteFilterTabDialog
+ open={params.action === "delete-search"}
+ confirmButtonState="default"
+ onClose={closeModal}
+ onSubmit={handleFilterTabDelete}
+ tabName={maybe(() => tabs[currentTab - 1].name, "...")}
+ />
</>
);
}}
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 46fdfe02dd..57e6efbceb 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -12,6 +12,7 @@ function loadStories() {
require("./stories/components/Chip");
require("./stories/components/Date");
require("./stories/components/DateTime");
+ require("./stories/components/DeleteFilterTabDialog");
require("./stories/components/EditableTableCell");
require("./stories/components/ErrorMessageCard");
require("./stories/components/ErrorPage");
diff --git a/saleor/static/dashboard-next/storybook/stories/components/DeleteFilterTabDialog.tsx b/saleor/static/dashboard-next/storybook/stories/components/DeleteFilterTabDialog.tsx
new file mode 100644
index 0000000000..e5aff4e653
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/components/DeleteFilterTabDialog.tsx
@@ -0,0 +1,19 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import DeleteFilterTabDialog, {
+ DeleteFilterTabDialogProps
+} from "../../../components/DeleteFilterTabDialog";
+import Decorator from "../../Decorator";
+
+const props: DeleteFilterTabDialogProps = {
+ confirmButtonState: "default",
+ onClose: () => undefined,
+ onSubmit: () => undefined,
+ open: true,
+ tabName: "Out of stock"
+};
+
+storiesOf("Generics / Delete filter tab", module)
+ .addDecorator(Decorator)
+ .add("default", () => <DeleteFilterTabDialog {...props} />);