Skip to content

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

Split paths and urls in product type views

dominik-zeglen2efde9c0775f
diff --git a/saleor/static/dashboard-next/productTypes/index.tsx b/saleor/static/dashboard-next/productTypes/index.tsx
index 0355ab1adb..bd18c97d99 100644
--- a/saleor/static/dashboard-next/productTypes/index.tsx
+++ b/saleor/static/dashboard-next/productTypes/index.tsx
@@ -4,7 +4,11 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { WindowTitle } from "../components/WindowTitle";
import i18n from "../i18n";
-import { productTypeAddUrl, productTypeListUrl, productTypeUrl } from "./urls";
+import {
+ productTypeAddPath,
+ productTypeListPath,
+ productTypePath
+} from "./urls";
import ProductTypeCreate from "./views/ProductTypeCreate";
import ProductTypeListComponent, {
ProductTypeListQueryParams
@@ -37,9 +41,9 @@ export const ProductTypeRouter: React.StatelessComponent<
<>
<WindowTitle title={i18n.t("Product types")} />
<Switch>
- <Route exact path={productTypeListUrl} component={ProductTypeList} />
- <Route exact path={productTypeAddUrl} component={ProductTypeCreate} />
- <Route path={productTypeUrl(":id")} component={ProductTypeUpdate} />
+ <Route exact path={productTypeListPath} component={ProductTypeList} />
+ <Route exact path={productTypeAddPath} component={ProductTypeCreate} />
+ <Route path={productTypePath(":id")} component={ProductTypeUpdate} />
</Switch>
</>
);
diff --git a/saleor/static/dashboard-next/productTypes/urls.ts b/saleor/static/dashboard-next/productTypes/urls.ts
index 3003774b27..3eedcb207d 100644
--- a/saleor/static/dashboard-next/productTypes/urls.ts
+++ b/saleor/static/dashboard-next/productTypes/urls.ts
@@ -1,6 +1,13 @@
import * as urlJoin from "url-join";
const productTypeSection = "/productTypes/";
-export const productTypeListUrl = productTypeSection;
-export const productTypeAddUrl = urlJoin(productTypeSection, "add");
-export const productTypeUrl = (id: string) => urlJoin(productTypeSection, id);
+
+export const productTypeListPath = productTypeSection;
+export const productTypeListUrl = productTypeListPath;
+
+export const productTypeAddPath = urlJoin(productTypeSection, "add");
+export const productTypeAddUrl = productTypeAddPath;
+
+export const productTypePath = (id: string) => urlJoin(productTypeSection, id);
+export const productTypeUrl = (id: string) =>
+ productTypePath(encodeURIComponent(id));
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
index 49a8718bb4..1a1fd721a3 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
@@ -22,7 +22,12 @@ import { ProductTypeDelete } from "../../types/ProductTypeDelete";
import { ProductTypeUpdate as ProductTypeUpdateMutation } from "../../types/ProductTypeUpdate";
import { productTypeListUrl, productTypeUrl } from "../../urls";
import { ProductTypeUpdateErrors } from "./errors";
-import { addAttributeUrl, editAttributeUrl } from "./urls";
+import {
+ addAttributePath,
+ addAttributeUrl,
+ editAttributePath,
+ editAttributeUrl
+} from "./urls";
interface ProductTypeUpdateProps {
id: string;
@@ -40,7 +45,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
<TypedProductTypeDetailsQuery displayLoader variables={{ id }}>
{({ data, loading: dataLoading }) => {
const closeModal = () => {
- navigate(productTypeUrl(encodeURIComponent(id)), true);
+ navigate(productTypeUrl(id), true);
setErrors.addAttributeErrors([]);
setErrors.editAttributeErrors([]);
};
@@ -261,7 +266,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
{Object.keys(AttributeTypeEnum).map(key => (
<Route
exact
- path={addAttributeUrl(
+ path={addAttributePath(
encodeURIComponent(id),
AttributeTypeEnum[key]
)}
@@ -290,8 +295,8 @@ export const ProductTypeUpdate: React.StatelessComponent<
))}
<Route
exact
- path={editAttributeUrl(
- encodeURIComponent(id),
+ path={editAttributePath(
+ ":productTypeId",
":id"
)}
>
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
index b2fbbec2d1..a1ff7a1186 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
@@ -1,14 +1,24 @@
import * as urlJoin from "url-join";
import { AttributeTypeEnum } from "../../../types/globalTypes";
-import { productTypeUrl } from "../../urls";
+import { productTypePath } from "../../urls";
-export const addAttributeUrl = (
+export const addAttributePath = (
productTypeId: string,
type: AttributeTypeEnum
) =>
type === AttributeTypeEnum.PRODUCT
- ? urlJoin(productTypeUrl(productTypeId), "attribute/product/add")
- : urlJoin(productTypeUrl(productTypeId), "attribute/variant/add");
+ ? urlJoin(productTypePath(productTypeId), "attribute/product/add")
+ : urlJoin(productTypePath(productTypeId), "attribute/variant/add");
+export const addAttributeUrl = (
+ productTypeId: string,
+ type: AttributeTypeEnum
+) => addAttributePath(encodeURIComponent(productTypeId), type);
+
+export const editAttributePath = (productTypeId: string, attributeId: string) =>
+ urlJoin(productTypePath(productTypeId), "attribute", attributeId);
export const editAttributeUrl = (productTypeId: string, attributeId: string) =>
- urlJoin(productTypeUrl(productTypeId), "attribute", attributeId);
+ editAttributePath(
+ encodeURIComponent(productTypeId),
+ encodeURIComponent(attributeId)
+ );
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
index 1717bbb1d5..f49aae6716 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
@@ -141,11 +141,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
variants={maybe(() => product.variants)}
onAttributesEdit={() =>
navigate(
- productTypeUrl(
- encodeURIComponent(
- data.product.productType.id
- )
- )
+ productTypeUrl(data.product.productType.id)
)
}
onBack={() => {