SALEOR-3513 - Fix attribute values input display (#1156)
* Fix attribute values input display with additional search handler * Update changelog * Update attribute value search handler
This commit is contained in:
parent
4f39e75f2d
commit
99aa6365be
28 changed files with 180 additions and 220 deletions
|
@ -48,6 +48,7 @@ All notable, unreleased changes to this project will be documented in this file.
|
||||||
- Choosing user shipping and billing addresses for draft order - #1082 by @orzechdev
|
- Choosing user shipping and billing addresses for draft order - #1082 by @orzechdev
|
||||||
- Fix EditorJS inline formatting - #1096 by @orzechdev
|
- Fix EditorJS inline formatting - #1096 by @orzechdev
|
||||||
- Add pagination on attribute values - #1112 by @orzechdev
|
- Add pagination on attribute values - #1112 by @orzechdev
|
||||||
|
- Fix attribute values input display - #1156 by @orzechdev
|
||||||
|
|
||||||
# 2.11.1
|
# 2.11.1
|
||||||
|
|
||||||
|
|
|
@ -55,9 +55,8 @@ export interface AttributeRowHandlers {
|
||||||
onReferencesAddClick: (attribute: AttributeInput) => void;
|
onReferencesAddClick: (attribute: AttributeInput) => void;
|
||||||
onReferencesRemove: FormsetChange<string[]>;
|
onReferencesRemove: FormsetChange<string[]>;
|
||||||
onReferencesReorder: FormsetChange<ReorderEvent>;
|
onReferencesReorder: FormsetChange<ReorderEvent>;
|
||||||
fetchAttributeValues: (query: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
fetchMoreAttributeValues: FetchMoreProps;
|
fetchMoreAttributeValues: FetchMoreProps;
|
||||||
onAttributeFocus: (id: string) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AttributeRowProps extends AttributeRowHandlers {
|
interface AttributeRowProps extends AttributeRowHandlers {
|
||||||
|
@ -81,8 +80,7 @@ const AttributeRow: React.FC<AttributeRowProps> = ({
|
||||||
onReferencesReorder,
|
onReferencesReorder,
|
||||||
onChange,
|
onChange,
|
||||||
fetchAttributeValues,
|
fetchAttributeValues,
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues
|
||||||
onAttributeFocus
|
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const classes = useStyles({});
|
const classes = useStyles({});
|
||||||
|
@ -147,9 +145,9 @@ const AttributeRow: React.FC<AttributeRowProps> = ({
|
||||||
value={attribute.value[0]}
|
value={attribute.value[0]}
|
||||||
onChange={event => onChange(attribute.id, event.target.value)}
|
onChange={event => onChange(attribute.id, event.target.value)}
|
||||||
allowCustomValues={true}
|
allowCustomValues={true}
|
||||||
fetchChoices={fetchAttributeValues}
|
fetchOnFocus={true}
|
||||||
|
fetchChoices={value => fetchAttributeValues(value, attribute.id)}
|
||||||
{...fetchMoreAttributeValues}
|
{...fetchMoreAttributeValues}
|
||||||
onFocus={() => onAttributeFocus(attribute.id)}
|
|
||||||
/>
|
/>
|
||||||
</BasicAttributeRow>
|
</BasicAttributeRow>
|
||||||
);
|
);
|
||||||
|
@ -209,9 +207,9 @@ const AttributeRow: React.FC<AttributeRowProps> = ({
|
||||||
value={attribute.value}
|
value={attribute.value}
|
||||||
onChange={event => onMultiChange(attribute.id, event.target.value)}
|
onChange={event => onMultiChange(attribute.id, event.target.value)}
|
||||||
allowCustomValues={true}
|
allowCustomValues={true}
|
||||||
fetchChoices={fetchAttributeValues}
|
fetchOnFocus={true}
|
||||||
|
fetchChoices={value => fetchAttributeValues(value, attribute.id)}
|
||||||
{...fetchMoreAttributeValues}
|
{...fetchMoreAttributeValues}
|
||||||
onFocus={() => onAttributeFocus(attribute.id)}
|
|
||||||
/>
|
/>
|
||||||
</BasicAttributeRow>
|
</BasicAttributeRow>
|
||||||
);
|
);
|
||||||
|
|
|
@ -18,7 +18,6 @@ const props: AttributesProps = {
|
||||||
onReferencesAddClick: () => undefined,
|
onReferencesAddClick: () => undefined,
|
||||||
onReferencesRemove: () => undefined,
|
onReferencesRemove: () => undefined,
|
||||||
onReferencesReorder: () => undefined,
|
onReferencesReorder: () => undefined,
|
||||||
onAttributeFocus: () => undefined,
|
|
||||||
fetchAttributeValues: () => undefined,
|
fetchAttributeValues: () => undefined,
|
||||||
fetchMoreAttributeValues: fetchMoreProps
|
fetchMoreAttributeValues: fetchMoreProps
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,7 +36,7 @@ export type AttributeFileInput = FormsetAtomicData<AttributeInputData, File[]>;
|
||||||
export interface AttributesProps extends AttributeRowHandlers {
|
export interface AttributesProps extends AttributeRowHandlers {
|
||||||
attributes: AttributeInput[];
|
attributes: AttributeInput[];
|
||||||
attributeValues: AttributeValueFragment[];
|
attributeValues: AttributeValueFragment[];
|
||||||
fetchAttributeValues: (query: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
fetchMoreAttributeValues: FetchMoreProps;
|
fetchMoreAttributeValues: FetchMoreProps;
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
@ -44,7 +44,6 @@ export interface AttributesProps extends AttributeRowHandlers {
|
||||||
ProductErrorWithAttributesFragment | PageErrorWithAttributesFragment
|
ProductErrorWithAttributesFragment | PageErrorWithAttributesFragment
|
||||||
>;
|
>;
|
||||||
title?: React.ReactNode;
|
title?: React.ReactNode;
|
||||||
onAttributeFocus: (id: string) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
const useStyles = makeStyles(
|
||||||
|
|
|
@ -85,7 +85,7 @@ export interface MultiAutocompleteSelectFieldProps
|
||||||
testId?: string;
|
testId?: string;
|
||||||
fetchChoices?: (value: string) => void;
|
fetchChoices?: (value: string) => void;
|
||||||
onChange: (event: React.ChangeEvent<any>) => void;
|
onChange: (event: React.ChangeEvent<any>) => void;
|
||||||
onFocus?: () => void;
|
fetchOnFocus?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DebounceAutocomplete: React.ComponentType<DebounceProps<
|
const DebounceAutocomplete: React.ComponentType<DebounceProps<
|
||||||
|
@ -110,8 +110,8 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
testId,
|
testId,
|
||||||
fetchChoices,
|
fetchChoices,
|
||||||
onChange,
|
onChange,
|
||||||
onFocus,
|
|
||||||
onFetchMore,
|
onFetchMore,
|
||||||
|
fetchOnFocus,
|
||||||
...rest
|
...rest
|
||||||
} = props;
|
} = props;
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
|
@ -130,8 +130,10 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<DebounceAutocomplete debounceFn={fetchChoices}>
|
||||||
|
{debounceFn => (
|
||||||
<Downshift
|
<Downshift
|
||||||
onInputValueChange={fetchChoices}
|
onInputValueChange={value => debounceFn(value)}
|
||||||
onSelect={handleSelect}
|
onSelect={handleSelect}
|
||||||
itemToString={() => ""}
|
itemToString={() => ""}
|
||||||
>
|
>
|
||||||
|
@ -149,7 +151,8 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
inputValue.length > 0 &&
|
inputValue.length > 0 &&
|
||||||
allowCustomValues &&
|
allowCustomValues &&
|
||||||
!choices.find(
|
!choices.find(
|
||||||
choice => choice.label.toLowerCase() === inputValue.toLowerCase()
|
choice =>
|
||||||
|
choice.label.toLowerCase() === inputValue.toLowerCase()
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -167,8 +170,8 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
id: undefined,
|
id: undefined,
|
||||||
onClick: toggleMenu,
|
onClick: toggleMenu,
|
||||||
onFocus: () => {
|
onFocus: () => {
|
||||||
if (onFocus) {
|
if (fetchOnFocus) {
|
||||||
onFocus();
|
fetchChoices(inputValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@ -206,6 +209,8 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
</Downshift>
|
</Downshift>
|
||||||
|
)}
|
||||||
|
</DebounceAutocomplete>
|
||||||
<div className={classes.chipContainer}>
|
<div className={classes.chipContainer}>
|
||||||
{displayValues.map(value => (
|
{displayValues.map(value => (
|
||||||
<div className={classes.chip} key={value.value}>
|
<div className={classes.chip} key={value.value}>
|
||||||
|
|
|
@ -46,7 +46,7 @@ export interface SingleAutocompleteSelectFieldProps
|
||||||
InputProps?: InputProps;
|
InputProps?: InputProps;
|
||||||
fetchChoices?: (value: string) => void;
|
fetchChoices?: (value: string) => void;
|
||||||
onChange: (event: React.ChangeEvent<any>) => void;
|
onChange: (event: React.ChangeEvent<any>) => void;
|
||||||
onFocus?: () => void;
|
fetchOnFocus?: boolean;
|
||||||
FormHelperTextProps?: ExtendedFormHelperTextProps;
|
FormHelperTextProps?: ExtendedFormHelperTextProps;
|
||||||
nakedInput?: boolean;
|
nakedInput?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
|
||||||
fetchChoices,
|
fetchChoices,
|
||||||
onChange,
|
onChange,
|
||||||
onFetchMore,
|
onFetchMore,
|
||||||
onFocus,
|
fetchOnFocus,
|
||||||
FormHelperTextProps,
|
FormHelperTextProps,
|
||||||
nakedInput = false,
|
nakedInput = false,
|
||||||
...rest
|
...rest
|
||||||
|
@ -170,8 +170,8 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
|
||||||
onBlur: handleBlur,
|
onBlur: handleBlur,
|
||||||
onClick: toggleMenu,
|
onClick: toggleMenu,
|
||||||
onFocus: () => {
|
onFocus: () => {
|
||||||
if (onFocus) {
|
if (fetchOnFocus) {
|
||||||
onFocus();
|
fetchChoices(inputValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,11 +55,10 @@ export interface PageDetailsPageProps {
|
||||||
fetchMoreReferencePages?: FetchMoreProps;
|
fetchMoreReferencePages?: FetchMoreProps;
|
||||||
fetchReferenceProducts?: (data: string) => void;
|
fetchReferenceProducts?: (data: string) => void;
|
||||||
fetchMoreReferenceProducts?: FetchMoreProps;
|
fetchMoreReferenceProducts?: FetchMoreProps;
|
||||||
fetchAttributeValues: (query: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
fetchMoreAttributeValues?: FetchMoreProps;
|
fetchMoreAttributeValues?: FetchMoreProps;
|
||||||
onCloseDialog: () => void;
|
onCloseDialog: () => void;
|
||||||
onSelectPageType?: (pageTypeId: string) => void;
|
onSelectPageType?: (pageTypeId: string) => void;
|
||||||
onAttributeFocus: (id: string) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
||||||
|
@ -86,8 +85,7 @@ const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
||||||
fetchAttributeValues,
|
fetchAttributeValues,
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
onCloseDialog,
|
onCloseDialog,
|
||||||
onSelectPageType,
|
onSelectPageType
|
||||||
onAttributeFocus
|
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const localizeDate = useDateLocalize();
|
const localizeDate = useDateLocalize();
|
||||||
|
@ -191,7 +189,6 @@ const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onAttributeFocus={onAttributeFocus}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
|
|
|
@ -12,10 +12,10 @@ import {
|
||||||
import { useFileUploadMutation } from "@saleor/files/mutations";
|
import { useFileUploadMutation } from "@saleor/files/mutations";
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useNotifier from "@saleor/hooks/useNotifier";
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import useAttributeValueSearch from "@saleor/searches/useAttributeValueSearch";
|
|
||||||
import usePageSearch from "@saleor/searches/usePageSearch";
|
import usePageSearch from "@saleor/searches/usePageSearch";
|
||||||
import usePageTypeSearch from "@saleor/searches/usePageTypeSearch";
|
import usePageTypeSearch from "@saleor/searches/usePageTypeSearch";
|
||||||
import useProductSearch from "@saleor/searches/useProductSearch";
|
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||||
|
import createAttributeValueSearchHandler from "@saleor/utils/handlers/attributeValueSearchHandler";
|
||||||
import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler";
|
import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler";
|
||||||
import { mapEdgesToItems } from "@saleor/utils/maps";
|
import { mapEdgesToItems } from "@saleor/utils/maps";
|
||||||
import {
|
import {
|
||||||
|
@ -23,7 +23,7 @@ import {
|
||||||
usePrivateMetadataUpdate
|
usePrivateMetadataUpdate
|
||||||
} from "@saleor/utils/metadata/updateMetadata";
|
} from "@saleor/utils/metadata/updateMetadata";
|
||||||
import { getParsedDataForJsonStringField } from "@saleor/utils/richText/misc";
|
import { getParsedDataForJsonStringField } from "@saleor/utils/richText/misc";
|
||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import PageDetailsPage from "../components/PageDetailsPage";
|
import PageDetailsPage from "../components/PageDetailsPage";
|
||||||
|
@ -73,18 +73,11 @@ export const PageCreate: React.FC<PageCreateProps> = ({ params }) => {
|
||||||
} = useProductSearch({
|
} = useProductSearch({
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
});
|
});
|
||||||
const [focusedAttribute, setFocusedAttribute] = useState<string>();
|
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts
|
||||||
} = useAttributeValueSearch({
|
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
variables: {
|
|
||||||
id: focusedAttribute,
|
|
||||||
...DEFAULT_INITIAL_SEARCH_DATA
|
|
||||||
},
|
|
||||||
skip: !focusedAttribute
|
|
||||||
});
|
|
||||||
|
|
||||||
const { data: selectedPageType } = usePageTypeQuery({
|
const { data: selectedPageType } = usePageTypeQuery({
|
||||||
variables: {
|
variables: {
|
||||||
|
@ -222,7 +215,6 @@ export const PageCreate: React.FC<PageCreateProps> = ({ params }) => {
|
||||||
onCloseDialog={() => navigate(pageCreateUrl())}
|
onCloseDialog={() => navigate(pageCreateUrl())}
|
||||||
selectedPageType={selectedPageType?.pageType}
|
selectedPageType={selectedPageType?.pageType}
|
||||||
onSelectPageType={id => setSelectedPageTypeId(id)}
|
onSelectPageType={id => setSelectedPageTypeId(id)}
|
||||||
onAttributeFocus={setFocusedAttribute}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -24,9 +24,9 @@ import { UploadErrorFragment } from "@saleor/fragments/types/UploadErrorFragment
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useNotifier from "@saleor/hooks/useNotifier";
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import { commonMessages } from "@saleor/intl";
|
import { commonMessages } from "@saleor/intl";
|
||||||
import useAttributeValueSearch from "@saleor/searches/useAttributeValueSearch";
|
|
||||||
import usePageSearch from "@saleor/searches/usePageSearch";
|
import usePageSearch from "@saleor/searches/usePageSearch";
|
||||||
import useProductSearch from "@saleor/searches/useProductSearch";
|
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||||
|
import createAttributeValueSearchHandler from "@saleor/utils/handlers/attributeValueSearchHandler";
|
||||||
import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler";
|
import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler";
|
||||||
import { mapEdgesToItems } from "@saleor/utils/maps";
|
import { mapEdgesToItems } from "@saleor/utils/maps";
|
||||||
import {
|
import {
|
||||||
|
@ -34,7 +34,7 @@ import {
|
||||||
usePrivateMetadataUpdate
|
usePrivateMetadataUpdate
|
||||||
} from "@saleor/utils/metadata/updateMetadata";
|
} from "@saleor/utils/metadata/updateMetadata";
|
||||||
import { getParsedDataForJsonStringField } from "@saleor/utils/richText/misc";
|
import { getParsedDataForJsonStringField } from "@saleor/utils/richText/misc";
|
||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
import { getStringOrPlaceholder, maybe } from "../../misc";
|
import { getStringOrPlaceholder, maybe } from "../../misc";
|
||||||
|
@ -173,18 +173,11 @@ export const PageDetails: React.FC<PageDetailsProps> = ({ id, params }) => {
|
||||||
} = useProductSearch({
|
} = useProductSearch({
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
});
|
});
|
||||||
const [focusedAttribute, setFocusedAttribute] = useState<string>();
|
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts
|
||||||
} = useAttributeValueSearch({
|
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
variables: {
|
|
||||||
id: focusedAttribute,
|
|
||||||
...DEFAULT_INITIAL_SEARCH_DATA
|
|
||||||
},
|
|
||||||
skip: !focusedAttribute
|
|
||||||
});
|
|
||||||
|
|
||||||
const attributeValues = mapEdgesToItems(
|
const attributeValues = mapEdgesToItems(
|
||||||
searchAttributeValuesOpts?.data?.attribute.choices
|
searchAttributeValuesOpts?.data?.attribute.choices
|
||||||
|
@ -243,7 +236,6 @@ export const PageDetails: React.FC<PageDetailsProps> = ({ id, params }) => {
|
||||||
fetchAttributeValues={searchAttributeValues}
|
fetchAttributeValues={searchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onCloseDialog={() => navigate(pageUrl(id))}
|
onCloseDialog={() => navigate(pageUrl(id))}
|
||||||
onAttributeFocus={setFocusedAttribute}
|
|
||||||
/>
|
/>
|
||||||
<ActionDialog
|
<ActionDialog
|
||||||
open={params.action === "remove"}
|
open={params.action === "remove"}
|
||||||
|
|
|
@ -74,8 +74,7 @@ interface ProductCreatePageProps {
|
||||||
fetchCategories: (data: string) => void;
|
fetchCategories: (data: string) => void;
|
||||||
fetchCollections: (data: string) => void;
|
fetchCollections: (data: string) => void;
|
||||||
fetchProductTypes: (data: string) => void;
|
fetchProductTypes: (data: string) => void;
|
||||||
fetchAttributeValues: (query: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
onAttributeFocus: (id: string) => void;
|
|
||||||
onWarehouseConfigure: () => void;
|
onWarehouseConfigure: () => void;
|
||||||
openChannelsModal: () => void;
|
openChannelsModal: () => void;
|
||||||
onChannelsChange: (data: ChannelData[]) => void;
|
onChannelsChange: (data: ChannelData[]) => void;
|
||||||
|
@ -130,8 +129,7 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
fetchAttributeValues,
|
fetchAttributeValues,
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
onCloseDialog,
|
onCloseDialog,
|
||||||
onSelectProductType,
|
onSelectProductType
|
||||||
onAttributeFocus
|
|
||||||
}: ProductCreatePageProps) => {
|
}: ProductCreatePageProps) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
@ -242,7 +240,6 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onAttributeFocus={onAttributeFocus}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
|
|
|
@ -60,7 +60,6 @@ const props: ProductUpdatePageProps = {
|
||||||
onVariantsAdd: () => undefined,
|
onVariantsAdd: () => undefined,
|
||||||
onWarehouseConfigure: () => undefined,
|
onWarehouseConfigure: () => undefined,
|
||||||
openChannelsModal: () => undefined,
|
openChannelsModal: () => undefined,
|
||||||
onAttributeFocus: () => undefined,
|
|
||||||
placeholderImage,
|
placeholderImage,
|
||||||
product,
|
product,
|
||||||
referencePages: [],
|
referencePages: [],
|
||||||
|
|
|
@ -101,8 +101,7 @@ export interface ProductUpdatePageProps extends ListActions, ChannelProps {
|
||||||
fetchCollections: (query: string) => void;
|
fetchCollections: (query: string) => void;
|
||||||
fetchReferencePages?: (data: string) => void;
|
fetchReferencePages?: (data: string) => void;
|
||||||
fetchReferenceProducts?: (data: string) => void;
|
fetchReferenceProducts?: (data: string) => void;
|
||||||
fetchAttributeValues: (query: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
onAttributeFocus: (id: string) => void;
|
|
||||||
onAssignReferencesClick: (attribute: AttributeInput) => void;
|
onAssignReferencesClick: (attribute: AttributeInput) => void;
|
||||||
onCloseDialog: () => void;
|
onCloseDialog: () => void;
|
||||||
onVariantsAdd: () => void;
|
onVariantsAdd: () => void;
|
||||||
|
@ -195,8 +194,7 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
onCloseDialog,
|
onCloseDialog,
|
||||||
channelsWithVariantsData,
|
channelsWithVariantsData,
|
||||||
onChannelsChange,
|
onChannelsChange
|
||||||
onAttributeFocus
|
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
@ -319,7 +317,6 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onAttributeFocus={onAttributeFocus}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
|
|
|
@ -78,10 +78,9 @@ interface ProductVariantCreatePageProps {
|
||||||
onWarehouseConfigure: () => void;
|
onWarehouseConfigure: () => void;
|
||||||
assignReferencesAttributeId?: string;
|
assignReferencesAttributeId?: string;
|
||||||
onAssignReferencesClick: (attribute: AttributeInput) => void;
|
onAssignReferencesClick: (attribute: AttributeInput) => void;
|
||||||
onAttributeFocus: (id: string) => void;
|
|
||||||
fetchReferencePages?: (data: string) => void;
|
fetchReferencePages?: (data: string) => void;
|
||||||
fetchReferenceProducts?: (data: string) => void;
|
fetchReferenceProducts?: (data: string) => void;
|
||||||
fetchAttributeValues: (query: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
fetchMoreReferencePages?: FetchMoreProps;
|
fetchMoreReferencePages?: FetchMoreProps;
|
||||||
fetchMoreReferenceProducts?: FetchMoreProps;
|
fetchMoreReferenceProducts?: FetchMoreProps;
|
||||||
fetchMoreAttributeValues?: FetchMoreProps;
|
fetchMoreAttributeValues?: FetchMoreProps;
|
||||||
|
@ -105,7 +104,6 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
onVariantClick,
|
onVariantClick,
|
||||||
onVariantReorder,
|
onVariantReorder,
|
||||||
onWarehouseConfigure,
|
onWarehouseConfigure,
|
||||||
onAttributeFocus,
|
|
||||||
assignReferencesAttributeId,
|
assignReferencesAttributeId,
|
||||||
onAssignReferencesClick,
|
onAssignReferencesClick,
|
||||||
fetchReferencePages,
|
fetchReferencePages,
|
||||||
|
@ -194,7 +192,6 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onAttributeFocus={onAttributeFocus}
|
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<Attributes
|
<Attributes
|
||||||
|
@ -216,7 +213,6 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onAttributeFocus={onAttributeFocus}
|
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<ProductShipping
|
<ProductShipping
|
||||||
|
|
|
@ -109,8 +109,7 @@ const props: ProductVariantCreatorContentProps = {
|
||||||
errors: [],
|
errors: [],
|
||||||
variantsLeft: 6,
|
variantsLeft: 6,
|
||||||
step: ProductVariantCreatorStep.values,
|
step: ProductVariantCreatorStep.values,
|
||||||
warehouses: warehouseList,
|
warehouses: warehouseList
|
||||||
onAttributeFocus: () => undefined
|
|
||||||
};
|
};
|
||||||
|
|
||||||
storiesOf("Views / Products / Create multiple variants", module)
|
storiesOf("Views / Products / Create multiple variants", module)
|
||||||
|
|
|
@ -27,9 +27,8 @@ export interface ProductVariantCreatorContentProps {
|
||||||
step: ProductVariantCreatorStep;
|
step: ProductVariantCreatorStep;
|
||||||
variantsLeft: number | null;
|
variantsLeft: number | null;
|
||||||
warehouses: WarehouseFragment[];
|
warehouses: WarehouseFragment[];
|
||||||
fetchAttributeValues: (query: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
fetchMoreAttributeValues?: FetchMoreProps;
|
fetchMoreAttributeValues?: FetchMoreProps;
|
||||||
onAttributeFocus: (id: string) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps> = ({
|
const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps> = ({
|
||||||
|
@ -43,8 +42,7 @@ const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps>
|
||||||
errors,
|
errors,
|
||||||
step,
|
step,
|
||||||
variantsLeft,
|
variantsLeft,
|
||||||
warehouses,
|
warehouses
|
||||||
onAttributeFocus
|
|
||||||
}) => {
|
}) => {
|
||||||
const selectedAttributes = attributes.filter(attribute =>
|
const selectedAttributes = attributes.filter(attribute =>
|
||||||
isSelected(
|
isSelected(
|
||||||
|
@ -73,7 +71,6 @@ const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps>
|
||||||
type: ProductVariantCreateReducerActionType.selectValue
|
type: ProductVariantCreateReducerActionType.selectValue
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
onAttributeFocus={onAttributeFocus}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{step === ProductVariantCreatorStep.prices && (
|
{step === ProductVariantCreatorStep.prices && (
|
||||||
|
|
|
@ -55,7 +55,7 @@ export function getMultiDisplayValues(
|
||||||
export interface ProductVariantCreatorValuesProps {
|
export interface ProductVariantCreatorValuesProps {
|
||||||
attributes: ProductDetails_product_productType_variantAttributes[];
|
attributes: ProductDetails_product_productType_variantAttributes[];
|
||||||
attributeValues: SearchAttributeValues_attribute_choices_edges_node[];
|
attributeValues: SearchAttributeValues_attribute_choices_edges_node[];
|
||||||
fetchAttributeValues: (query: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
fetchMoreAttributeValues?: FetchMoreProps;
|
fetchMoreAttributeValues?: FetchMoreProps;
|
||||||
data: ProductVariantCreateFormData;
|
data: ProductVariantCreateFormData;
|
||||||
variantsLeft: number | null;
|
variantsLeft: number | null;
|
||||||
|
@ -63,7 +63,6 @@ export interface ProductVariantCreatorValuesProps {
|
||||||
attributeId: string,
|
attributeId: string,
|
||||||
value: AttributeValue<AttributeValueFragment>
|
value: AttributeValue<AttributeValueFragment>
|
||||||
) => void;
|
) => void;
|
||||||
onAttributeFocus: (id: string) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductVariantCreatorValues: React.FC<ProductVariantCreatorValuesProps> = props => {
|
const ProductVariantCreatorValues: React.FC<ProductVariantCreatorValuesProps> = props => {
|
||||||
|
@ -74,8 +73,7 @@ const ProductVariantCreatorValues: React.FC<ProductVariantCreatorValuesProps> =
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
data,
|
data,
|
||||||
variantsLeft,
|
variantsLeft,
|
||||||
onValueClick,
|
onValueClick
|
||||||
onAttributeFocus
|
|
||||||
} = props;
|
} = props;
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const variantsNumber = getVariantsNumber(data);
|
const variantsNumber = getVariantsNumber(data);
|
||||||
|
@ -128,9 +126,10 @@ const ProductVariantCreatorValues: React.FC<ProductVariantCreatorValuesProps> =
|
||||||
handleValueClick(attribute.id, event.target.value)
|
handleValueClick(attribute.id, event.target.value)
|
||||||
}
|
}
|
||||||
allowCustomValues={true}
|
allowCustomValues={true}
|
||||||
fetchChoices={fetchAttributeValues}
|
fetchChoices={value =>
|
||||||
|
fetchAttributeValues(value, attribute.id)
|
||||||
|
}
|
||||||
{...fetchMoreAttributeValues}
|
{...fetchMoreAttributeValues}
|
||||||
onFocus={() => onAttributeFocus(attribute.id)}
|
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
|
@ -94,9 +94,8 @@ interface ProductVariantPageProps {
|
||||||
fetchMoreAttributeValues?: FetchMoreProps;
|
fetchMoreAttributeValues?: FetchMoreProps;
|
||||||
fetchReferencePages?: (data: string) => void;
|
fetchReferencePages?: (data: string) => void;
|
||||||
fetchReferenceProducts?: (data: string) => void;
|
fetchReferenceProducts?: (data: string) => void;
|
||||||
fetchAttributeValues: (query: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
onAssignReferencesClick: (attribute: AttributeInput) => void;
|
onAssignReferencesClick: (attribute: AttributeInput) => void;
|
||||||
onAttributeFocus: (id: string) => void;
|
|
||||||
onCloseDialog: () => void;
|
onCloseDialog: () => void;
|
||||||
onVariantReorder: ReorderAction;
|
onVariantReorder: ReorderAction;
|
||||||
onAdd();
|
onAdd();
|
||||||
|
@ -133,7 +132,6 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
onVariantReorder,
|
onVariantReorder,
|
||||||
onSetDefaultVariant,
|
onSetDefaultVariant,
|
||||||
onWarehouseConfigure,
|
onWarehouseConfigure,
|
||||||
onAttributeFocus,
|
|
||||||
assignReferencesAttributeId,
|
assignReferencesAttributeId,
|
||||||
onAssignReferencesClick,
|
onAssignReferencesClick,
|
||||||
fetchReferencePages,
|
fetchReferencePages,
|
||||||
|
@ -247,7 +245,6 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onAttributeFocus={onAttributeFocus}
|
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<Attributes
|
<Attributes
|
||||||
|
@ -271,7 +268,6 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onAttributeFocus={onAttributeFocus}
|
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<ProductVariantMedia
|
<ProductVariantMedia
|
||||||
|
|
|
@ -28,7 +28,6 @@ import {
|
||||||
productListUrl,
|
productListUrl,
|
||||||
productUrl
|
productUrl
|
||||||
} from "@saleor/products/urls";
|
} from "@saleor/products/urls";
|
||||||
import useAttributeValueSearch from "@saleor/searches/useAttributeValueSearch";
|
|
||||||
import useCategorySearch from "@saleor/searches/useCategorySearch";
|
import useCategorySearch from "@saleor/searches/useCategorySearch";
|
||||||
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
||||||
import usePageSearch from "@saleor/searches/usePageSearch";
|
import usePageSearch from "@saleor/searches/usePageSearch";
|
||||||
|
@ -36,6 +35,7 @@ import useProductSearch from "@saleor/searches/useProductSearch";
|
||||||
import useProductTypeSearch from "@saleor/searches/useProductTypeSearch";
|
import useProductTypeSearch from "@saleor/searches/useProductTypeSearch";
|
||||||
import { useTaxTypeList } from "@saleor/taxes/queries";
|
import { useTaxTypeList } from "@saleor/taxes/queries";
|
||||||
import { getProductErrorMessage } from "@saleor/utils/errors";
|
import { getProductErrorMessage } from "@saleor/utils/errors";
|
||||||
|
import createAttributeValueSearchHandler from "@saleor/utils/handlers/attributeValueSearchHandler";
|
||||||
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler";
|
import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler";
|
||||||
import { mapEdgesToItems } from "@saleor/utils/maps";
|
import { mapEdgesToItems } from "@saleor/utils/maps";
|
||||||
|
@ -45,7 +45,7 @@ import {
|
||||||
} from "@saleor/utils/metadata/updateMetadata";
|
} from "@saleor/utils/metadata/updateMetadata";
|
||||||
import { useWarehouseList } from "@saleor/warehouses/queries";
|
import { useWarehouseList } from "@saleor/warehouses/queries";
|
||||||
import { warehouseAddPath } from "@saleor/warehouses/urls";
|
import { warehouseAddPath } from "@saleor/warehouses/urls";
|
||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import { createHandler } from "./handlers";
|
import { createHandler } from "./handlers";
|
||||||
|
@ -106,18 +106,11 @@ export const ProductCreateView: React.FC<ProductCreateProps> = ({ params }) => {
|
||||||
} = useProductSearch({
|
} = useProductSearch({
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
});
|
});
|
||||||
const [focusedAttribute, setFocusedAttribute] = useState<string>();
|
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts
|
||||||
} = useAttributeValueSearch({
|
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
variables: {
|
|
||||||
id: focusedAttribute,
|
|
||||||
...DEFAULT_INITIAL_SEARCH_DATA
|
|
||||||
},
|
|
||||||
skip: !focusedAttribute
|
|
||||||
});
|
|
||||||
const warehouses = useWarehouseList({
|
const warehouses = useWarehouseList({
|
||||||
displayLoader: true,
|
displayLoader: true,
|
||||||
variables: {
|
variables: {
|
||||||
|
@ -351,7 +344,6 @@ export const ProductCreateView: React.FC<ProductCreateProps> = ({ params }) => {
|
||||||
onCloseDialog={() => navigate(productAddUrl())}
|
onCloseDialog={() => navigate(productAddUrl())}
|
||||||
selectedProductType={selectedProductType?.productType}
|
selectedProductType={selectedProductType?.productType}
|
||||||
onSelectProductType={id => setSelectedProductTypeId(id)}
|
onSelectProductType={id => setSelectedProductTypeId(id)}
|
||||||
onAttributeFocus={setFocusedAttribute}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -41,12 +41,12 @@ import {
|
||||||
useSimpleProductUpdateMutation,
|
useSimpleProductUpdateMutation,
|
||||||
useVariantCreateMutation
|
useVariantCreateMutation
|
||||||
} from "@saleor/products/mutations";
|
} from "@saleor/products/mutations";
|
||||||
import useAttributeValueSearch from "@saleor/searches/useAttributeValueSearch";
|
|
||||||
import useCategorySearch from "@saleor/searches/useCategorySearch";
|
import useCategorySearch from "@saleor/searches/useCategorySearch";
|
||||||
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
||||||
import usePageSearch from "@saleor/searches/usePageSearch";
|
import usePageSearch from "@saleor/searches/usePageSearch";
|
||||||
import useProductSearch from "@saleor/searches/useProductSearch";
|
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||||
import { getProductErrorMessage } from "@saleor/utils/errors";
|
import { getProductErrorMessage } from "@saleor/utils/errors";
|
||||||
|
import createAttributeValueSearchHandler from "@saleor/utils/handlers/attributeValueSearchHandler";
|
||||||
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler";
|
import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler";
|
||||||
import { mapEdgesToItems } from "@saleor/utils/maps";
|
import { mapEdgesToItems } from "@saleor/utils/maps";
|
||||||
|
@ -56,7 +56,7 @@ import {
|
||||||
} from "@saleor/utils/metadata/updateMetadata";
|
} from "@saleor/utils/metadata/updateMetadata";
|
||||||
import { useWarehouseList } from "@saleor/warehouses/queries";
|
import { useWarehouseList } from "@saleor/warehouses/queries";
|
||||||
import { warehouseAddPath } from "@saleor/warehouses/urls";
|
import { warehouseAddPath } from "@saleor/warehouses/urls";
|
||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import { defineMessages, FormattedMessage, useIntl } from "react-intl";
|
import { defineMessages, FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
import { getMutationState } from "../../../misc";
|
import { getMutationState } from "../../../misc";
|
||||||
|
@ -144,18 +144,11 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
} = useProductSearch({
|
} = useProductSearch({
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
});
|
});
|
||||||
const [focusedAttribute, setFocusedAttribute] = useState<string>();
|
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts
|
||||||
} = useAttributeValueSearch({
|
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
variables: {
|
|
||||||
id: focusedAttribute,
|
|
||||||
...DEFAULT_INITIAL_SEARCH_DATA
|
|
||||||
},
|
|
||||||
skip: !focusedAttribute
|
|
||||||
});
|
|
||||||
const warehouses = useWarehouseList({
|
const warehouses = useWarehouseList({
|
||||||
displayLoader: true,
|
displayLoader: true,
|
||||||
variables: {
|
variables: {
|
||||||
|
@ -608,7 +601,6 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
fetchMoreReferenceProducts={fetchMoreReferenceProducts}
|
fetchMoreReferenceProducts={fetchMoreReferenceProducts}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onCloseDialog={() => navigate(productUrl(id))}
|
onCloseDialog={() => navigate(productUrl(id))}
|
||||||
onAttributeFocus={setFocusedAttribute}
|
|
||||||
/>
|
/>
|
||||||
<ActionDialog
|
<ActionDialog
|
||||||
open={params.action === "remove"}
|
open={params.action === "remove"}
|
||||||
|
|
|
@ -23,9 +23,9 @@ import useShop from "@saleor/hooks/useShop";
|
||||||
import { commonMessages } from "@saleor/intl";
|
import { commonMessages } from "@saleor/intl";
|
||||||
import { useProductVariantChannelListingUpdate } from "@saleor/products/mutations";
|
import { useProductVariantChannelListingUpdate } from "@saleor/products/mutations";
|
||||||
import { ProductVariantDetails_productVariant } from "@saleor/products/types/ProductVariantDetails";
|
import { ProductVariantDetails_productVariant } from "@saleor/products/types/ProductVariantDetails";
|
||||||
import useAttributeValueSearch from "@saleor/searches/useAttributeValueSearch";
|
|
||||||
import usePageSearch from "@saleor/searches/usePageSearch";
|
import usePageSearch from "@saleor/searches/usePageSearch";
|
||||||
import useProductSearch from "@saleor/searches/useProductSearch";
|
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||||
|
import createAttributeValueSearchHandler from "@saleor/utils/handlers/attributeValueSearchHandler";
|
||||||
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler";
|
import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler";
|
||||||
import { mapEdgesToItems } from "@saleor/utils/maps";
|
import { mapEdgesToItems } from "@saleor/utils/maps";
|
||||||
|
@ -300,18 +300,11 @@ export const ProductVariant: React.FC<ProductUpdateProps> = ({
|
||||||
} = useProductSearch({
|
} = useProductSearch({
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
});
|
});
|
||||||
const [focusedAttribute, setFocusedAttribute] = useState<string>();
|
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts
|
||||||
} = useAttributeValueSearch({
|
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
variables: {
|
|
||||||
id: focusedAttribute,
|
|
||||||
...DEFAULT_INITIAL_SEARCH_DATA
|
|
||||||
},
|
|
||||||
skip: !focusedAttribute
|
|
||||||
});
|
|
||||||
|
|
||||||
const fetchMoreReferencePages = {
|
const fetchMoreReferencePages = {
|
||||||
hasMore: searchPagesOpts.data?.search?.pageInfo?.hasNextPage,
|
hasMore: searchPagesOpts.data?.search?.pageInfo?.hasNextPage,
|
||||||
|
@ -382,7 +375,6 @@ export const ProductVariant: React.FC<ProductUpdateProps> = ({
|
||||||
onCloseDialog={() =>
|
onCloseDialog={() =>
|
||||||
navigate(productVariantEditUrl(productId, variantId))
|
navigate(productVariantEditUrl(productId, variantId))
|
||||||
}
|
}
|
||||||
onAttributeFocus={setFocusedAttribute}
|
|
||||||
/>
|
/>
|
||||||
<ProductVariantDeleteDialog
|
<ProductVariantDeleteDialog
|
||||||
confirmButtonState={deleteVariantOpts.status}
|
confirmButtonState={deleteVariantOpts.status}
|
||||||
|
|
|
@ -11,9 +11,9 @@ import { DEFAULT_INITIAL_SEARCH_DATA } from "@saleor/config";
|
||||||
import { useFileUploadMutation } from "@saleor/files/mutations";
|
import { useFileUploadMutation } from "@saleor/files/mutations";
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useShop from "@saleor/hooks/useShop";
|
import useShop from "@saleor/hooks/useShop";
|
||||||
import useAttributeValueSearch from "@saleor/searches/useAttributeValueSearch";
|
|
||||||
import usePageSearch from "@saleor/searches/usePageSearch";
|
import usePageSearch from "@saleor/searches/usePageSearch";
|
||||||
import useProductSearch from "@saleor/searches/useProductSearch";
|
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||||
|
import createAttributeValueSearchHandler from "@saleor/utils/handlers/attributeValueSearchHandler";
|
||||||
import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler";
|
import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler";
|
||||||
import { mapEdgesToItems } from "@saleor/utils/maps";
|
import { mapEdgesToItems } from "@saleor/utils/maps";
|
||||||
import {
|
import {
|
||||||
|
@ -22,7 +22,7 @@ import {
|
||||||
} from "@saleor/utils/metadata/updateMetadata";
|
} from "@saleor/utils/metadata/updateMetadata";
|
||||||
import { useWarehouseList } from "@saleor/warehouses/queries";
|
import { useWarehouseList } from "@saleor/warehouses/queries";
|
||||||
import { warehouseAddPath } from "@saleor/warehouses/urls";
|
import { warehouseAddPath } from "@saleor/warehouses/urls";
|
||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import { weight } from "../../misc";
|
import { weight } from "../../misc";
|
||||||
|
@ -168,18 +168,11 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
||||||
} = useProductSearch({
|
} = useProductSearch({
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
});
|
});
|
||||||
const [focusedAttribute, setFocusedAttribute] = useState<string>();
|
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts
|
||||||
} = useAttributeValueSearch({
|
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
variables: {
|
|
||||||
id: focusedAttribute,
|
|
||||||
...DEFAULT_INITIAL_SEARCH_DATA
|
|
||||||
},
|
|
||||||
skip: !focusedAttribute
|
|
||||||
});
|
|
||||||
|
|
||||||
const fetchMoreReferencePages = {
|
const fetchMoreReferencePages = {
|
||||||
hasMore: searchPagesOpts.data?.search?.pageInfo?.hasNextPage,
|
hasMore: searchPagesOpts.data?.search?.pageInfo?.hasNextPage,
|
||||||
|
@ -247,7 +240,6 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
||||||
fetchAttributeValues={searchAttributeValues}
|
fetchAttributeValues={searchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onCloseDialog={() => navigate(productVariantAddUrl(productId))}
|
onCloseDialog={() => navigate(productVariantAddUrl(productId))}
|
||||||
onAttributeFocus={setFocusedAttribute}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,9 +6,9 @@ import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import { useProductVariantBulkCreateMutation } from "@saleor/products/mutations";
|
import { useProductVariantBulkCreateMutation } from "@saleor/products/mutations";
|
||||||
import { useCreateMultipleVariantsData } from "@saleor/products/queries";
|
import { useCreateMultipleVariantsData } from "@saleor/products/queries";
|
||||||
import { productUrl } from "@saleor/products/urls";
|
import { productUrl } from "@saleor/products/urls";
|
||||||
import useAttributeValueSearch from "@saleor/searches/useAttributeValueSearch";
|
import createAttributeValueSearchHandler from "@saleor/utils/handlers/attributeValueSearchHandler";
|
||||||
import { mapEdgesToItems } from "@saleor/utils/maps";
|
import { mapEdgesToItems } from "@saleor/utils/maps";
|
||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import ProductVariantCreatorPage from "../../components/ProductVariantCreatorPage";
|
import ProductVariantCreatorPage from "../../components/ProductVariantCreatorPage";
|
||||||
|
@ -53,18 +53,11 @@ const ProductVariantCreator: React.FC<ProductVariantCreatorProps> = ({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const [focusedAttribute, setFocusedAttribute] = useState<string>();
|
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts
|
||||||
} = useAttributeValueSearch({
|
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
variables: {
|
|
||||||
id: focusedAttribute,
|
|
||||||
...DEFAULT_INITIAL_SEARCH_DATA
|
|
||||||
},
|
|
||||||
skip: !focusedAttribute
|
|
||||||
});
|
|
||||||
|
|
||||||
const fetchMoreAttributeValues = {
|
const fetchMoreAttributeValues = {
|
||||||
hasMore: !!searchAttributeValuesOpts.data?.attribute?.choices?.pageInfo
|
hasMore: !!searchAttributeValuesOpts.data?.attribute?.choices?.pageInfo
|
||||||
|
@ -107,7 +100,6 @@ const ProductVariantCreator: React.FC<ProductVariantCreatorProps> = ({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
warehouses={mapEdgesToItems(data?.warehouses)}
|
warehouses={mapEdgesToItems(data?.warehouses)}
|
||||||
onAttributeFocus={setFocusedAttribute}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -24,8 +24,7 @@ const props: PageDetailsPageProps = {
|
||||||
attributeValues: [],
|
attributeValues: [],
|
||||||
saveButtonBarState: "default",
|
saveButtonBarState: "default",
|
||||||
fetchAttributeValues: () => undefined,
|
fetchAttributeValues: () => undefined,
|
||||||
fetchMoreAttributeValues: fetchMoreProps,
|
fetchMoreAttributeValues: fetchMoreProps
|
||||||
onAttributeFocus: () => undefined
|
|
||||||
};
|
};
|
||||||
|
|
||||||
storiesOf("Views / Pages / Page details", module)
|
storiesOf("Views / Pages / Page details", module)
|
||||||
|
|
|
@ -56,7 +56,6 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onSelectProductType={() => undefined}
|
onSelectProductType={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("When loading", () => (
|
.add("When loading", () => (
|
||||||
|
@ -93,7 +92,6 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onSelectProductType={() => undefined}
|
onSelectProductType={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("form errors", () => (
|
.add("form errors", () => (
|
||||||
|
@ -145,6 +143,5 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onSelectProductType={() => undefined}
|
onSelectProductType={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
|
@ -70,7 +70,6 @@ const props: ProductUpdatePageProps = {
|
||||||
onVariantsAdd: () => undefined,
|
onVariantsAdd: () => undefined,
|
||||||
onWarehouseConfigure: () => undefined,
|
onWarehouseConfigure: () => undefined,
|
||||||
openChannelsModal: () => undefined,
|
openChannelsModal: () => undefined,
|
||||||
onAttributeFocus: () => undefined,
|
|
||||||
placeholderImage,
|
placeholderImage,
|
||||||
product,
|
product,
|
||||||
referencePages: [],
|
referencePages: [],
|
||||||
|
|
|
@ -40,7 +40,6 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("with errors", () => (
|
.add("with errors", () => (
|
||||||
|
@ -83,7 +82,6 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("when loading data", () => (
|
.add("when loading data", () => (
|
||||||
|
@ -107,7 +105,6 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("add first variant", () => (
|
.add("add first variant", () => (
|
||||||
|
@ -134,7 +131,6 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("no warehouses", () => (
|
.add("no warehouses", () => (
|
||||||
|
@ -158,6 +154,5 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
|
@ -39,7 +39,6 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("when loading data", () => (
|
.add("when loading data", () => (
|
||||||
|
@ -68,7 +67,6 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("no warehouses", () => (
|
.add("no warehouses", () => (
|
||||||
|
@ -96,7 +94,6 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("attribute errors", () => (
|
.add("attribute errors", () => (
|
||||||
|
@ -152,6 +149,5 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onAttributeFocus={() => undefined}
|
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
51
src/utils/handlers/attributeValueSearchHandler.ts
Normal file
51
src/utils/handlers/attributeValueSearchHandler.ts
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import { SearchAttributeValuesVariables } from "@saleor/searches/types/SearchAttributeValues";
|
||||||
|
import useAttributeValueSearch from "@saleor/searches/useAttributeValueSearch";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
interface AttributeValueSearchHandlerState {
|
||||||
|
id: string | null;
|
||||||
|
query: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAttributeValueSearchHandler(
|
||||||
|
variables: SearchAttributeValuesVariables
|
||||||
|
) {
|
||||||
|
const [state, setState] = useState<AttributeValueSearchHandlerState>({
|
||||||
|
id: null,
|
||||||
|
query: variables.query
|
||||||
|
});
|
||||||
|
|
||||||
|
const { loadMore, search, result } = useAttributeValueSearch({
|
||||||
|
variables: {
|
||||||
|
...variables,
|
||||||
|
...state
|
||||||
|
},
|
||||||
|
skip: !state.id
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSearch = (query: string, id: string | null) => {
|
||||||
|
if (query !== state.query) {
|
||||||
|
search(query);
|
||||||
|
}
|
||||||
|
if (id !== state.id || query !== state.query) {
|
||||||
|
setState({
|
||||||
|
query,
|
||||||
|
id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (state.id) {
|
||||||
|
search("");
|
||||||
|
}
|
||||||
|
}, [state.id]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
loadMore,
|
||||||
|
search: handleSearch,
|
||||||
|
result
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default createAttributeValueSearchHandler;
|
Loading…
Reference in a new issue