Skip to content

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

Move dialogs to view

dominik-zeglenca23b7f553c5
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
index c1c00d1e4d..71370acf6d 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
@@ -12,7 +12,6 @@ import * as React from "react";
import CardTitle from "../../../components/CardTitle";
import Skeleton from "../../../components/Skeleton";
-import Toggle from "../../../components/Toggle";
import i18n from "../../../i18n";
import { maybe, renderCollection } from "../../../misc";
import { AttributeTypeEnum } from "../../../types/globalTypes";
@@ -20,24 +19,15 @@ import {
ProductTypeDetails_productType_productAttributes,
ProductTypeDetails_productType_variantAttributes
} from "../../types/ProductTypeDetails";
-import ProductTypeAttributeEditDialog, {
- FormData as ProductTypeAttributeEditDialogFormData
-} from "../ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog";
interface ProductTypeAttributesProps {
attributes:
| ProductTypeDetails_productType_productAttributes[]
| ProductTypeDetails_productType_variantAttributes[];
type: AttributeTypeEnum;
- onAttributeAdd: (
- data: ProductTypeAttributeEditDialogFormData,
- type: AttributeTypeEnum
- ) => void;
+ onAttributeAdd: (type: AttributeTypeEnum) => void;
onAttributeDelete: (id: string, event: React.MouseEvent<any>) => void;
- onAttributeUpdate: (
- id: string,
- data: ProductTypeAttributeEditDialogFormData
- ) => void;
+ onAttributeUpdate: (id: string) => void;
}
const decorate = withStyles(theme => ({
@@ -63,119 +53,77 @@ const ProductTypeAttributes = decorate<ProductTypeAttributesProps>(
onAttributeDelete,
onAttributeUpdate
}) => (
- <Toggle>
- {(openedAttributeAddDialog, { toggle: toggleAttributeAddDialog }) => (
- <>
- <Card>
- <CardTitle
- title={
- type === AttributeTypeEnum.PRODUCT
- ? i18n.t("Product Attributes")
- : i18n.t("Variant Attributes")
- }
- toolbar={
- <Button
- color="secondary"
- variant="flat"
- onClick={toggleAttributeAddDialog}
- >
- {i18n.t("Add attribute", { context: "button" })}
- </Button>
- }
- />
- <Table>
- <TableHead>
- <TableRow>
- <TableCell>{i18n.t("Attribute name")}</TableCell>
- <TableCell className={classes.textLeft}>
- {i18n.t("Values")}
- </TableCell>
- <TableCell />
- </TableRow>
- </TableHead>
- <TableBody>
- {renderCollection(
- attributes,
- attribute => (
- <Toggle key={maybe(() => attribute.id)}>
- {(
- openedAttributeEditDialog,
- { toggle: toggleAttributeEditDialog }
- ) => (
- <>
- <TableRow
- className={!!attribute ? classes.link : undefined}
- hover={!!attribute}
- onClick={toggleAttributeEditDialog}
- key={maybe(() => attribute.id)}
- >
- <TableCell>
- {maybe(() => attribute.name) ? (
- attribute.name
- ) : (
- <Skeleton />
- )}
- </TableCell>
- <TableCell className={classes.textLeft}>
- {maybe(() => attribute.values) !== undefined ? (
- attribute.values
- .map(value => value.name)
- .join(", ")
- ) : (
- <Skeleton />
- )}
- </TableCell>
- <TableCell className={classes.iconCell}>
- <IconButton
- onClick={event =>
- onAttributeDelete(attribute.id, event)
- }
- >
- <DeleteIcon color="secondary" />
- </IconButton>
- </TableCell>
- </TableRow>
- <ProductTypeAttributeEditDialog
- name={maybe(() => attribute.name)}
- opened={openedAttributeEditDialog}
- title={i18n.t("Edit attribute")}
- values={maybe(() =>
- attribute.values.map(value => ({
- label: value.name,
- value: value.id
- }))
- )}
- onClose={toggleAttributeEditDialog}
- onConfirm={data =>
- onAttributeUpdate(attribute.id, data)
- }
- />
- </>
- )}
- </Toggle>
- ),
- () => (
- <TableRow>
- <TableCell colSpan={2}>
- {i18n.t("No attributes found")}
- </TableCell>
- </TableRow>
- )
- )}
- </TableBody>
- </Table>
- </Card>
- <ProductTypeAttributeEditDialog
- opened={openedAttributeAddDialog}
- title={i18n.t("Add attribute")}
- name=""
- values={[]}
- onClose={toggleAttributeAddDialog}
- onConfirm={data => onAttributeAdd(data, type)}
- />
- </>
- )}
- </Toggle>
+ <Card>
+ <CardTitle
+ title={
+ type === AttributeTypeEnum.PRODUCT
+ ? i18n.t("Product Attributes")
+ : i18n.t("Variant Attributes")
+ }
+ toolbar={
+ <Button
+ color="secondary"
+ variant="flat"
+ onClick={() => onAttributeAdd(type)}
+ >
+ {i18n.t("Add attribute", { context: "button" })}
+ </Button>
+ }
+ />
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell>{i18n.t("Attribute name")}</TableCell>
+ <TableCell className={classes.textLeft}>
+ {i18n.t("Values")}
+ </TableCell>
+ <TableCell />
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {renderCollection(
+ attributes,
+ attribute => (
+ <TableRow
+ className={!!attribute ? classes.link : undefined}
+ hover={!!attribute}
+ onClick={
+ !!attribute
+ ? () => onAttributeUpdate(attribute.id)
+ : undefined
+ }
+ key={maybe(() => attribute.id)}
+ >
+ <TableCell>
+ {maybe(() => attribute.name) ? attribute.name : <Skeleton />}
+ </TableCell>
+ <TableCell className={classes.textLeft}>
+ {maybe(() => attribute.values) !== undefined ? (
+ attribute.values.map(value => value.name).join(", ")
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.iconCell}>
+ <IconButton
+ onClick={event => onAttributeDelete(attribute.id, event)}
+ >
+ <DeleteIcon color="secondary" />
+ </IconButton>
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={2}>
+ {i18n.t("No attributes found")}
+ </TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
)
);
ProductTypeAttributes.displayName = "ProductTypeAttributes";
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
index a0191a5900..db5cb5da0a 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
@@ -19,7 +19,6 @@ import {
WeightUnitsEnum
} from "../../../types/globalTypes";
import { ProductTypeDetails_productType } from "../../types/ProductTypeDetails";
-import { FormData as ProductTypeAttributeEditDialogFormData } from "../ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog";
import ProductTypeAttributes from "../ProductTypeAttributes/ProductTypeAttributes";
import ProductTypeDetails from "../ProductTypeDetails/ProductTypeDetails";
import ProductTypeShipping from "../ProductTypeShipping/ProductTypeShipping";
@@ -48,15 +47,9 @@ export interface ProductTypeDetailsPageProps {
disabled: boolean;
pageTitle: string;
saveButtonBarState: SaveButtonBarState;
- onAttributeAdd: (
- data: ProductTypeAttributeEditDialogFormData,
- type: AttributeTypeEnum
- ) => void;
+ onAttributeAdd: (type: AttributeTypeEnum) => void;
onAttributeDelete: (id: string, event: React.MouseEvent<any>) => void;
- onAttributeUpdate: (
- id: string,
- data: ProductTypeAttributeEditDialogFormData
- ) => void;
+ onAttributeUpdate: (id: string) => void;
onBack: () => void;
onDelete: () => void;
onSubmit: (data: ProductTypeForm) => void;
diff --git a/saleor/static/dashboard-next/productTypes/index.tsx b/saleor/static/dashboard-next/productTypes/index.tsx
index 45228b39da..e47d2792f5 100644
--- a/saleor/static/dashboard-next/productTypes/index.tsx
+++ b/saleor/static/dashboard-next/productTypes/index.tsx
@@ -38,7 +38,7 @@ export const ProductTypeRouter: React.StatelessComponent<
<Switch>
<Route exact path={match.url} component={ProductTypeList} />
<Route exact path={match.url + "/add/"} component={ProductTypeCreate} />
- <Route exact path={match.url + "/:id/"} component={ProductTypeUpdate} />
+ <Route path={match.url + "/:id/"} component={ProductTypeUpdate} />
</Switch>
);
ProductTypeRouter.displayName = "ProductTypeRouter";
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
similarity index 55%
rename from saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
rename to saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
index ebc4356ec4..f744727ea6 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
@@ -1,22 +1,26 @@
import * as React from "react";
-import Navigator from "../../components/Navigator";
+import { Route } from "react-router-dom";
-import { productTypeListUrl } from "..";
-import Messages from "../../components/messages";
-import i18n from "../../i18n";
-import { maybe } from "../../misc";
-import { AttributeTypeEnum } from "../../types/globalTypes";
-import { FormData as AttributeForm } from "../components/ProductTypeAttributeEditDialog";
+import { productTypeDetailsUrl, productTypeListUrl } from "../../";
+import Messages from "../../../components/messages";
+import Navigator from "../../../components/Navigator";
+import i18n from "../../../i18n";
+import { maybe } from "../../../misc";
+import { AttributeTypeEnum } from "../../../types/globalTypes";
+import ProductTypeAttributeEditDialog, {
+ FormData as AttributeForm
+} from "../../components/ProductTypeAttributeEditDialog";
import ProductTypeDetailsPage, {
ProductTypeForm
-} from "../components/ProductTypeDetailsPage";
-import ProductTypeOperations from "../containers/ProductTypeOperations";
-import { TypedProductTypeDetailsQuery } from "../queries";
-import { AttributeCreate } from "../types/AttributeCreate";
-import { AttributeDelete } from "../types/AttributeDelete";
-import { AttributeUpdate } from "../types/AttributeUpdate";
-import { ProductTypeDelete } from "../types/ProductTypeDelete";
-import { ProductTypeUpdate as ProductTypeUpdateMutation } from "../types/ProductTypeUpdate";
+} from "../../components/ProductTypeDetailsPage";
+import ProductTypeOperations from "../../containers/ProductTypeOperations";
+import { TypedProductTypeDetailsQuery } from "../../queries";
+import { AttributeCreate } from "../../types/AttributeCreate";
+import { AttributeDelete } from "../../types/AttributeDelete";
+import { AttributeUpdate } from "../../types/AttributeUpdate";
+import { ProductTypeDelete } from "../../types/ProductTypeDelete";
+import { ProductTypeUpdate as ProductTypeUpdateMutation } from "../../types/ProductTypeUpdate";
+import { addAttributeUrl, editAttributeUrl } from "./urls";
interface ProductTypeUpdateProps {
id: string;
@@ -31,6 +35,8 @@ export const ProductTypeUpdate: React.StatelessComponent<
{navigate => (
<TypedProductTypeDetailsQuery variables={{ id }}>
{({ data, loading: dataLoading }) => {
+ const closeModal = () =>
+ navigate(productTypeDetailsUrl(id), true);
const handleAttributeCreateSuccess = (data: AttributeCreate) => {
if (!maybe(() => data.attributeCreate.errors.length)) {
pushMessage({
@@ -38,6 +44,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
context: "notification"
})
});
+ closeModal();
}
};
const handleAttributeDeleteSuccess = (data: AttributeDelete) => {
@@ -56,6 +63,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
context: "notification"
})
});
+ closeModal();
}
};
const handleProductTypeDeleteSuccess = (
@@ -179,22 +187,97 @@ export const ProductTypeUpdate: React.StatelessComponent<
};
const loading = mutationLoading || dataLoading;
return (
- <ProductTypeDetailsPage
- defaultWeightUnit={maybe(
- () => data.shop.defaultWeightUnit
+ <>
+ <ProductTypeDetailsPage
+ defaultWeightUnit={maybe(
+ () => data.shop.defaultWeightUnit
+ )}
+ disabled={loading}
+ errors={errors}
+ pageTitle={maybe(() => data.productType.name)}
+ productType={maybe(() => data.productType)}
+ saveButtonBarState={loading ? "loading" : "default"}
+ onAttributeAdd={type =>
+ navigate(addAttributeUrl(id, type))
+ }
+ onAttributeDelete={handleAttributeDelete}
+ onAttributeUpdate={attributeId =>
+ navigate(editAttributeUrl(id, attributeId))
+ }
+ onBack={() => navigate(productTypeListUrl)}
+ onDelete={handleProductTypeDelete}
+ onSubmit={handleProductTypeUpdate}
+ />
+ {!dataLoading && (
+ <>
+ {Object.keys(AttributeTypeEnum).map(key => (
+ <Route
+ exact
+ path={addAttributeUrl(
+ id,
+ AttributeTypeEnum[key]
+ )}
+ key={key}
+ >
+ {({ match }) => (
+ <ProductTypeAttributeEditDialog
+ name=""
+ values={[]}
+ onClose={closeModal}
+ onConfirm={data =>
+ handleAttributeCreate(
+ data,
+ AttributeTypeEnum[key]
+ )
+ }
+ opened={!!match}
+ title={i18n.t("Add Attribute", {
+ context: "modal title"
+ })}
+ />
+ )}
+ </Route>
+ ))}
+ <Route exact path={editAttributeUrl(id, ":id")}>
+ {({ match }) => {
+ const attribute = maybe(
+ () =>
+ data.productType.productAttributes
+ .concat(
+ data.productType.variantAttributes
+ )
+ .filter(
+ attribute =>
+ attribute.id === match.params.id
+ )[0]
+ );
+ return (
+ <ProductTypeAttributeEditDialog
+ name={maybe(() => attribute.name)}
+ values={maybe(() =>
+ attribute.values.map(value => ({
+ label: value.name,
+ value: value.id
+ }))
+ )}
+ onClose={closeModal}
+ onConfirm={data =>
+ handleAttributeUpdate(
+ match.params.id,
+ data
+ )
+ }
+ opened={!!match}
+ title={i18n.t("Edit Attribute", {
+ context: "modal title"
+ })}
+ />
+ );
+ }}
+ </Route>
+ </>
)}
- disabled={loading}
- errors={errors}
- pageTitle={maybe(() => data.productType.name)}
- productType={maybe(() => data.productType)}
- saveButtonBarState={loading ? "loading" : "default"}
- onAttributeAdd={handleAttributeCreate}
- onAttributeDelete={handleAttributeDelete}
- onAttributeUpdate={handleAttributeUpdate}
- onBack={() => navigate(productTypeListUrl)}
- onDelete={handleProductTypeDelete}
- onSubmit={handleProductTypeUpdate}
- />
+ </>
);
}}
</ProductTypeOperations>
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
new file mode 100644
index 0000000000..661b6d3b99
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
@@ -0,0 +1,12 @@
+import { productTypeDetailsUrl } from "../..";
+import { AttributeTypeEnum } from "../../../types/globalTypes";
+
+export const addAttributeUrl = (
+ productTypeId: string,
+ type: AttributeTypeEnum
+) =>
+ type === AttributeTypeEnum.PRODUCT
+ ? productTypeDetailsUrl(productTypeId) + "attribute/product/add"
+ : productTypeDetailsUrl(productTypeId) + "attribute/variant/add";
+export const editAttributeUrl = (productTypeId: string, attributeId: string) =>
+ productTypeDetailsUrl(productTypeId) + "attribute/" + attributeId;