Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Replace select field with autocomplete in collection choice
dominik-zeglen5c09626c9240
diff --git a/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx b/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsxindex a9d41aed23..1a450e8132 100644--- a/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx+++ b/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx@@ -13,6 +13,7 @@ import * as React from "react";import i18n from "../../i18n";import ArrowDropdownIcon from "../../icons/ArrowDropdown";+import Debounce, { DebounceProps } from "../Debounce";interface ChoiceType {label: string;@@ -52,6 +53,10 @@ interface MultiAutocompleteSelectFieldProps extends WithStyles<typeof styles> {onChange(event);}+const DebounceAutocomplete: React.ComponentType<+ DebounceProps<string>+> = Debounce;+export const MultiAutocompleteSelectField = withStyles(styles, {name: "MultiAutocompleteSelectField"})(@@ -75,8 +80,12 @@ export const MultiAutocompleteSelectField = withStyles(styles, {onChange({ target: { name, value: [...value, item] } });};const handleDelete = (item: ChoiceType) => () => {- value.splice(value.indexOf(item), 1);- onChange({ target: { name, value } });+ const newValue = value.slice();+ newValue.splice(+ value.findIndex(listItem => listItem.value === item.value),+ 1+ );+ onChange({ target: { name, value: newValue } });};const handleKeyDown = (inputValue: string | null) => (event: React.KeyboardEvent<any>@@ -101,78 +110,83 @@ export const MultiAutocompleteSelectField = withStyles(styles, {);return (- <Downshift- selectedItem={value}- itemToString={item => (item ? item.label : "")}- onSelect={handleSelect}- onInputValueChange={fetchChoices}- >- {({- getInputProps,- getItemProps,- isOpen,- inputValue,- selectedItem,- highlightedIndex- }) => {- return (- <div className={classes.container}>- <TextField- InputProps={{- classes: {- root: classes.inputRoot- },- ...getInputProps({- onKeyDown: handleKeyDown(inputValue),- placeholder- }),- endAdornment: <ArrowDropdownIcon />,- startAdornment: selectedItem.map(item => (- <Chip- key={item.value}- tabIndex={-1}- label={item.label}- className={classes.chip}- onDelete={handleDelete(item)}- />- ))- }}- helperText={helperText}- label={label}- fullWidth={true}- />- {isOpen && (- <Paper className={classes.paper} square>- {loading ? (- <MenuItem disabled={true} component="div">- {i18n.t("Loading...")}- </MenuItem>- ) : (- <>- {filteredChoices.length > 0- ? filteredChoices.map((suggestion, index) => (- <MenuItem- key={suggestion.value}- selected={highlightedIndex === index}- component="div"- {...getItemProps({ item: suggestion })}- >- {suggestion.label}- </MenuItem>- ))- : !loading && (- <MenuItem disabled={true} component="div">- {i18n.t("No results found")}- </MenuItem>- )}- </>+ <DebounceAutocomplete debounceFn={fetchChoices}>+ {debounce => (+ <Downshift+ selectedItem={value}+ itemToString={item => (item ? item.label : "")}+ onSelect={handleSelect}+ onInputValueChange={value => debounce(value)}+ >+ {({+ getInputProps,+ getItemProps,+ isOpen,+ inputValue,+ selectedItem,+ toggleMenu,+ highlightedIndex+ }) => {+ return (+ <div className={classes.container}>+ <TextField+ InputProps={{+ classes: {+ root: classes.inputRoot+ },+ ...getInputProps({+ onKeyDown: handleKeyDown(inputValue),+ placeholder+ }),+ endAdornment: <ArrowDropdownIcon onClick={toggleMenu} />,+ startAdornment: selectedItem.map(item => (+ <Chip+ key={item.value}+ tabIndex={-1}+ label={item.label}+ className={classes.chip}+ onDelete={handleDelete(item)}+ />+ ))+ }}+ helperText={helperText}+ label={label}+ fullWidth={true}+ />+ {isOpen && (+ <Paper className={classes.paper} square>+ {loading ? (+ <MenuItem disabled={true} component="div">+ {i18n.t("Loading...")}+ </MenuItem>+ ) : (+ <>+ {filteredChoices.length > 0+ ? filteredChoices.map((suggestion, index) => (+ <MenuItem+ key={suggestion.value}+ selected={highlightedIndex === index}+ component="div"+ {...getItemProps({ item: suggestion })}+ >+ {suggestion.label}+ </MenuItem>+ ))+ : !loading && (+ <MenuItem disabled={true} component="div">+ {i18n.t("No results found")}+ </MenuItem>+ )}+ </>+ )}+ </Paper>)}- </Paper>- )}- </div>- );- }}- </Downshift>+ </div>+ );+ }}+ </Downshift>+ )}+ </DebounceAutocomplete>);});diff --git a/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx b/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsxindex 32675a0771..53107dc5c1 100644--- a/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx+++ b/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx@@ -99,6 +99,7 @@ const SingleAutocompleteSelectFieldComponent = withStyles(styles, {isOpen,inputValue,selectedItem,+ toggleMenu,highlightedIndex}) => {const isCustom =@@ -116,7 +117,7 @@ const SingleAutocompleteSelectFieldComponent = withStyles(styles, {...getInputProps({placeholder}),- endAdornment: <ArrowDropdownIcon />+ endAdornment: <ArrowDropdownIcon onClick={toggleMenu} />}}disabled={disabled}helperText={helperText}diff --git a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsxindex ebb121fae5..fa2a9fd3b9 100644--- a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx+++ b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx@@ -11,7 +11,7 @@ import * as React from "react";import CardTitle from "../../../components/CardTitle";import { FormSpacer } from "../../../components/FormSpacer";-import MultiSelectField from "../../../components/MultiSelectField";+import MultiAutocompleteSelectField from "../../../components/MultiAutocompleteSelectField";import SingleAutocompleteSelectField from "../../../components/SingleAutocompleteSelectField";import SingleSelectField from "../../../components/SingleSelectField";import Skeleton from "../../../components/Skeleton";@@ -19,6 +19,10 @@ import i18n from "../../../i18n";import { maybe } from "../../../misc";import { ProductCreateData_productTypes_edges_node_productAttributes } from "../../types/ProductCreateData";+interface ChoiceType {+ label: string;+ value: string;+}interface ProductType {hasVariants: boolean;id: string;@@ -46,16 +50,13 @@ const styles = (theme: Theme) =>interface ProductOrganizationProps extends WithStyles<typeof styles> {categories?: Array<{ value: string; label: string }>;collections?: Array<{ value: string; label: string }>;- productCollections: string[];data: {attributes: Array<{slug: string;value: string;}>;- category: {- label: string;- value: string;- };+ category: ChoiceType;+ collections: ChoiceType[];productType: {label: string;value: {@@ -76,6 +77,7 @@ interface ProductOrganizationProps extends WithStyles<typeof styles> {};productTypes?: ProductType[];fetchCategories: (query: string) => void;+ fetchCollections: (query: string) => void;onChange: (event: React.ChangeEvent<any>) => void;}@@ -86,10 +88,9 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(collections,data,disabled,- errors,fetchCategories,+ fetchCollections,product,- productCollections,productTypes,onChange}: ProductOrganizationProps) => {@@ -240,15 +241,13 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(/><FormSpacer /><hr className={classes.hr} />- <MultiSelectField- disabled={disabled}- error={!!errors.collections}- hint={errors.collections}+ <MultiAutocompleteSelectFieldlabel={i18n.t("Collections")}choices={disabled ? [] : collections}name="collections"- value={productCollections}+ value={data.collections}onChange={onChange}+ fetchChoices={fetchCollections}/></CardContent></Card>diff --git a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsxindex 3289a58bcf..2ce0ce19d8 100644--- a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx+++ b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx@@ -16,6 +16,7 @@ import i18n from "../../../i18n";import { UserError } from "../../../types";import {ProductDetails_product,+ ProductDetails_product_attributes_attribute,ProductDetails_product_images,ProductDetails_product_variants_priceOverride} from "../../types/ProductDetails";@@ -77,6 +78,7 @@ interface ProductUpdateProps extends WithStyles<typeof styles> {header: string;saveButtonBarState: ConfirmButtonTransitionState;fetchCategories: (query: string) => void;+ fetchCollections: (query: string) => void;onVariantShow: (id: string) => () => void;onImageDelete: (id: string) => () => void;onAttributesEdit: () => void;@@ -91,6 +93,40 @@ interface ProductUpdateProps extends WithStyles<typeof styles> {onVariantAdd?();}+interface ChoiceType {+ label: string;+ value: string;+}+export interface FormData {+ attributes: Array<{+ slug: string;+ value: string;+ }>;+ available: boolean;+ availableOn: string;+ category: ChoiceType | null;+ chargeTaxes: boolean;+ collections: ChoiceType[];+ description: string;+ name: string;+ price: string;+ productType: {+ label: string;+ value: {+ hasVariants: boolean;+ id: string;+ name: string;+ productAttributes: Array<+ Exclude<ProductDetails_product_attributes_attribute, "__typename">+ >;+ };+ } | null;+ seoDescription: string;+ seoTitle: string;+ sku: string;+ stockQuantity: number;+}+export const ProductUpdate = withStyles(styles, { name: "ProductUpdate" })(({classes,@@ -99,6 +135,7 @@ export const ProductUpdate = withStyles(styles, { name: "ProductUpdate" })(collections: collectionChoiceList,errors: userErrors,fetchCategories,+ fetchCollections,images,header,placeholderImage,@@ -118,7 +155,7 @@ export const ProductUpdate = withStyles(styles, { name: "ProductUpdate" })(onVariantAdd,onVariantShow}: ProductUpdateProps) => {- const initialData = product+ const initialData: FormData = product? {attributes: product.attributes? product.attributes.map(a => ({@@ -136,7 +173,10 @@ export const ProductUpdate = withStyles(styles, { name: "ProductUpdate" })(: undefined,chargeTaxes: product.chargeTaxes ? product.chargeTaxes : false,collections: productCollections- ? productCollections.map(node => node.id)+ ? productCollections.map(collection => ({+ label: collection.name,+ value: collection.id+ })): [],description: product.description,name: product.name,@@ -169,14 +209,20 @@ export const ProductUpdate = withStyles(styles, { name: "ProductUpdate" })(: undefined}: {+ attributes: [],+ available: false,availableOn: "",+ category: null,chargeTaxes: false,collections: [],description: "",- featured: false,name: "",+ price: "",+ productType: null,seoDescription: "",- seoTitle: ""+ seoTitle: "",+ sku: "",+ stockQuantity: 0};const categories =categoryChoiceList !== undefined@@ -266,7 +312,7 @@ export const ProductUpdate = withStyles(styles, { name: "ProductUpdate" })(categories={categories}errors={errors}fetchCategories={fetchCategories}- productCollections={data.collections}+ fetchCollections={fetchCollections}collections={collections}product={product}data={data}diff --git a/saleor/static/dashboard-next/products/containers/CollectionSearch.tsx b/saleor/static/dashboard-next/products/containers/CollectionSearch.tsxnew file mode 100644index 0000000000..53886bb188--- /dev/null+++ b/saleor/static/dashboard-next/products/containers/CollectionSearch.tsx@@ -0,0 +1,39 @@+import * as React from "react";+import { QueryResult } from "react-apollo";+import { TypedCollectionSearchQuery } from "../queries";+import {+ CollectionSearch,+ CollectionSearchVariables+} from "../types/CollectionSearch";++interface CollectionSearchProviderProps {+ children: ((+ props: {+ search: (query: string) => void;+ searchOpts: QueryResult<CollectionSearch, CollectionSearchVariables>;+ }+ ) => React.ReactElement<any>);+}+interface CollectionSearchProviderState {+ query: string;+}++export class CollectionSearchProvider extends React.Component<+ CollectionSearchProviderProps,+ CollectionSearchProviderState+> {+ state: CollectionSearchProviderState = { query: "" };++ search = (query: string) => this.setState({ query });++ render() {+ return (+ <TypedCollectionSearchQuery+ variables={{ query: this.state.query }}+ skip={!this.state.query}+ >+ {searchOpts => this.props.children({ search: this.search, searchOpts })}+ </TypedCollectionSearchQuery>+ );+ }+}diff --git a/saleor/static/dashboard-next/products/queries.ts b/saleor/static/dashboard-next/products/queries.tsindex f35bd5a735..d3ecd5667d 100644--- a/saleor/static/dashboard-next/products/queries.ts+++ b/saleor/static/dashboard-next/products/queries.ts@@ -5,6 +5,10 @@ import {CategorySearch,CategorySearchVariables} from "./types/CategorySearch";+import {+ CollectionSearch,+ CollectionSearchVariables+} from "./types/CollectionSearch";import { ProductCreateData } from "./types/ProductCreateData";import {ProductDetails,@@ -237,14 +241,6 @@ const productDetailsQuery = gql`product(id: $id) {...Product}- collections(first: 20) {- edges {- node {- id- name- }- }- }}`;export const TypedProductDetailsQuery = TypedQuery<@@ -287,14 +283,6 @@ const productCreateQuery = gql`}}}- collections(first: 20) {- edges {- node {- id- name- }- }- }}`;export const TypedProductCreateQuery = TypedQuery<ProductCreateData, {}>(@@ -378,3 +366,20 @@ export const TypedCategorySearchQuery = TypedQuery<CategorySearch,CategorySearchVariables>(categorySearch);++const collectionSearch = gql`+ query CollectionSearch($query: String) {+ collections(first: 5, query: $query) {+ edges {+ node {+ id+ name+ }+ }+ }+ }+`;+export const TypedCollectionSearchQuery = TypedQuery<+ CollectionSearch,+ CollectionSearchVariables+>(collectionSearch);diff --git a/saleor/static/dashboard-next/products/types/CollectionSearch.ts b/saleor/static/dashboard-next/products/types/CollectionSearch.tsnew file mode 100644index 0000000000..9c83fd5a61--- /dev/null+++ b/saleor/static/dashboard-next/products/types/CollectionSearch.ts@@ -0,0 +1,30 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL query operation: CollectionSearch+// ====================================================++export interface CollectionSearch_collections_edges_node {+ __typename: "Collection";+ id: string;+ name: string;+}++export interface CollectionSearch_collections_edges {+ __typename: "CollectionCountableEdge";+ node: CollectionSearch_collections_edges_node;+}++export interface CollectionSearch_collections {+ __typename: "CollectionCountableConnection";+ edges: CollectionSearch_collections_edges[];+}++export interface CollectionSearch {+ collections: CollectionSearch_collections | null;+}++export interface CollectionSearchVariables {+ query?: string | null;+}diff --git a/saleor/static/dashboard-next/products/types/ProductCreateData.ts b/saleor/static/dashboard-next/products/types/ProductCreateData.tsindex 90c613511e..4f20953f04 100644--- a/saleor/static/dashboard-next/products/types/ProductCreateData.ts+++ b/saleor/static/dashboard-next/products/types/ProductCreateData.ts@@ -55,24 +55,7 @@ export interface ProductCreateData_collections {edges: ProductCreateData_collections_edges[];}-export interface ProductCreateData_categories_edges_node {- __typename: "Category";- id: string;- name: string;-}--export interface ProductCreateData_categories_edges {- __typename: "CategoryCountableEdge";- node: ProductCreateData_categories_edges_node;-}--export interface ProductCreateData_categories {- __typename: "CategoryCountableConnection";- edges: ProductCreateData_categories_edges[];-}-export interface ProductCreateData {productTypes: ProductCreateData_productTypes | null;collections: ProductCreateData_collections | null;- categories: ProductCreateData_categories | null;}diff --git a/saleor/static/dashboard-next/products/types/ProductDetails.ts b/saleor/static/dashboard-next/products/types/ProductDetails.tsindex 1764e7d340..049d036ef0 100644--- a/saleor/static/dashboard-next/products/types/ProductDetails.ts+++ b/saleor/static/dashboard-next/products/types/ProductDetails.ts@@ -178,26 +178,9 @@ export interface ProductDetails_collections {edges: ProductDetails_collections_edges[];}-export interface ProductDetails_categories_edges_node {- __typename: "Category";- id: string;- name: string;-}--export interface ProductDetails_categories_edges {- __typename: "CategoryCountableEdge";- node: ProductDetails_categories_edges_node;-}--export interface ProductDetails_categories {- __typename: "CategoryCountableConnection";- edges: ProductDetails_categories_edges[];-}-export interface ProductDetails {product: ProductDetails_product | null;collections: ProductDetails_collections | null;- categories: ProductDetails_categories | null;}export interface ProductDetailsVariables {diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsxindex 7870c9159a..3d0d6558c4 100644--- a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx+++ b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx@@ -12,8 +12,11 @@ import { WindowTitle } from "../../../components/WindowTitle";import i18n from "../../../i18n";import { decimal, getMutationState, maybe } from "../../../misc";import { productTypeUrl } from "../../../productTypes/urls";-import ProductUpdatePage from "../../components/ProductUpdatePage";+import ProductUpdatePage, {+ FormData+} from "../../components/ProductUpdatePage";import { CategorySearchProvider } from "../../containers/CategorySearch";+import { CollectionSearchProvider } from "../../containers/CollectionSearch";import ProductUpdateOperations from "../../containers/ProductUpdateOperations";import { TypedProductDetailsQuery } from "../../queries";import {@@ -43,213 +46,242 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({search: searchCategories,searchOpts: searchCategoriesOpts}) => (- <TypedProductDetailsQuery displayLoader variables={{ id }}>- {({ data, loading, error }) => {- if (error) {- return (- <ErrorMessageCard message="Something went wrong" />- );- }+ <CollectionSearchProvider>+ {({+ search: searchCollections,+ searchOpts: searchCollectionsOpts+ }) => (+ <TypedProductDetailsQuery+ displayLoader+ variables={{ id }}+ >+ {({ data, loading, error }) => {+ if (error) {+ return (+ <ErrorMessageCard message="Something went wrong" />+ );+ }- const handleDelete = () => {- pushMessage({ text: i18n.t("Product removed") });- navigate(productListUrl());- };- const handleUpdate = () =>- pushMessage({ text: i18n.t("Saved changes") });- const handleImageCreate = () =>- pushMessage({- text: i18n.t("Image successfully uploaded")- });- const handleImageDeleteSuccess = () =>- pushMessage({- text: i18n.t("Image successfully deleted")- });- const handleVariantAdd = () =>- navigate(productVariantAddUrl(id));+ const handleDelete = () => {+ pushMessage({ text: i18n.t("Product removed") });+ navigate(productListUrl());+ };+ const handleUpdate = () =>+ pushMessage({ text: i18n.t("Saved changes") });+ const handleImageCreate = () =>+ pushMessage({+ text: i18n.t("Image successfully uploaded")+ });+ const handleImageDeleteSuccess = () =>+ pushMessage({+ text: i18n.t("Image successfully deleted")+ });+ const handleVariantAdd = () =>+ navigate(productVariantAddUrl(id));- const product = data ? data.product : undefined;- const allCollections =- data && data.collections- ? data.collections.edges.map(edge => edge.node)- : [];- return (- <ProductUpdateOperations- product={product}- onDelete={handleDelete}- onImageCreate={handleImageCreate}- onImageDelete={handleImageDeleteSuccess}- onUpdate={handleUpdate}- >- {({- createProductImage,- deleteProduct,- deleteProductImage,- reorderProductImages,- updateProduct- }) => {- const handleImageDelete = (id: string) => () =>- deleteProductImage.mutate({ id });- const handleImageEdit = (imageId: string) => () =>- navigate(productImageUrl(id, imageId));- const handleSubmit = data => {- if (product) {- updateProduct.mutate({- attributes: data.attributes,- availableOn:- data.availableOn !== ""- ? data.availableOn- : null,- category: data.category,- chargeTaxes: data.chargeTaxes,- collections: data.collections,- description: data.description,- id: product.id,- isPublished: data.available,- name: data.name,- price: decimal(data.price)- });- }- };+ const product = data ? data.product : undefined;+ return (+ <ProductUpdateOperations+ product={product}+ onDelete={handleDelete}+ onImageCreate={handleImageCreate}+ onImageDelete={handleImageDeleteSuccess}+ onUpdate={handleUpdate}+ >+ {({+ createProductImage,+ deleteProduct,+ deleteProductImage,+ reorderProductImages,+ updateProduct+ }) => {+ const handleImageDelete = (id: string) => () =>+ deleteProductImage.mutate({ id });+ const handleImageEdit = (+ imageId: string+ ) => () =>+ navigate(productImageUrl(id, imageId));+ const handleSubmit = (data: FormData) => {+ if (product) {+ updateProduct.mutate({+ attributes: data.attributes,+ availableOn:+ data.availableOn !== ""+ ? data.availableOn+ : null,+ category: data.category.value,+ chargeTaxes: data.chargeTaxes,+ collections: data.collections.map(+ collection => collection.value+ ),+ description: data.description,+ id: product.id,+ isPublished: data.available,+ name: data.name,+ price: decimal(data.price)+ });+ }+ };- const disableFormSave =- createProductImage.opts.loading ||- deleteProduct.opts.loading ||- reorderProductImages.opts.loading ||- updateProduct.opts.loading ||- loading;- const formTransitionState = getMutationState(- updateProduct.opts.called,- updateProduct.opts.loading,- maybe(- () =>- updateProduct.opts.data.productUpdate.errors- )- );- const deleteTransitionState = getMutationState(- deleteProduct.opts.called,- deleteProduct.opts.loading,- maybe(- () =>- deleteProduct.opts.data.productDelete.errors- )- );- return (- <>- <WindowTitle- title={maybe(() => data.product.name)}- />- <ProductUpdatePage- categories={maybe(- () =>- searchCategoriesOpts.data.categories- .edges,- []- ).map(edge => edge.node)}- collections={allCollections}- disabled={disableFormSave}- errors={maybe(+ const disableFormSave =+ createProductImage.opts.loading ||+ deleteProduct.opts.loading ||+ reorderProductImages.opts.loading ||+ updateProduct.opts.loading ||+ loading;+ const formTransitionState = getMutationState(+ updateProduct.opts.called,+ updateProduct.opts.loading,+ maybe(() =>updateProduct.opts.data.productUpdate- .errors,- []- )}- fetchCategories={searchCategories}- saveButtonBarState={formTransitionState}- images={maybe(() => data.product.images)}- header={maybe(() => product.name)}- placeholderImage={placeholderImg}- product={product}- productCollections={maybe(- () => product.collections- )}- variants={maybe(() => product.variants)}- onAttributesEdit={() =>- navigate(- productTypeUrl(- data.product.productType.id- )- )- }- onBack={() => {- navigate(productListUrl());- }}- onDelete={() =>- navigate(productRemoveUrl(id))- }- onProductShow={() => {- if (product) {- window.open(product.url);- }- }}- onImageReorder={({ newIndex, oldIndex }) => {- if (product) {- let ids = product.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(- product.id,- variantId- )- )}- onImageUpload={event => {- if (product) {- createProductImage.mutate({- alt: "",- image: event.target.files[0],- product: product.id- });- }- }}- onImageEdit={handleImageEdit}- onImageDelete={handleImageDelete}- />- <Route- path={productRemovePath(":id")}- render={({ match }) => (- <ActionDialog- open={!!match}- onClose={() => navigate(productUrl(id))}- confirmButtonState={deleteTransitionState}- onConfirm={() =>- deleteProduct.mutate({ id })+ .errors+ )+ );+ const deleteTransitionState = getMutationState(+ deleteProduct.opts.called,+ deleteProduct.opts.loading,+ maybe(+ () =>+ deleteProduct.opts.data.productDelete+ .errors+ )+ );+ return (+ <>+ <WindowTitle+ title={maybe(() => data.product.name)}+ />+ <ProductUpdatePage+ categories={maybe(+ () =>+ searchCategoriesOpts.data.categories+ .edges,+ []+ ).map(edge => edge.node)}+ collections={maybe(+ () =>+ searchCollectionsOpts.data.collections+ .edges,+ []+ ).map(edge => edge.node)}+ disabled={disableFormSave}+ errors={maybe(+ () =>+ updateProduct.opts.data.productUpdate+ .errors,+ []+ )}+ fetchCategories={searchCategories}+ fetchCollections={searchCollections}+ saveButtonBarState={formTransitionState}+ images={maybe(() => data.product.images)}+ header={maybe(() => product.name)}+ placeholderImage={placeholderImg}+ product={product}+ productCollections={maybe(+ () => product.collections+ )}+ variants={maybe(() => product.variants)}+ onAttributesEdit={() =>+ navigate(+ productTypeUrl(+ data.product.productType.id+ )+ )+ }+ onBack={() => {+ navigate(productListUrl());+ }}+ onDelete={() =>+ navigate(productRemoveUrl(id))}- variant="delete"- title={i18n.t("Remove product")}- >- <DialogContentText- dangerouslySetInnerHTML={{- __html: i18n.t(- "Are you sure you want to remove <strong>{{ name }}</strong>?",- {- name: product- ? product.name- : undefined- }+ onProductShow={() => {+ if (product) {+ window.open(product.url);+ }+ }}+ onImageReorder={({+ newIndex,+ oldIndex+ }) => {+ if (product) {+ let ids = product.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(+ product.id,+ variantId)- }}- />- </ActionDialog>- )}- />- </>- );- }}- </ProductUpdateOperations>- );- }}- </TypedProductDetailsQuery>+ )}+ onImageUpload={event => {+ if (product) {+ createProductImage.mutate({+ alt: "",+ image: event.target.files[0],+ product: product.id+ });+ }+ }}+ onImageEdit={handleImageEdit}+ onImageDelete={handleImageDelete}+ />+ <Route+ path={productRemovePath(":id")}+ render={({ match }) => (+ <ActionDialog+ open={!!match}+ onClose={() =>+ navigate(productUrl(id))+ }+ confirmButtonState={+ deleteTransitionState+ }+ onConfirm={() =>+ deleteProduct.mutate({ id })+ }+ variant="delete"+ title={i18n.t("Remove product")}+ >+ <DialogContentText+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "Are you sure you want to remove <strong>{{ name }}</strong>?",+ {+ name: product+ ? product.name+ : undefined+ }+ )+ }}+ />+ </ActionDialog>+ )}+ />+ </>+ );+ }}+ </ProductUpdateOperations>+ );+ }}+ </TypedProductDetailsQuery>+ )}+ </CollectionSearchProvider>)}</CategorySearchProvider>);