Merge pull request #1287 from mirumee/SALEOR-3617-variant-creator-multiselect-fix
variant creator multiselect fix
This commit is contained in:
commit
82e7b58bbf
27 changed files with 141 additions and 35 deletions
|
@ -73,6 +73,7 @@ interface AttributeRowProps extends AttributeRowHandlers {
|
||||||
error: ProductErrorWithAttributesFragment | PageErrorWithAttributesFragment;
|
error: ProductErrorWithAttributesFragment | PageErrorWithAttributesFragment;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
entityId: string;
|
entityId: string;
|
||||||
|
onAttributeSelectBlur?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AttributeRow: React.FC<AttributeRowProps> = ({
|
const AttributeRow: React.FC<AttributeRowProps> = ({
|
||||||
|
@ -89,7 +90,8 @@ const AttributeRow: React.FC<AttributeRowProps> = ({
|
||||||
onChange,
|
onChange,
|
||||||
fetchAttributeValues,
|
fetchAttributeValues,
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
entityId
|
entityId,
|
||||||
|
onAttributeSelectBlur
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const classes = useStyles({});
|
const classes = useStyles({});
|
||||||
|
@ -156,6 +158,7 @@ const AttributeRow: React.FC<AttributeRowProps> = ({
|
||||||
allowCustomValues={true}
|
allowCustomValues={true}
|
||||||
fetchOnFocus={true}
|
fetchOnFocus={true}
|
||||||
fetchChoices={value => fetchAttributeValues(value, attribute.id)}
|
fetchChoices={value => fetchAttributeValues(value, attribute.id)}
|
||||||
|
onBlur={onAttributeSelectBlur}
|
||||||
{...fetchMoreAttributeValues}
|
{...fetchMoreAttributeValues}
|
||||||
/>
|
/>
|
||||||
</BasicAttributeRow>
|
</BasicAttributeRow>
|
||||||
|
@ -268,6 +271,7 @@ const AttributeRow: React.FC<AttributeRowProps> = ({
|
||||||
allowCustomValues={true}
|
allowCustomValues={true}
|
||||||
fetchOnFocus={true}
|
fetchOnFocus={true}
|
||||||
fetchChoices={value => fetchAttributeValues(value, attribute.id)}
|
fetchChoices={value => fetchAttributeValues(value, attribute.id)}
|
||||||
|
onBlur={onAttributeSelectBlur}
|
||||||
{...fetchMoreAttributeValues}
|
{...fetchMoreAttributeValues}
|
||||||
/>
|
/>
|
||||||
</BasicAttributeRow>
|
</BasicAttributeRow>
|
||||||
|
|
|
@ -19,7 +19,8 @@ const props: AttributesProps = {
|
||||||
onReferencesRemove: () => undefined,
|
onReferencesRemove: () => undefined,
|
||||||
onReferencesReorder: () => undefined,
|
onReferencesReorder: () => undefined,
|
||||||
fetchAttributeValues: () => undefined,
|
fetchAttributeValues: () => undefined,
|
||||||
fetchMoreAttributeValues: fetchMoreProps
|
fetchMoreAttributeValues: fetchMoreProps,
|
||||||
|
onAttributeSelectBlur: () => undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
storiesOf("Attributes / Attributes", module)
|
storiesOf("Attributes / Attributes", module)
|
||||||
|
|
|
@ -38,6 +38,7 @@ export interface AttributesProps extends AttributeRowHandlers {
|
||||||
attributeValues: AttributeValueFragment[];
|
attributeValues: AttributeValueFragment[];
|
||||||
fetchAttributeValues: (query: string, attributeId: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
fetchMoreAttributeValues: FetchMoreProps;
|
fetchMoreAttributeValues: FetchMoreProps;
|
||||||
|
onAttributeSelectBlur: () => void;
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
errors: Array<
|
errors: Array<
|
||||||
|
@ -117,6 +118,7 @@ const Attributes: React.FC<AttributesProps> = ({
|
||||||
attributeValues,
|
attributeValues,
|
||||||
errors,
|
errors,
|
||||||
title,
|
title,
|
||||||
|
onAttributeSelectBlur,
|
||||||
entityId = "_defaultId",
|
entityId = "_defaultId",
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -168,6 +170,7 @@ const Attributes: React.FC<AttributesProps> = ({
|
||||||
attribute={attribute}
|
attribute={attribute}
|
||||||
attributeValues={attributeValues}
|
attributeValues={attributeValues}
|
||||||
error={error}
|
error={error}
|
||||||
|
onAttributeSelectBlur={onAttributeSelectBlur}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
|
|
|
@ -89,6 +89,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;
|
||||||
|
onBlur?: () => void;
|
||||||
fetchOnFocus?: boolean;
|
fetchOnFocus?: boolean;
|
||||||
endAdornment?: React.ReactNode;
|
endAdornment?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
@ -115,6 +116,7 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
testId,
|
testId,
|
||||||
fetchChoices,
|
fetchChoices,
|
||||||
onChange,
|
onChange,
|
||||||
|
onBlur,
|
||||||
onFetchMore,
|
onFetchMore,
|
||||||
fetchOnFocus,
|
fetchOnFocus,
|
||||||
endAdornment,
|
endAdornment,
|
||||||
|
@ -142,6 +144,14 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
onInputValueChange={value => debounceFn(value)}
|
onInputValueChange={value => debounceFn(value)}
|
||||||
onSelect={handleSelect}
|
onSelect={handleSelect}
|
||||||
itemToString={() => ""}
|
itemToString={() => ""}
|
||||||
|
// this is to prevent unwanted state updates when the dropdown is closed with an empty value,
|
||||||
|
// which downshift interprets as the value being updated with an empty string, causing side-effects
|
||||||
|
stateReducer={(state, changes) => {
|
||||||
|
if (changes.isOpen === false && state.inputValue === "") {
|
||||||
|
delete changes.inputValue;
|
||||||
|
}
|
||||||
|
return changes;
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{({
|
{({
|
||||||
closeMenu,
|
closeMenu,
|
||||||
|
@ -175,6 +185,7 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
id: undefined,
|
id: undefined,
|
||||||
|
onBlur,
|
||||||
onClick: toggleMenu,
|
onClick: toggleMenu,
|
||||||
onFocus: () => {
|
onFocus: () => {
|
||||||
if (fetchOnFocus) {
|
if (fetchOnFocus) {
|
||||||
|
|
|
@ -49,6 +49,7 @@ export interface SingleAutocompleteSelectFieldProps
|
||||||
fetchOnFocus?: boolean;
|
fetchOnFocus?: boolean;
|
||||||
FormHelperTextProps?: ExtendedFormHelperTextProps;
|
FormHelperTextProps?: ExtendedFormHelperTextProps;
|
||||||
nakedInput?: boolean;
|
nakedInput?: boolean;
|
||||||
|
onBlur?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DebounceAutocomplete: React.ComponentType<DebounceProps<
|
const DebounceAutocomplete: React.ComponentType<DebounceProps<
|
||||||
|
@ -79,6 +80,7 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
|
||||||
fetchOnFocus,
|
fetchOnFocus,
|
||||||
FormHelperTextProps,
|
FormHelperTextProps,
|
||||||
nakedInput = false,
|
nakedInput = false,
|
||||||
|
onBlur,
|
||||||
...rest
|
...rest
|
||||||
} = props;
|
} = props;
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
|
@ -101,6 +103,14 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
|
||||||
onInputValueChange={value => debounceFn(value)}
|
onInputValueChange={value => debounceFn(value)}
|
||||||
onSelect={handleChange}
|
onSelect={handleChange}
|
||||||
selectedItem={value || ""}
|
selectedItem={value || ""}
|
||||||
|
// this is to prevent unwanted state updates when the dropdown is closed with an empty value,
|
||||||
|
// which downshift interprets as the value being updated with an empty string, causing side-effects
|
||||||
|
stateReducer={(_, changes) => {
|
||||||
|
if (changes.isOpen === false) {
|
||||||
|
delete changes.inputValue;
|
||||||
|
}
|
||||||
|
return changes;
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{({
|
{({
|
||||||
getInputProps,
|
getInputProps,
|
||||||
|
@ -150,6 +160,7 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
|
||||||
|
|
||||||
const handleBlur = () => {
|
const handleBlur = () => {
|
||||||
ensureProperValues(true);
|
ensureProperValues(true);
|
||||||
|
onBlur();
|
||||||
closeMenu();
|
closeMenu();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -199,6 +210,7 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
|
||||||
FormHelperTextProps={FormHelperTextProps}
|
FormHelperTextProps={FormHelperTextProps}
|
||||||
label={label}
|
label={label}
|
||||||
fullWidth={true}
|
fullWidth={true}
|
||||||
|
onBlur={onBlur}
|
||||||
/>
|
/>
|
||||||
{isOpen && (!!inputValue || !!choices.length) && (
|
{isOpen && (!!inputValue || !!choices.length) && (
|
||||||
<SingleAutocompleteSelectFieldContent
|
<SingleAutocompleteSelectFieldContent
|
||||||
|
|
|
@ -59,6 +59,7 @@ export interface PageDetailsPageProps {
|
||||||
fetchMoreAttributeValues?: FetchMoreProps;
|
fetchMoreAttributeValues?: FetchMoreProps;
|
||||||
onCloseDialog: () => void;
|
onCloseDialog: () => void;
|
||||||
onSelectPageType?: (pageTypeId: string) => void;
|
onSelectPageType?: (pageTypeId: string) => void;
|
||||||
|
onAttributeSelectBlur: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
||||||
|
@ -85,7 +86,8 @@ const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
||||||
fetchAttributeValues,
|
fetchAttributeValues,
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
onCloseDialog,
|
onCloseDialog,
|
||||||
onSelectPageType
|
onSelectPageType,
|
||||||
|
onAttributeSelectBlur
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const localizeDate = useDateLocalize();
|
const localizeDate = useDateLocalize();
|
||||||
|
@ -189,6 +191,7 @@ const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
|
onAttributeSelectBlur={onAttributeSelectBlur}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
|
|
|
@ -15,7 +15,7 @@ import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
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 useAttributeValueSearchHandler 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 {
|
||||||
|
@ -76,8 +76,9 @@ export const PageCreate: React.FC<PageCreateProps> = ({ params }) => {
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts,
|
||||||
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
reset: searchAttributeReset
|
||||||
|
} = useAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
|
|
||||||
const { data: selectedPageType } = usePageTypeQuery({
|
const { data: selectedPageType } = usePageTypeQuery({
|
||||||
variables: {
|
variables: {
|
||||||
|
@ -218,6 +219,7 @@ 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)}
|
||||||
|
onAttributeSelectBlur={searchAttributeReset}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -26,7 +26,7 @@ import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import { commonMessages } from "@saleor/intl";
|
import { commonMessages } from "@saleor/intl";
|
||||||
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 useAttributeValueSearchHandler 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 {
|
||||||
|
@ -176,8 +176,9 @@ export const PageDetails: React.FC<PageDetailsProps> = ({ id, params }) => {
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts,
|
||||||
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
reset: searchAttributeReset
|
||||||
|
} = useAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
|
|
||||||
const attributeValues =
|
const attributeValues =
|
||||||
mapEdgesToItems(searchAttributeValuesOpts?.data?.attribute.choices) || [];
|
mapEdgesToItems(searchAttributeValuesOpts?.data?.attribute.choices) || [];
|
||||||
|
@ -237,6 +238,7 @@ export const PageDetails: React.FC<PageDetailsProps> = ({ id, params }) => {
|
||||||
fetchAttributeValues={searchAttributeValues}
|
fetchAttributeValues={searchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onCloseDialog={() => navigate(pageUrl(id))}
|
onCloseDialog={() => navigate(pageUrl(id))}
|
||||||
|
onAttributeSelectBlur={searchAttributeReset}
|
||||||
/>
|
/>
|
||||||
<ActionDialog
|
<ActionDialog
|
||||||
open={params.action === "remove"}
|
open={params.action === "remove"}
|
||||||
|
|
|
@ -84,6 +84,7 @@ interface ProductCreatePageProps {
|
||||||
fetchReferenceProducts?: (data: string) => void;
|
fetchReferenceProducts?: (data: string) => void;
|
||||||
fetchMoreReferencePages?: FetchMoreProps;
|
fetchMoreReferencePages?: FetchMoreProps;
|
||||||
fetchMoreReferenceProducts?: FetchMoreProps;
|
fetchMoreReferenceProducts?: FetchMoreProps;
|
||||||
|
onAttributeSelectBlur: () => void;
|
||||||
onCloseDialog: () => void;
|
onCloseDialog: () => void;
|
||||||
onSelectProductType: (productTypeId: string) => void;
|
onSelectProductType: (productTypeId: string) => void;
|
||||||
onBack?();
|
onBack?();
|
||||||
|
@ -129,7 +130,8 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
fetchAttributeValues,
|
fetchAttributeValues,
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
onCloseDialog,
|
onCloseDialog,
|
||||||
onSelectProductType
|
onSelectProductType,
|
||||||
|
onAttributeSelectBlur
|
||||||
}: ProductCreatePageProps) => {
|
}: ProductCreatePageProps) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
@ -240,6 +242,7 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
|
onAttributeSelectBlur={onAttributeSelectBlur}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
|
|
|
@ -37,6 +37,7 @@ const props: ProductUpdatePageProps = {
|
||||||
fetchCategories: () => undefined,
|
fetchCategories: () => undefined,
|
||||||
fetchCollections: () => undefined,
|
fetchCollections: () => undefined,
|
||||||
fetchAttributeValues: () => undefined,
|
fetchAttributeValues: () => undefined,
|
||||||
|
onAttributeSelectBlur: () => undefined,
|
||||||
fetchMoreCategories: fetchMoreProps,
|
fetchMoreCategories: fetchMoreProps,
|
||||||
fetchMoreCollections: fetchMoreProps,
|
fetchMoreCollections: fetchMoreProps,
|
||||||
fetchMoreAttributeValues: fetchMoreProps,
|
fetchMoreAttributeValues: fetchMoreProps,
|
||||||
|
|
|
@ -110,6 +110,7 @@ export interface ProductUpdatePageProps extends ListActions, ChannelProps {
|
||||||
onImageDelete: (id: string) => () => void;
|
onImageDelete: (id: string) => () => void;
|
||||||
onSubmit: (data: ProductUpdatePageSubmitData) => SubmitPromise;
|
onSubmit: (data: ProductUpdatePageSubmitData) => SubmitPromise;
|
||||||
openChannelsModal: () => void;
|
openChannelsModal: () => void;
|
||||||
|
onAttributeSelectBlur: () => void;
|
||||||
onBack?();
|
onBack?();
|
||||||
onDelete();
|
onDelete();
|
||||||
onImageEdit?(id: string);
|
onImageEdit?(id: string);
|
||||||
|
@ -194,7 +195,8 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
onCloseDialog,
|
onCloseDialog,
|
||||||
channelsWithVariantsData,
|
channelsWithVariantsData,
|
||||||
onChannelsChange
|
onChannelsChange,
|
||||||
|
onAttributeSelectBlur
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
@ -317,6 +319,7 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
|
onAttributeSelectBlur={onAttributeSelectBlur}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
|
|
|
@ -85,6 +85,7 @@ interface ProductVariantCreatePageProps {
|
||||||
fetchMoreReferenceProducts?: FetchMoreProps;
|
fetchMoreReferenceProducts?: FetchMoreProps;
|
||||||
fetchMoreAttributeValues?: FetchMoreProps;
|
fetchMoreAttributeValues?: FetchMoreProps;
|
||||||
onCloseDialog: () => void;
|
onCloseDialog: () => void;
|
||||||
|
onAttributeSelectBlur: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
|
@ -112,7 +113,8 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
fetchMoreReferencePages,
|
fetchMoreReferencePages,
|
||||||
fetchMoreReferenceProducts,
|
fetchMoreReferenceProducts,
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
onCloseDialog
|
onCloseDialog,
|
||||||
|
onAttributeSelectBlur
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
@ -192,6 +194,7 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
|
onAttributeSelectBlur={onAttributeSelectBlur}
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<Attributes
|
<Attributes
|
||||||
|
@ -213,6 +216,7 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
|
onAttributeSelectBlur={onAttributeSelectBlur}
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<ProductShipping
|
<ProductShipping
|
||||||
|
|
|
@ -109,7 +109,8 @@ const props: ProductVariantCreatorContentProps = {
|
||||||
errors: [],
|
errors: [],
|
||||||
variantsLeft: 6,
|
variantsLeft: 6,
|
||||||
step: ProductVariantCreatorStep.values,
|
step: ProductVariantCreatorStep.values,
|
||||||
warehouses: warehouseList
|
warehouses: warehouseList,
|
||||||
|
onAttributeSelectBlur: () => undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
storiesOf("Views / Products / Create multiple variants", module)
|
storiesOf("Views / Products / Create multiple variants", module)
|
||||||
|
|
|
@ -29,6 +29,7 @@ export interface ProductVariantCreatorContentProps {
|
||||||
warehouses: WarehouseFragment[];
|
warehouses: WarehouseFragment[];
|
||||||
fetchAttributeValues: (query: string, attributeId: string) => void;
|
fetchAttributeValues: (query: string, attributeId: string) => void;
|
||||||
fetchMoreAttributeValues?: FetchMoreProps;
|
fetchMoreAttributeValues?: FetchMoreProps;
|
||||||
|
onAttributeSelectBlur: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps> = ({
|
const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps> = ({
|
||||||
|
@ -42,7 +43,8 @@ const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps>
|
||||||
errors,
|
errors,
|
||||||
step,
|
step,
|
||||||
variantsLeft,
|
variantsLeft,
|
||||||
warehouses
|
warehouses,
|
||||||
|
onAttributeSelectBlur
|
||||||
}) => {
|
}) => {
|
||||||
const selectedAttributes = attributes.filter(attribute =>
|
const selectedAttributes = attributes.filter(attribute =>
|
||||||
isSelected(
|
isSelected(
|
||||||
|
@ -71,6 +73,7 @@ const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps>
|
||||||
type: ProductVariantCreateReducerActionType.selectValue
|
type: ProductVariantCreateReducerActionType.selectValue
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
onValueBlur={onAttributeSelectBlur}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{step === ProductVariantCreatorStep.prices && (
|
{step === ProductVariantCreatorStep.prices && (
|
||||||
|
|
|
@ -102,6 +102,7 @@ export interface ProductVariantCreatorValuesProps {
|
||||||
attributeId: string,
|
attributeId: string,
|
||||||
value: AttributeValue<Partial<AttributeValueFragment>>
|
value: AttributeValue<Partial<AttributeValueFragment>>
|
||||||
) => void;
|
) => void;
|
||||||
|
onValueBlur: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductVariantCreatorValues: React.FC<ProductVariantCreatorValuesProps> = props => {
|
const ProductVariantCreatorValues: React.FC<ProductVariantCreatorValuesProps> = props => {
|
||||||
|
@ -112,7 +113,8 @@ const ProductVariantCreatorValues: React.FC<ProductVariantCreatorValuesProps> =
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
data,
|
data,
|
||||||
variantsLeft,
|
variantsLeft,
|
||||||
onValueClick
|
onValueClick,
|
||||||
|
onValueBlur
|
||||||
} = props;
|
} = props;
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const variantsNumber = getVariantsNumber(data);
|
const variantsNumber = getVariantsNumber(data);
|
||||||
|
@ -208,6 +210,7 @@ const ProductVariantCreatorValues: React.FC<ProductVariantCreatorValuesProps> =
|
||||||
fetchChoices={value =>
|
fetchChoices={value =>
|
||||||
fetchAttributeValues(value, attribute.id)
|
fetchAttributeValues(value, attribute.id)
|
||||||
}
|
}
|
||||||
|
onBlur={onValueBlur}
|
||||||
{...fetchMoreAttributeValues}
|
{...fetchMoreAttributeValues}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -98,6 +98,7 @@ interface ProductVariantPageProps {
|
||||||
onAssignReferencesClick: (attribute: AttributeInput) => void;
|
onAssignReferencesClick: (attribute: AttributeInput) => void;
|
||||||
onCloseDialog: () => void;
|
onCloseDialog: () => void;
|
||||||
onVariantReorder: ReorderAction;
|
onVariantReorder: ReorderAction;
|
||||||
|
onAttributeSelectBlur: () => void;
|
||||||
onAdd();
|
onAdd();
|
||||||
onBack();
|
onBack();
|
||||||
onDelete();
|
onDelete();
|
||||||
|
@ -140,7 +141,8 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
fetchMoreReferencePages,
|
fetchMoreReferencePages,
|
||||||
fetchMoreReferenceProducts,
|
fetchMoreReferenceProducts,
|
||||||
fetchMoreAttributeValues,
|
fetchMoreAttributeValues,
|
||||||
onCloseDialog
|
onCloseDialog,
|
||||||
|
onAttributeSelectBlur
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
@ -246,6 +248,7 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
|
onAttributeSelectBlur={onAttributeSelectBlur}
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<Attributes
|
<Attributes
|
||||||
|
@ -270,6 +273,7 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
onReferencesReorder={handlers.reorderAttributeValue}
|
onReferencesReorder={handlers.reorderAttributeValue}
|
||||||
fetchAttributeValues={fetchAttributeValues}
|
fetchAttributeValues={fetchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
|
onAttributeSelectBlur={onAttributeSelectBlur}
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<ProductVariantMedia
|
<ProductVariantMedia
|
||||||
|
|
|
@ -35,7 +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 useAttributeValueSearchHandler 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";
|
||||||
|
@ -109,8 +109,9 @@ export const ProductCreateView: React.FC<ProductCreateProps> = ({ params }) => {
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts,
|
||||||
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
reset: searchAttributeReset
|
||||||
|
} = useAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
const warehouses = useWarehouseList({
|
const warehouses = useWarehouseList({
|
||||||
displayLoader: true,
|
displayLoader: true,
|
||||||
variables: {
|
variables: {
|
||||||
|
@ -348,6 +349,7 @@ 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)}
|
||||||
|
onAttributeSelectBlur={searchAttributeReset}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -47,7 +47,7 @@ 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 useAttributeValueSearchHandler 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";
|
||||||
|
@ -148,8 +148,9 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts,
|
||||||
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
reset: searchAttributeReset
|
||||||
|
} = useAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
const warehouses = useWarehouseList({
|
const warehouses = useWarehouseList({
|
||||||
displayLoader: true,
|
displayLoader: true,
|
||||||
variables: {
|
variables: {
|
||||||
|
@ -606,6 +607,7 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
fetchMoreReferenceProducts={fetchMoreReferenceProducts}
|
fetchMoreReferenceProducts={fetchMoreReferenceProducts}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onCloseDialog={() => navigate(productUrl(id))}
|
onCloseDialog={() => navigate(productUrl(id))}
|
||||||
|
onAttributeSelectBlur={searchAttributeReset}
|
||||||
/>
|
/>
|
||||||
<ActionDialog
|
<ActionDialog
|
||||||
open={params.action === "remove"}
|
open={params.action === "remove"}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import { useProductVariantChannelListingUpdate } from "@saleor/products/mutation
|
||||||
import { ProductVariantDetails_productVariant } from "@saleor/products/types/ProductVariantDetails";
|
import { ProductVariantDetails_productVariant } from "@saleor/products/types/ProductVariantDetails";
|
||||||
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 useAttributeValueSearchHandler 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";
|
||||||
|
@ -303,8 +303,9 @@ export const ProductVariant: React.FC<ProductUpdateProps> = ({
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts,
|
||||||
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
reset: searchAttributeReset
|
||||||
|
} = useAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
|
|
||||||
const fetchMoreReferencePages = {
|
const fetchMoreReferencePages = {
|
||||||
hasMore: searchPagesOpts.data?.search?.pageInfo?.hasNextPage,
|
hasMore: searchPagesOpts.data?.search?.pageInfo?.hasNextPage,
|
||||||
|
@ -376,6 +377,7 @@ export const ProductVariant: React.FC<ProductUpdateProps> = ({
|
||||||
onCloseDialog={() =>
|
onCloseDialog={() =>
|
||||||
navigate(productVariantEditUrl(productId, variantId))
|
navigate(productVariantEditUrl(productId, variantId))
|
||||||
}
|
}
|
||||||
|
onAttributeSelectBlur={searchAttributeReset}
|
||||||
/>
|
/>
|
||||||
<ProductVariantDeleteDialog
|
<ProductVariantDeleteDialog
|
||||||
confirmButtonState={deleteVariantOpts.status}
|
confirmButtonState={deleteVariantOpts.status}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useShop from "@saleor/hooks/useShop";
|
import useShop from "@saleor/hooks/useShop";
|
||||||
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 useAttributeValueSearchHandler 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 {
|
||||||
|
@ -171,8 +171,9 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts,
|
||||||
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
reset: searchAttributeReset
|
||||||
|
} = useAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
|
|
||||||
const fetchMoreReferencePages = {
|
const fetchMoreReferencePages = {
|
||||||
hasMore: searchPagesOpts.data?.search?.pageInfo?.hasNextPage,
|
hasMore: searchPagesOpts.data?.search?.pageInfo?.hasNextPage,
|
||||||
|
@ -241,6 +242,7 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
||||||
fetchAttributeValues={searchAttributeValues}
|
fetchAttributeValues={searchAttributeValues}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onCloseDialog={() => navigate(productVariantAddUrl(productId))}
|
onCloseDialog={() => navigate(productVariantAddUrl(productId))}
|
||||||
|
onAttributeSelectBlur={searchAttributeReset}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,7 +6,7 @@ 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 createAttributeValueSearchHandler from "@saleor/utils/handlers/attributeValueSearchHandler";
|
import useAttributeValueSearchHandler from "@saleor/utils/handlers/attributeValueSearchHandler";
|
||||||
import { mapEdgesToItems } from "@saleor/utils/maps";
|
import { mapEdgesToItems } from "@saleor/utils/maps";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
@ -56,8 +56,9 @@ const ProductVariantCreator: React.FC<ProductVariantCreatorProps> = ({
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreAttributeValues,
|
loadMore: loadMoreAttributeValues,
|
||||||
search: searchAttributeValues,
|
search: searchAttributeValues,
|
||||||
|
reset: searchAttributeReset,
|
||||||
result: searchAttributeValuesOpts
|
result: searchAttributeValuesOpts
|
||||||
} = createAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
} = useAttributeValueSearchHandler(DEFAULT_INITIAL_SEARCH_DATA);
|
||||||
|
|
||||||
const fetchMoreAttributeValues = {
|
const fetchMoreAttributeValues = {
|
||||||
hasMore: !!searchAttributeValuesOpts.data?.attribute?.choices?.pageInfo
|
hasMore: !!searchAttributeValuesOpts.data?.attribute?.choices?.pageInfo
|
||||||
|
@ -98,6 +99,7 @@ const ProductVariantCreator: React.FC<ProductVariantCreatorProps> = ({
|
||||||
variables: { id, inputs }
|
variables: { id, inputs }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
onAttributeSelectBlur={searchAttributeReset}
|
||||||
warehouses={mapEdgesToItems(data?.warehouses) || []}
|
warehouses={mapEdgesToItems(data?.warehouses) || []}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -24,6 +24,7 @@ const props: PageDetailsPageProps = {
|
||||||
attributeValues: [],
|
attributeValues: [],
|
||||||
saveButtonBarState: "default",
|
saveButtonBarState: "default",
|
||||||
fetchAttributeValues: () => undefined,
|
fetchAttributeValues: () => undefined,
|
||||||
|
onAttributeSelectBlur: () => undefined,
|
||||||
fetchMoreAttributeValues: fetchMoreProps
|
fetchMoreAttributeValues: fetchMoreProps
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onSelectProductType={() => undefined}
|
onSelectProductType={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("When loading", () => (
|
.add("When loading", () => (
|
||||||
|
@ -92,6 +93,7 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onSelectProductType={() => undefined}
|
onSelectProductType={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("form errors", () => (
|
.add("form errors", () => (
|
||||||
|
@ -143,5 +145,6 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
onSelectProductType={() => undefined}
|
onSelectProductType={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
|
@ -48,6 +48,7 @@ const props: ProductUpdatePageProps = {
|
||||||
fetchCategories: () => undefined,
|
fetchCategories: () => undefined,
|
||||||
fetchCollections: () => undefined,
|
fetchCollections: () => undefined,
|
||||||
fetchAttributeValues: () => undefined,
|
fetchAttributeValues: () => undefined,
|
||||||
|
onAttributeSelectBlur: () => undefined,
|
||||||
fetchMoreCategories: fetchMoreProps,
|
fetchMoreCategories: fetchMoreProps,
|
||||||
fetchMoreCollections: fetchMoreProps,
|
fetchMoreCollections: fetchMoreProps,
|
||||||
fetchMoreAttributeValues: fetchMoreProps,
|
fetchMoreAttributeValues: fetchMoreProps,
|
||||||
|
|
|
@ -40,6 +40,7 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("with errors", () => (
|
.add("with errors", () => (
|
||||||
|
@ -82,6 +83,7 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("when loading data", () => (
|
.add("when loading data", () => (
|
||||||
|
@ -105,6 +107,7 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("add first variant", () => (
|
.add("add first variant", () => (
|
||||||
|
@ -131,6 +134,7 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("no warehouses", () => (
|
.add("no warehouses", () => (
|
||||||
|
@ -154,5 +158,6 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
|
@ -39,6 +39,7 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("when loading data", () => (
|
.add("when loading data", () => (
|
||||||
|
@ -67,6 +68,7 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("no warehouses", () => (
|
.add("no warehouses", () => (
|
||||||
|
@ -94,6 +96,7 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("attribute errors", () => (
|
.add("attribute errors", () => (
|
||||||
|
@ -149,5 +152,6 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
fetchAttributeValues={() => undefined}
|
fetchAttributeValues={() => undefined}
|
||||||
onAssignReferencesClick={() => undefined}
|
onAssignReferencesClick={() => undefined}
|
||||||
onCloseDialog={() => undefined}
|
onCloseDialog={() => undefined}
|
||||||
|
onAttributeSelectBlur={() => undefined}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
import { SearchAttributeValuesVariables } from "@saleor/searches/types/SearchAttributeValues";
|
import { UseSearchResult } from "@saleor/hooks/makeSearch";
|
||||||
|
import {
|
||||||
|
SearchAttributeValues,
|
||||||
|
SearchAttributeValuesVariables
|
||||||
|
} from "@saleor/searches/types/SearchAttributeValues";
|
||||||
import useAttributeValueSearch from "@saleor/searches/useAttributeValueSearch";
|
import useAttributeValueSearch from "@saleor/searches/useAttributeValueSearch";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
@ -7,9 +11,18 @@ interface AttributeValueSearchHandlerState {
|
||||||
query: string;
|
query: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createAttributeValueSearchHandler(
|
export interface UseAttributeValueSearchHandler
|
||||||
|
extends Omit<
|
||||||
|
UseSearchResult<SearchAttributeValues, SearchAttributeValuesVariables>,
|
||||||
|
"search"
|
||||||
|
> {
|
||||||
|
reset: () => void;
|
||||||
|
search: (query: string, id: string | null) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function useAttributeValueSearchHandler(
|
||||||
variables: SearchAttributeValuesVariables
|
variables: SearchAttributeValuesVariables
|
||||||
) {
|
): UseAttributeValueSearchHandler {
|
||||||
const [state, setState] = useState<AttributeValueSearchHandlerState>({
|
const [state, setState] = useState<AttributeValueSearchHandlerState>({
|
||||||
id: null,
|
id: null,
|
||||||
query: variables.query
|
query: variables.query
|
||||||
|
@ -35,16 +48,25 @@ function createAttributeValueSearchHandler(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const reset = () => setState(prevState => ({ ...prevState, id: null }));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state.id) {
|
if (state.id) {
|
||||||
search("");
|
search("");
|
||||||
}
|
}
|
||||||
}, [state.id]);
|
}, [state.id]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loadMore,
|
loadMore,
|
||||||
search: handleSearch,
|
search: handleSearch,
|
||||||
result
|
reset,
|
||||||
|
result: state.id
|
||||||
|
? result
|
||||||
|
: {
|
||||||
|
...result,
|
||||||
|
data: undefined
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createAttributeValueSearchHandler;
|
export default useAttributeValueSearchHandler;
|
||||||
|
|
Loading…
Reference in a new issue