Skip to content

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

Split urls and paths in product views

dominik-zeglencfde077a75a4
diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
index af34f91c3f..053f764ee2 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
@@ -128,9 +128,7 @@ export const CategoryDetails: React.StatelessComponent<
onPreviousPage={loadPreviousPage}
pageInfo={pageInfo}
onProductClick={id => () =>
- navigate(
- productUrl(encodeURIComponent(id))
- )}
+ navigate(productUrl(id))}
onSubmit={formData =>
updateCategory({
variables: {
diff --git a/saleor/static/dashboard-next/home/views/index.tsx b/saleor/static/dashboard-next/home/views/index.tsx
index a1f6737136..20726a2185 100644
--- a/saleor/static/dashboard-next/home/views/index.tsx
+++ b/saleor/static/dashboard-next/home/views/index.tsx
@@ -26,12 +26,7 @@ const HomeSection = () => (
data.productTopToday.edges.map(edge => edge.node)
)}
onProductClick={(productId, variantId) =>
- navigate(
- productVariantEditUrl(
- encodeURIComponent(productId),
- encodeURIComponent(variantId)
- )
- )
+ navigate(productVariantEditUrl(productId, variantId))
}
onOrdersToCaptureClick={() =>
navigate(
diff --git a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
index a958963dbf..a22ebe5a3b 100644
--- a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
+++ b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
@@ -184,7 +184,7 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
navigate(
orderFulfillmentCancelUrl(
id,
- encodeURIComponent(fulfillmentId)
+ fulfillmentId
)
)
}
@@ -192,7 +192,7 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
navigate(
orderFulfillmentEditTrackingUrl(
id,
- encodeURIComponent(fulfillmentId)
+ fulfillmentId
)
)
}
@@ -206,9 +206,7 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
navigate(orderPaymentRefundUrl(id))
}
onProductClick={id => () =>
- navigate(
- productUrl(encodeURIComponent(id))
- )}
+ navigate(productUrl(id))}
onBillingAddressEdit={() =>
navigate(orderBillingAddressEditUrl(id))
}
diff --git a/saleor/static/dashboard-next/products/index.tsx b/saleor/static/dashboard-next/products/index.tsx
index 67678bc547..f6112ca90d 100644
--- a/saleor/static/dashboard-next/products/index.tsx
+++ b/saleor/static/dashboard-next/products/index.tsx
@@ -5,12 +5,12 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { WindowTitle } from "../components/WindowTitle";
import i18n from "../i18n";
import {
- productAddUrl,
- productImageUrl,
- productListUrl,
- productUrl,
- productVariantAddUrl,
- productVariantEditUrl
+ productAddPath,
+ productImagePath,
+ productListPath,
+ productPath,
+ productVariantAddPath,
+ productVariantEditPath
} from "./urls";
import ProductCreate from "./views/ProductCreate";
import ProductImageComponent from "./views/ProductImage";
@@ -75,22 +75,22 @@ const Component = () => (
<>
<WindowTitle title={i18n.t("Products")} />
<Switch>
- <Route exact path={productListUrl()} component={ProductList} />
- <Route exact path={productAddUrl} component={ProductCreate} />
+ <Route exact path={productListPath} component={ProductList} />
+ <Route exact path={productAddPath} component={ProductCreate} />
<Route
exact
- path={productVariantAddUrl(":id")}
+ path={productVariantAddPath(":id")}
component={ProductVariantCreate}
/>
<Route
- path={productVariantEditUrl(":productId", ":variantId")}
+ path={productVariantEditPath(":productId", ":variantId")}
component={ProductVariant}
/>
<Route
- path={productImageUrl(":productId", ":imageId")}
+ path={productImagePath(":productId", ":imageId")}
component={ProductImage}
/>
- <Route path={productUrl(":id")} component={ProductUpdate} />
+ <Route path={productPath(":id")} component={ProductUpdate} />
</Switch>
</>
);
diff --git a/saleor/static/dashboard-next/products/urls.ts b/saleor/static/dashboard-next/products/urls.ts
index 0a63acbd25..c76ec7256f 100644
--- a/saleor/static/dashboard-next/products/urls.ts
+++ b/saleor/static/dashboard-next/products/urls.ts
@@ -3,21 +3,36 @@ import * as urlJoin from "url-join";
import { ProductListQueryParams } from "./views/ProductList";
const productSection = "/products/";
-export const productAddUrl = urlJoin(productSection, "add");
+
+export const productAddPath = urlJoin(productSection, "add");
+export const productAddUrl = productAddPath;
+
+export const productListPath = productSection;
export const productListUrl = (params?: ProductListQueryParams): string => {
- const productList = productSection;
if (params === undefined) {
- return productList;
+ return productListPath;
} else {
- return urlJoin(productList, "?" + stringifyQs(params));
+ return urlJoin(productListPath, "?" + stringifyQs(params));
}
};
-export const productUrl = (id: string) => urlJoin(productSection, id);
-export const productVariantEditUrl = (productId: string, variantId: string) =>
+
+export const productPath = (id: string) => urlJoin(productSection, id);
+export const productUrl = (id: string) => productPath(encodeURIComponent(id));
+
+export const productVariantEditPath = (productId: string, variantId: string) =>
urlJoin(productSection, productId, "variant", variantId);
+export const productVariantEditUrl = (productId: string, variantId: string) =>
+ productVariantEditPath(
+ encodeURIComponent(productId),
+ encodeURIComponent(variantId)
+ );
-export const productVariantAddUrl = (productId: string) =>
+export const productVariantAddPath = (productId: string) =>
urlJoin(productSection, productId, "variant/add");
+export const productVariantAddUrl = (productId: string) =>
+ productVariantAddPath(encodeURIComponent(productId));
-export const productImageUrl = (productId: string, imageId: string) =>
+export const productImagePath = (productId: string, imageId: string) =>
urlJoin(productSection, productId, "image", imageId);
+export const productImageUrl = (productId: string, imageId: string) =>
+ productImagePath(encodeURIComponent(productId), encodeURIComponent(imageId));
diff --git a/saleor/static/dashboard-next/products/views/ProductCreate.tsx b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
index 8fdc674aa8..531fdc31db 100644
--- a/saleor/static/dashboard-next/products/views/ProductCreate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
@@ -35,11 +35,7 @@ export const ProductUpdate: React.StatelessComponent<
const handleSuccess = (data: ProductCreate) => {
if (data.productCreate.errors.length === 0) {
pushMessage({ text: i18n.t("Product created") });
- navigate(
- productUrl(
- encodeURIComponent(data.productCreate.product.id)
- )
- );
+ navigate(productUrl(data.productCreate.product.id));
}
};
diff --git a/saleor/static/dashboard-next/products/views/ProductImage/index.tsx b/saleor/static/dashboard-next/products/views/ProductImage/index.tsx
index 29a9971c26..94864150c3 100644
--- a/saleor/static/dashboard-next/products/views/ProductImage/index.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductImage/index.tsx
@@ -14,8 +14,8 @@ import {
} from "../../mutations";
import { TypedProductImageQuery } from "../../queries";
import { ProductImageUpdate } from "../../types/ProductImageUpdate";
-import { productImageUrl, productUrl } from "../../urls";
-import { productImageRemoveUrl } from "./urls";
+import { productImageRemovePath, productImageRemoveUrl } from "./urls";
+import { productUrl, productImageUrl } from "../../urls";
interface ProductImageProps {
imageId: string;
@@ -30,8 +30,7 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({
{pushMessage => (
<Navigator>
{navigate => {
- const handleBack = () =>
- navigate(productUrl(encodeURIComponent(productId)));
+ const handleBack = () => navigate(productUrl(productId));
const handleUpdateSuccess = (data: ProductImageUpdate) => {
if (
data.productImageUpdate &&
@@ -59,12 +58,7 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({
const handleDelete = () =>
deleteImage({ variables: { id: imageId } });
const handleImageClick = (id: string) => () =>
- navigate(
- productImageUrl(
- encodeURIComponent(productId),
- encodeURIComponent(id)
- )
- );
+ navigate(productImageUrl(productId, id));
const handleUpdate = (formData: {
description: string;
}) => {
@@ -94,10 +88,7 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({
onBack={handleBack}
onDelete={() =>
navigate(
- productImageRemoveUrl(
- encodeURIComponent(productId),
- encodeURIComponent(imageId)
- )
+ productImageRemoveUrl(productId, imageId)
)
}
onRowClick={handleImageClick}
@@ -105,7 +96,7 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({
saveButtonBarState={formTransitionState}
/>
<Route
- path={productImageRemoveUrl(
+ path={productImageRemovePath(
":productId",
":imageId"
)}
diff --git a/saleor/static/dashboard-next/products/views/ProductImage/urls.ts b/saleor/static/dashboard-next/products/views/ProductImage/urls.ts
index de98840daf..2a18f034e5 100644
--- a/saleor/static/dashboard-next/products/views/ProductImage/urls.ts
+++ b/saleor/static/dashboard-next/products/views/ProductImage/urls.ts
@@ -1,6 +1,11 @@
import * as urlJoin from "url-join";
-import { productImageUrl } from "../../urls";
+import { productImagePath } from "../../urls";
+export const productImageRemovePath = (productId: string, imageId: string) =>
+ urlJoin(productImagePath(productId, imageId), "remove");
export const productImageRemoveUrl = (productId: string, imageId: string) =>
- urlJoin(productImageUrl(productId, imageId), "remove");
+ productImageRemovePath(
+ encodeURIComponent(productId),
+ encodeURIComponent(imageId)
+ );
diff --git a/saleor/static/dashboard-next/products/views/ProductList.tsx b/saleor/static/dashboard-next/products/views/ProductList.tsx
index 65149080cd..8ba0e3080a 100644
--- a/saleor/static/dashboard-next/products/views/ProductList.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductList.tsx
@@ -1,7 +1,6 @@
import { stringify as stringifyQs } from "qs";
import * as React from "react";
-import ErrorMessageCard from "../../components/ErrorMessageCard";
import Navigator from "../../components/Navigator";
import { createPaginationState, Paginator } from "../../components/Paginator";
import { maybe } from "../../misc";
@@ -49,11 +48,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
stockAvailability: params.status
}}
>
- {({ data, loading, error }) => {
- if (error) {
- return <ErrorMessageCard message="Something went wrong" />;
- }
-
+ {({ data, loading }) => {
const currentTab = getTabName(params);
return (
<Paginator
@@ -77,8 +72,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
onNextPage={loadNextPage}
onPreviousPage={loadPreviousPage}
pageInfo={pageInfo}
- onRowClick={id => () =>
- navigate(productUrl(encodeURIComponent(id)))}
+ onRowClick={id => () => navigate(productUrl(id))}
onAllProducts={() =>
changeFilters({
status: undefined
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
index f93cf8fb8d..1717bbb1d5 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
@@ -22,7 +22,7 @@ import {
productVariantAddUrl,
productVariantEditUrl
} from "../../urls";
-import { productRemoveUrl } from "./urls";
+import { productRemovePath, productRemoveUrl } from "./urls";
interface ProductUpdateProps {
id: string;
@@ -58,7 +58,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
text: i18n.t("Image successfully deleted")
});
const handleVariantAdd = () =>
- navigate(productVariantAddUrl(encodeURIComponent(id)));
+ navigate(productVariantAddUrl(id));
const product = data ? data.product : undefined;
const allCollections =
@@ -88,12 +88,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
const handleImageDelete = (id: string) => () =>
deleteProductImage.mutate({ id });
const handleImageEdit = (imageId: string) => () =>
- navigate(
- productImageUrl(
- encodeURIComponent(id),
- encodeURIComponent(imageId)
- )
- );
+ navigate(productImageUrl(id, imageId));
const handleSubmit = data => {
if (product) {
updateProduct.mutate({
@@ -156,11 +151,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
onBack={() => {
navigate(productListUrl());
}}
- onDelete={() =>
- navigate(
- productRemoveUrl(encodeURIComponent(id))
- )
- }
+ onDelete={() => navigate(productRemoveUrl(id))}
onProductShow={() => {
if (product) {
window.open(product.url);
@@ -182,10 +173,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
onVariantAdd={handleVariantAdd}
onVariantShow={variantId => () =>
navigate(
- productVariantEditUrl(
- encodeURIComponent(product.id),
- encodeURIComponent(variantId)
- )
+ productVariantEditUrl(product.id, variantId)
)}
onImageUpload={event => {
if (product) {
@@ -200,13 +188,11 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
onImageDelete={handleImageDelete}
/>
<Route
- path={productRemoveUrl(":id")}
+ path={productRemovePath(":id")}
render={({ match }) => (
<ActionDialog
open={!!match}
- onClose={() =>
- navigate(productUrl(encodeURIComponent(id)))
- }
+ onClose={() => navigate(productUrl(id))}
onConfirm={() => deleteProduct.mutate({ id })}
variant="delete"
title={i18n.t("Remove product")}
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/urls.ts b/saleor/static/dashboard-next/products/views/ProductUpdate/urls.ts
index 327e2376ae..323f096555 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate/urls.ts
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate/urls.ts
@@ -1,5 +1,7 @@
import * as urlJoin from "url-join";
-import { productUrl } from "../../urls";
+import { productPath } from "../../urls";
+export const productRemovePath = (id: string) =>
+ urlJoin(productPath(id), "remove");
export const productRemoveUrl = (id: string) =>
- urlJoin(productUrl(id), "remove");
+ productRemovePath(encodeURIComponent(id));
diff --git a/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx b/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx
index 1a2d946292..acf42c7557 100644
--- a/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx
@@ -14,7 +14,7 @@ import ProductVariantOperations from "../../containers/ProductVariantOperations"
import { TypedProductVariantQuery } from "../../queries";
import { VariantUpdate } from "../../types/VariantUpdate";
import { productUrl, productVariantEditUrl } from "../../urls";
-import { productVariantRemoveUrl } from "./urls";
+import { productVariantRemovePath, productVariantRemoveUrl } from "./urls";
interface ProductUpdateProps {
variantId: string;
@@ -47,11 +47,10 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
return <ErrorMessageCard message="Something went wrong" />;
}
const variant = data ? data.productVariant : undefined;
- const handleBack = () =>
- navigate(productUrl(encodeURIComponent(productId)));
+ const handleBack = () => navigate(productUrl(productId));
const handleDelete = () => {
pushMessage({ text: i18n.t("Variant removed") });
- navigate(productUrl(encodeURIComponent(productId)));
+ navigate(productUrl(productId));
};
const handleUpdate = (data: VariantUpdate) => {
if (!maybe(() => data.productVariantUpdate.errors.length)) {
@@ -123,10 +122,7 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
onBack={handleBack}
onDelete={() =>
navigate(
- productVariantRemoveUrl(
- encodeURIComponent(productId),
- encodeURIComponent(variantId)
- )
+ productVariantRemoveUrl(productId, variantId)
)
}
onImageSelect={handleImageSelect}
@@ -147,15 +143,12 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
}}
onVariantClick={variantId => {
navigate(
- productVariantEditUrl(
- encodeURIComponent(productId),
- encodeURIComponent(variantId)
- )
+ productVariantEditUrl(productId, variantId)
);
}}
/>
<Route
- path={productVariantRemoveUrl(
+ path={productVariantRemovePath(
":productId",
":variantId"
)}
@@ -163,10 +156,7 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
<ProductVariantDeleteDialog
onClose={() =>
navigate(
- productVariantEditUrl(
- encodeURIComponent(productId),
- encodeURIComponent(variantId)
- )
+ productVariantEditUrl(productId, variantId)
)
}
onConfirm={() => deleteVariant.mutate(variantId)}
diff --git a/saleor/static/dashboard-next/products/views/ProductVariant/urls.ts b/saleor/static/dashboard-next/products/views/ProductVariant/urls.ts
index b4f9be714c..5ba178ac2e 100644
--- a/saleor/static/dashboard-next/products/views/ProductVariant/urls.ts
+++ b/saleor/static/dashboard-next/products/views/ProductVariant/urls.ts
@@ -1,5 +1,12 @@
import * as urlJoin from "url-join";
-import { productVariantEditUrl } from "../../urls";
+import { productVariantEditPath } from "../../urls";
+export const productVariantRemovePath = (
+ productId: string,
+ variantId: string
+) => urlJoin(productVariantEditPath(productId, variantId), "remove");
export const productVariantRemoveUrl = (productId: string, variantId: string) =>
- urlJoin(productVariantEditUrl(productId, variantId), "remove");
+ productVariantRemovePath(
+ encodeURIComponent(productId),
+ encodeURIComponent(variantId)
+ );
diff --git a/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx b/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx
index d9ed358ff3..3916c11976 100644
--- a/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx
@@ -41,15 +41,7 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
displayLoader
variables={{ id: productId }}
>
- {({ data, error, loading: productLoading }) => {
- if (error) {
- return (
- <ErrorMessageCard
- message={i18n.t("Something went wrong")}
- />
- );
- }
-
+ {({ data, loading: productLoading }) => {
const handleCreateSuccess = (data: VariantCreate) => {
if (
data.productVariantCreate.errors === null ||
@@ -58,10 +50,8 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
pushMessage({ text: i18n.t("Product created") });
navigate(
productVariantEditUrl(
- encodeURIComponent(productId),
- encodeURIComponent(
- data.productVariantCreate.productVariant.id
- )
+ productId,
+ data.productVariantCreate.productVariant.id
)
);
}
@@ -81,7 +71,7 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
}
const handleBack = () =>
- navigate(productUrl(encodeURIComponent(productId)));
+ navigate(productUrl(productId));
const handleSubmit = (formData: FormData) =>
variantCreate({
variables: {
@@ -95,12 +85,7 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
}
});
const handleVariantClick = (id: string) =>
- navigate(
- productVariantEditUrl(
- encodeURIComponent(productId),
- encodeURIComponent(id)
- )
- );
+ navigate(productVariantEditUrl(productId, id));
const disableForm =
productLoading || variantCreateResult.loading;