Skip to content

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

Escape category view urls

dominik-zeglendaead82ebc06
diff --git a/saleor/static/dashboard-next/categories/index.tsx b/saleor/static/dashboard-next/categories/index.tsx
index f74cdc0db1..f8515e45f3 100644
--- a/saleor/static/dashboard-next/categories/index.tsx
+++ b/saleor/static/dashboard-next/categories/index.tsx
@@ -3,7 +3,7 @@ import * as React from "react";
import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { WindowTitle } from "../components/WindowTitle";
import i18n from "../i18n";
-import { categoryAddUrl, categoryListUrl, categoryUrl } from "./urls";
+import { categoryAddPath, categoryListPath, categoryPath } from "./urls";
import { CategoryCreateView } from "./views/CategoryCreate";
import CategoryDetailsView, {
CategoryDetailsQueryParams
@@ -48,10 +48,10 @@ const Component = () => (
<>
<WindowTitle title={i18n.t("Categories")} />
<Switch>
- <Route exact path={categoryListUrl} component={CategoryList} />
- <Route exact path={categoryAddUrl()} component={CategoryCreate} />
- <Route exact path={categoryAddUrl(":id")} component={CategoryCreate} />
- <Route path={categoryUrl(":id")} component={CategoryDetails} />
+ <Route exact path={categoryListPath} component={CategoryList} />
+ <Route exact path={categoryAddPath()} component={CategoryCreate} />
+ <Route exact path={categoryAddPath(":id")} component={CategoryCreate} />
+ <Route path={categoryPath(":id")} component={CategoryDetails} />
</Switch>
</>
);
diff --git a/saleor/static/dashboard-next/categories/urls.ts b/saleor/static/dashboard-next/categories/urls.ts
index 80d0f5384c..0abf642264 100644
--- a/saleor/static/dashboard-next/categories/urls.ts
+++ b/saleor/static/dashboard-next/categories/urls.ts
@@ -1,11 +1,18 @@
import * as urlJoin from "url-join";
const categorySectionUrl = "/categories/";
+
+export const categoryListPath = categorySectionUrl;
export const categoryListUrl = categorySectionUrl;
-export const categoryUrl = (id: string) => urlJoin(categorySectionUrl, id);
-export const categoryAddUrl = (parentId?: string) => {
+
+export const categoryPath = (id: string) => urlJoin(categorySectionUrl, id);
+export const categoryUrl = (id: string) => categoryPath(encodeURIComponent(id));
+
+export const categoryAddPath = (parentId?: string) => {
if (parentId) {
- return urlJoin(categoryUrl(parentId), "add");
+ return urlJoin(categoryPath(parentId), "add");
}
return urlJoin(categorySectionUrl, "add");
};
+export const categoryAddUrl = (parentId?: string) =>
+ categoryAddPath(encodeURIComponent(parentId));
diff --git a/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx b/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
index 41a567a45e..347dea8215 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
@@ -24,9 +24,7 @@ export const CategoryCreateView: React.StatelessComponent<
const handleSuccess = (data: CategoryCreate) => {
if (data.categoryCreate.errors.length === 0) {
pushMessage({ text: i18n.t("Category created") });
- navigate(
- categoryUrl(encodeURIComponent(data.categoryCreate.category.id))
- );
+ navigate(categoryUrl(data.categoryCreate.category.id));
}
};
return (
@@ -48,9 +46,7 @@ export const CategoryCreateView: React.StatelessComponent<
[]
)}
disabled={createCategoryResult.loading}
- onBack={() =>
- navigate(categoryUrl(encodeURIComponent(parentId)))
- }
+ onBack={() => navigate(categoryUrl(parentId))}
onSubmit={formData =>
createCategory({
variables: {
diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
index 313b67cdfb..af34f91c3f 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
@@ -21,7 +21,7 @@ import {
import { TypedCategoryDetailsQuery } from "../../queries";
import { CategoryDelete } from "../../types/CategoryDelete";
import { categoryAddUrl, categoryListUrl, categoryUrl } from "../../urls";
-import { categoryDeleteUrl } from "./urls";
+import { categoryDeletePath, categoryDeleteUrl } from "./urls";
export type CategoryDetailsQueryParams = Partial<{
after: string;
@@ -105,32 +105,22 @@ export const CategoryDetails: React.StatelessComponent<
)}
placeholderImage={""}
onAddCategory={() =>
- navigate(
- categoryAddUrl(encodeURIComponent(id))
- )
+ navigate(categoryAddUrl(id))
}
onAddProduct={() => navigate(productAddUrl)}
onBack={() =>
navigate(
maybe(
() =>
- categoryUrl(
- encodeURIComponent(
- data.category.parent.id
- )
- ),
+ categoryUrl(data.category.parent.id),
categoryListUrl
)
)
}
onCategoryClick={id => () =>
- navigate(
- categoryUrl(encodeURIComponent(id))
- )}
+ navigate(categoryUrl(id))}
onDelete={() =>
- navigate(
- categoryDeleteUrl(encodeURIComponent(id))
- )
+ navigate(categoryDeleteUrl(id))
}
onImageDelete={() => undefined}
onImageUpload={() => undefined}
@@ -172,17 +162,14 @@ export const CategoryDetails: React.StatelessComponent<
)}
</Paginator>
<Route
- path={categoryDeleteUrl(encodeURIComponent(id))}
+ path={categoryDeletePath(":id")}
render={({ match }) => (
<ActionDialog
confirmButtonState={
removeDialogTransitionState
}
onClose={() =>
- navigate(
- categoryUrl(encodeURIComponent(id)),
- true
- )
+ navigate(categoryUrl(id), true)
}
onConfirm={() =>
deleteCategory({ variables: { id } })
diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails/urls.ts b/saleor/static/dashboard-next/categories/views/CategoryDetails/urls.ts
index e6afc274d5..83527ff9e1 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryDetails/urls.ts
+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails/urls.ts
@@ -1,5 +1,7 @@
import * as urlJoin from "url-join";
-import { categoryUrl } from "../../urls";
+import { categoryPath } from "../../urls";
+export const categoryDeletePath = (id: string) =>
+ urlJoin(categoryPath(id), "delete");
export const categoryDeleteUrl = (id: string) =>
- urlJoin(categoryUrl(id), "delete");
+ categoryDeletePath(encodeURIComponent(id));
diff --git a/saleor/static/dashboard-next/categories/views/CategoryList.tsx b/saleor/static/dashboard-next/categories/views/CategoryList.tsx
index 266506d1a4..1efb0a4995 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryList.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryList.tsx
@@ -17,8 +17,7 @@ export const CategoryList: React.StatelessComponent = () => (
[]
)}
onAddCategory={() => navigate(categoryAddUrl())}
- onCategoryClick={id => () =>
- navigate(categoryUrl(encodeURIComponent(id)))}
+ onCategoryClick={id => () => navigate(categoryUrl(id))}
/>
)}
</TypedRootCategoriesQuery>