Skip to content

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

Add product views titles

dominik-zeglena2bc4065a376
diff --git a/saleor/static/dashboard-next/products/index.tsx b/saleor/static/dashboard-next/products/index.tsx
index 51bfb81fbb..6e1b2d8d06 100644
--- a/saleor/static/dashboard-next/products/index.tsx
+++ b/saleor/static/dashboard-next/products/index.tsx
@@ -2,6 +2,8 @@ import { parse as parseQs } from "qs";
import * as React from "react";
import { Route, RouteComponentProps, Switch } from "react-router-dom";
+import { WindowTitle } from "../components/WindowTitle";
+import i18n from "../i18n";
import ProductCreate from "./views/ProductCreate";
import ProductImageComponent from "./views/ProductImage";
import ProductListComponent, {
@@ -61,26 +63,29 @@ const ProductVariantCreate: React.StatelessComponent<
};
const Component = ({ match }) => (
- <Switch>
- <Route exact path={match.url} component={ProductList} />
- <Route exact path={`${match.url}/add/`} component={ProductCreate} />
- <Route exact path={`${match.url}/:id/`} component={ProductUpdate} />
- <Route
- exact
- path={`${match.url}/:id/variant/add/`}
- component={ProductVariantCreate}
- />
- <Route
- exact
- path={`${match.url}/:productId/variant/:variantId/`}
- component={ProductVariant}
- />
- <Route
- exact
- path={`${match.url}/:productId/image/:imageId/`}
- component={ProductImage}
- />
- </Switch>
+ <>
+ <WindowTitle title={i18n.t("Products")} />
+ <Switch>
+ <Route exact path={match.url} component={ProductList} />
+ <Route exact path={`${match.url}/add/`} component={ProductCreate} />
+ <Route exact path={`${match.url}/:id/`} component={ProductUpdate} />
+ <Route
+ exact
+ path={`${match.url}/:id/variant/add/`}
+ component={ProductVariantCreate}
+ />
+ <Route
+ exact
+ path={`${match.url}/:productId/variant/:variantId/`}
+ component={ProductVariant}
+ />
+ <Route
+ exact
+ path={`${match.url}/:productId/image/:imageId/`}
+ component={ProductImage}
+ />
+ </Switch>
+ </>
);
export const productUrl = (id: string) => {
diff --git a/saleor/static/dashboard-next/products/views/ProductCreate.tsx b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
index 212e619d2e..74bfdf36dd 100644
--- a/saleor/static/dashboard-next/products/views/ProductCreate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
@@ -10,6 +10,7 @@ import { productListUrl, productUrl } from "../index";
import { TypedProductCreateMutation } from "../mutations";
import { productCreateQuery, TypedProductCreateQuery } from "../queries";
import { ProductCreate } from "../types/ProductCreate";
+import { WindowTitle } from "../../components/WindowTitle";
interface ProductUpdateProps {
id: string;
@@ -79,37 +80,44 @@ export const ProductUpdate: React.StatelessComponent<
const disabled = loading || productCreateDataLoading;
return (
- <ProductCreatePage
- // FIXME: this should be fetched from API
- currency="USD"
- categories={
- data && data.categories
- ? data.categories.edges.map(edge => edge.node)
- : undefined
- }
- collections={
- data && data.collections
- ? data.collections.edges.map(edge => edge.node)
- : undefined
- }
- disabled={disabled}
- errors={
- productCreateData &&
- productCreateData.productCreate &&
- productCreateData.productCreate.errors
- ? productCreateData.productCreate.errors
- : []
- }
- header={i18n.t("New Product")}
- productTypes={
- data && data.productTypes
- ? data.productTypes.edges.map(edge => edge.node)
- : undefined
- }
- onAttributesEdit={handleAttributesEdit}
- onBack={handleBack}
- onSubmit={handleSubmit}
- />
+ <>
+ <WindowTitle title={i18n.t("Create product")} />
+ <ProductCreatePage
+ // FIXME: this should be fetched from API
+ currency="USD"
+ categories={
+ data && data.categories
+ ? data.categories.edges.map(edge => edge.node)
+ : undefined
+ }
+ collections={
+ data && data.collections
+ ? data.collections.edges.map(
+ edge => edge.node
+ )
+ : undefined
+ }
+ disabled={disabled}
+ errors={
+ productCreateData &&
+ productCreateData.productCreate &&
+ productCreateData.productCreate.errors
+ ? productCreateData.productCreate.errors
+ : []
+ }
+ header={i18n.t("New Product")}
+ productTypes={
+ data && data.productTypes
+ ? data.productTypes.edges.map(
+ edge => edge.node
+ )
+ : undefined
+ }
+ onAttributesEdit={handleAttributesEdit}
+ onBack={handleBack}
+ onSubmit={handleSubmit}
+ />
+ </>
);
}}
</TypedProductCreateMutation>
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
index 0d8f102b98..2d1feb9b65 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
@@ -5,8 +5,9 @@ import * as placeholderImg from "../../../images/placeholder255x255.png";
import ErrorMessageCard from "../../components/ErrorMessageCard";
import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
+import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
-import { decimal } from "../../misc";
+import { decimal, maybe } from "../../misc";
import { productTypeDetailsUrl } from "../../productTypes";
import ProductUpdatePage from "../components/ProductUpdatePage";
import ProductUpdateOperations from "../containers/ProductUpdateOperations";
@@ -126,77 +127,84 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
? "loading"
: "idle";
return (
- <ProductUpdatePage
- categories={allCategories}
- collections={allCollections}
- disabled={disableFormSave}
- errors={errors}
- saveButtonBarState={formSubmitState}
- images={images}
- header={product ? product.name : undefined}
- placeholderImage={placeholderImg}
- product={product}
- productCollections={
- product && product.collections
- ? product.collections.edges.map(
- edge => edge.node
- )
- : undefined
- }
- variants={
- product && product.variants
- ? product.variants.edges.map(edge => edge.node)
- : undefined
- }
- onAttributesEdit={() =>
- navigate(
- productTypeDetailsUrl(
- encodeURIComponent(
- data.product.productType.id
- )
- )
- )
- }
- onBack={() => {
- navigate(productListUrl);
- }}
- onDelete={() => deleteProduct.mutate({ id })}
- onProductShow={() => {
- if (product) {
- window.open(product.url);
+ <>
+ <WindowTitle
+ title={maybe(() => data.product.name)}
+ />
+ <ProductUpdatePage
+ categories={allCategories}
+ collections={allCollections}
+ disabled={disableFormSave}
+ errors={errors}
+ saveButtonBarState={formSubmitState}
+ images={images}
+ header={product ? product.name : undefined}
+ placeholderImage={placeholderImg}
+ product={product}
+ productCollections={
+ product && product.collections
+ ? product.collections.edges.map(
+ edge => edge.node
+ )
+ : undefined
}
- }}
- onImageReorder={({ newIndex, oldIndex }) => {
- if (product) {
- let ids = images.map(image => image.id);
- ids = arrayMove(ids, oldIndex, newIndex);
- reorderProductImages.mutate({
- imagesIds: ids,
- productId: product.id
- });
+ variants={
+ product && product.variants
+ ? product.variants.edges.map(
+ edge => edge.node
+ )
+ : undefined
}
- }}
- onSubmit={handleSubmit}
- onVariantAdd={handleVariantAdd}
- onVariantShow={variantId => () =>
- navigate(
- productVariantEditUrl(
- encodeURIComponent(product.id),
- encodeURIComponent(variantId)
+ onAttributesEdit={() =>
+ navigate(
+ productTypeDetailsUrl(
+ encodeURIComponent(
+ data.product.productType.id
+ )
+ )
)
- )}
- onImageUpload={event => {
- if (product) {
- createProductImage.mutate({
- alt: "",
- image: event.target.files[0],
- product: product.id
- });
}
- }}
- onImageEdit={handleImageEdit}
- onImageDelete={handleImageDelete}
- />
+ onBack={() => {
+ navigate(productListUrl);
+ }}
+ onDelete={() => deleteProduct.mutate({ id })}
+ onProductShow={() => {
+ if (product) {
+ window.open(product.url);
+ }
+ }}
+ onImageReorder={({ newIndex, oldIndex }) => {
+ if (product) {
+ let ids = images.map(image => image.id);
+ ids = arrayMove(ids, oldIndex, newIndex);
+ reorderProductImages.mutate({
+ imagesIds: ids,
+ productId: product.id
+ });
+ }
+ }}
+ onSubmit={handleSubmit}
+ onVariantAdd={handleVariantAdd}
+ onVariantShow={variantId => () =>
+ navigate(
+ productVariantEditUrl(
+ encodeURIComponent(product.id),
+ encodeURIComponent(variantId)
+ )
+ )}
+ onImageUpload={event => {
+ if (product) {
+ createProductImage.mutate({
+ alt: "",
+ image: event.target.files[0],
+ product: product.id
+ });
+ }
+ }}
+ onImageEdit={handleImageEdit}
+ onImageDelete={handleImageDelete}
+ />
+ </>
);
}}
</ProductUpdateOperations>
diff --git a/saleor/static/dashboard-next/products/views/ProductVariant.tsx b/saleor/static/dashboard-next/products/views/ProductVariant.tsx
index ecb5e0aa90..5d4d753e4c 100644
--- a/saleor/static/dashboard-next/products/views/ProductVariant.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductVariant.tsx
@@ -5,6 +5,7 @@ import * as placeholderImg from "../../../images/placeholder255x255.png";
import ErrorMessageCard from "../../components/ErrorMessageCard";
import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
+import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
import { decimal, maybe } from "../../misc";
import ProductVariantPage from "../components/ProductVariantPage";
@@ -104,42 +105,47 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
};
return (
- <ProductVariantPage
- errors={errors}
- saveButtonBarState={formSubmitState}
- loading={disableFormSave}
- placeholderImage={placeholderImg}
- variant={variant}
- header={
- variant ? variant.name || variant.sku : undefined
- }
- onBack={handleBack}
- onDelete={() => deleteVariant.mutate(variantId)}
- onImageSelect={handleImageSelect}
- onSubmit={(data: FormData) => {
- if (variant) {
- updateVariant.mutate({
- attributes: data.attributes
- ? data.attributes
- : null,
- costPrice: decimal(data.costPrice),
- id: variantId,
- priceOverride: decimal(data.priceOverride),
- quantity: data.quantity || null,
- sku: data.sku,
- trackInventory: true // FIXME: missing in UI
- });
+ <>
+ <WindowTitle
+ title={maybe(() => data.productVariant.name)}
+ />
+ <ProductVariantPage
+ errors={errors}
+ saveButtonBarState={formSubmitState}
+ loading={disableFormSave}
+ placeholderImage={placeholderImg}
+ variant={variant}
+ header={
+ variant ? variant.name || variant.sku : undefined
}
- }}
- onVariantClick={variantId => {
- navigate(
- productVariantEditUrl(
- encodeURIComponent(productId),
- encodeURIComponent(variantId)
- )
- );
- }}
- />
+ onBack={handleBack}
+ onDelete={() => deleteVariant.mutate(variantId)}
+ onImageSelect={handleImageSelect}
+ onSubmit={(data: FormData) => {
+ if (variant) {
+ updateVariant.mutate({
+ attributes: data.attributes
+ ? data.attributes
+ : null,
+ costPrice: decimal(data.costPrice),
+ id: variantId,
+ priceOverride: decimal(data.priceOverride),
+ quantity: data.quantity || null,
+ sku: data.sku,
+ trackInventory: true // FIXME: missing in UI
+ });
+ }
+ }}
+ onVariantClick={variantId => {
+ navigate(
+ productVariantEditUrl(
+ encodeURIComponent(productId),
+ encodeURIComponent(variantId)
+ )
+ );
+ }}
+ />
+ </>
);
}}
</ProductVariantOperations>
diff --git a/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx b/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx
index 8cbe7fab0e..a6b4c595cb 100644
--- a/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx
@@ -4,6 +4,7 @@ import { productUrl, productVariantEditUrl } from "..";
import ErrorMessageCard from "../../components/ErrorMessageCard";
import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
+import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
import { decimal, maybe } from "../../misc";
import ProductVariantCreatePage from "../components/ProductVariantCreatePage";
@@ -100,20 +101,23 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
const loading =
productLoading || variantCreateResult.loading;
return (
- <ProductVariantCreatePage
- errors={maybe(
- () =>
- variantCreateResult.data.productVariantCreate
- .errors,
- []
- )}
- header={i18n.t("Add Variant")}
- loading={loading}
- product={maybe(() => data.product)}
- onBack={handleBack}
- onSubmit={handleSubmit}
- onVariantClick={handleVariantClick}
- />
+ <>
+ <WindowTitle title={i18n.t("Create variant")} />
+ <ProductVariantCreatePage
+ errors={maybe(
+ () =>
+ variantCreateResult.data.productVariantCreate
+ .errors,
+ []
+ )}
+ header={i18n.t("Add Variant")}
+ loading={loading}
+ product={maybe(() => data.product)}
+ onBack={handleBack}
+ onSubmit={handleSubmit}
+ onVariantClick={handleVariantClick}
+ />
+ </>
);
}}
</TypedVariantCreateMutation>