Skip to content

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

Encode urls in collection views

dominik-zeglenc6d17a37d6b9
diff --git a/saleor/static/dashboard-next/collections/index.tsx b/saleor/static/dashboard-next/collections/index.tsx
index a276f9f4fc..4bb45457e5 100644
--- a/saleor/static/dashboard-next/collections/index.tsx
+++ b/saleor/static/dashboard-next/collections/index.tsx
@@ -4,7 +4,7 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { WindowTitle } from "../components/WindowTitle";
import i18n from "../i18n";
-import { collectionAddUrl, collectionListUrl, collectionUrl } from "./urls";
+import { collectionAddPath, collectionListPath, collectionPath } from "./urls";
import CollectionCreate from "./views/CollectionCreate";
import CollectionDetailsView, {
CollectionDetailsQueryParams
@@ -47,9 +47,9 @@ const Component = () => (
<>
<WindowTitle title={i18n.t("Collections")} />
<Switch>
- <Route exact path={collectionListUrl} component={CollectionList} />
- <Route exact path={collectionAddUrl} component={CollectionCreate} />
- <Route path={collectionUrl(":id")} component={CollectionDetails} />
+ <Route exact path={collectionListPath} component={CollectionList} />
+ <Route exact path={collectionAddPath} component={CollectionCreate} />
+ <Route path={collectionPath(":id")} component={CollectionDetails} />
</Switch>
</>
);
diff --git a/saleor/static/dashboard-next/collections/urls.ts b/saleor/static/dashboard-next/collections/urls.ts
index 7f0949ac43..68ee8d2465 100644
--- a/saleor/static/dashboard-next/collections/urls.ts
+++ b/saleor/static/dashboard-next/collections/urls.ts
@@ -1,12 +1,28 @@
import * as urlJoin from "url-join";
const collectionSectionUrl = "/collections/";
+
+export const collectionListPath = collectionSectionUrl;
export const collectionListUrl = collectionSectionUrl;
-export const collectionUrl = (id: string) => urlJoin(collectionSectionUrl, id);
-export const collectionAddUrl = urlJoin(collectionSectionUrl, "add");
+
+export const collectionPath = (id: string) => urlJoin(collectionSectionUrl, id);
+export const collectionUrl = (id: string) =>
+ collectionPath(encodeURIComponent(id));
+
+export const collectionAddPath = urlJoin(collectionSectionUrl, "add");
+export const collectionAddUrl = collectionAddPath;
+
+export const collectionRemovePath = (id: string) =>
+ urlJoin(collectionPath(id), "remove");
export const collectionRemoveUrl = (id: string) =>
- urlJoin(collectionUrl(id), "remove");
+ collectionRemovePath(encodeURIComponent(id));
+
+export const collectionImageRemovePath = (id: string) =>
+ urlJoin(collectionPath(id), "removeImage");
export const collectionImageRemoveUrl = (id: string) =>
- urlJoin(collectionUrl(id), "removeImage");
+ collectionImageRemovePath(encodeURIComponent(id));
+
+export const collectionAddProductPath = (id: string) =>
+ urlJoin(collectionPath(id), "add");
export const collectionAddProductUrl = (id: string) =>
- urlJoin(collectionUrl(id), "add");
+ collectionAddProductPath(encodeURIComponent(id));
diff --git a/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx b/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
index 2aa6e72039..dc3b00af3b 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
@@ -25,11 +25,7 @@ export const CollectionCreate: React.StatelessComponent<{}> = () => (
context: "notification"
})
});
- navigate(
- collectionUrl(
- encodeURIComponent(data.collectionCreate.collection.id)
- )
- );
+ navigate(collectionUrl(data.collectionCreate.collection.id));
}
};
return (
diff --git a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
index 63ce62917e..4b554f2282 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
@@ -184,9 +184,7 @@ export const CollectionDetails: React.StatelessComponent<
<CollectionDetailsPage
onAdd={() =>
navigate(
- collectionAddProductUrl(
- encodeURIComponent(id)
- ),
+ collectionAddProductUrl(id),
false,
true
)
@@ -202,18 +200,14 @@ export const CollectionDetails: React.StatelessComponent<
)}
onCollectionRemove={() =>
navigate(
- collectionRemoveUrl(
- encodeURIComponent(id)
- ),
+ collectionRemoveUrl(id),
false,
true
)
}
onImageDelete={() =>
navigate(
- collectionImageRemoveUrl(
- encodeURIComponent(id)
- ),
+ collectionImageRemoveUrl(id),
false,
true
)
@@ -239,28 +233,20 @@ export const CollectionDetails: React.StatelessComponent<
});
}}
onRowClick={id => () =>
- navigate(
- productUrl(encodeURIComponent(id))
- )}
+ navigate(productUrl(id))}
saveButtonBarState={formTransitionState}
/>
)}
</Paginator>
<Route
- path={collectionAddProductUrl(
- encodeURIComponent(id)
- )}
+ path={collectionAddProductUrl(":id")}
render={({ match }) => (
<CollectionAssignProductDialog
open={!!match}
fetch={searchProducts}
loading={searchProductsOpts.loading}
onClose={() =>
- navigate(
- collectionUrl(encodeURIComponent(id)),
- true,
- true
- )
+ navigate(collectionUrl(id), true, true)
}
onSubmit={product =>
assignProduct.mutate({
@@ -278,17 +264,11 @@ export const CollectionDetails: React.StatelessComponent<
)}
/>
<Route
- path={collectionRemoveUrl(
- encodeURIComponent(id)
- )}
+ path={collectionRemoveUrl(":id")}
render={({ match }) => (
<ActionDialog
onClose={() =>
- navigate(
- collectionUrl(encodeURIComponent(id)),
- true,
- true
- )
+ navigate(collectionUrl(id), true, true)
}
onConfirm={() =>
removeCollection.mutate({ id })
diff --git a/saleor/static/dashboard-next/collections/views/CollectionList.tsx b/saleor/static/dashboard-next/collections/views/CollectionList.tsx
index 91c95794af..a13f6d45c7 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionList.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionList.tsx
@@ -42,8 +42,7 @@ export const CollectionList: React.StatelessComponent<CollectionListProps> = ({
onNextPage={loadNextPage}
onPreviousPage={loadPreviousPage}
pageInfo={pageInfo}
- onRowClick={id => () =>
- navigate(collectionUrl(encodeURIComponent(id)))}
+ onRowClick={id => () => navigate(collectionUrl(id))}
/>
)}
</Paginator>