2022-04-28 08:43:05 +00:00
|
|
|
import {
|
|
|
|
InputBase,
|
|
|
|
Popper,
|
|
|
|
PopperPlacementType,
|
2022-06-21 09:36:55 +00:00
|
|
|
TextField,
|
2022-04-28 08:43:05 +00:00
|
|
|
} from "@material-ui/core";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { InputProps } from "@material-ui/core/Input";
|
2021-01-26 10:21:54 +00:00
|
|
|
import { ExtendedFormHelperTextProps } from "@saleor/channels/components/ChannelForm/types";
|
2022-09-23 11:39:25 +00:00
|
|
|
import { ChevronIcon } from "@saleor/macaw-ui";
|
2020-05-14 09:30:32 +00:00
|
|
|
import { FetchMoreProps } from "@saleor/types";
|
2020-09-23 08:29:13 +00:00
|
|
|
import classNames from "classnames";
|
2021-05-24 13:50:41 +00:00
|
|
|
import Downshift from "downshift";
|
2019-10-16 15:51:53 +00:00
|
|
|
import { filter } from "fuzzaldrin";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
import Debounce, { DebounceProps } from "../Debounce";
|
2019-12-02 10:49:14 +00:00
|
|
|
import SingleAutocompleteSelectFieldContent, {
|
2020-05-14 09:30:32 +00:00
|
|
|
SingleAutocompleteActionType,
|
2022-06-21 09:36:55 +00:00
|
|
|
SingleAutocompleteChoiceType,
|
2019-12-02 10:49:14 +00:00
|
|
|
} from "./SingleAutocompleteSelectFieldContent";
|
2022-09-23 11:39:25 +00:00
|
|
|
import { useStyles } from "./styles";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-10-14 14:17:03 +00:00
|
|
|
export interface SingleAutocompleteSelectFieldProps
|
|
|
|
extends Partial<FetchMoreProps> {
|
2020-02-11 14:41:56 +00:00
|
|
|
add?: SingleAutocompleteActionType;
|
2020-09-23 08:29:13 +00:00
|
|
|
className?: string;
|
2019-06-19 14:40:52 +00:00
|
|
|
error?: boolean;
|
|
|
|
name: string;
|
2019-08-09 11:14:35 +00:00
|
|
|
displayValue: string;
|
|
|
|
emptyOption?: boolean;
|
2021-09-21 13:16:21 +00:00
|
|
|
choices: Array<SingleAutocompleteChoiceType<string, string | JSX.Element>>;
|
2019-10-14 14:17:03 +00:00
|
|
|
value: string;
|
2019-06-19 14:40:52 +00:00
|
|
|
disabled?: boolean;
|
|
|
|
placeholder?: string;
|
2019-08-09 11:14:35 +00:00
|
|
|
allowCustomValues?: boolean;
|
2019-06-19 14:40:52 +00:00
|
|
|
helperText?: string;
|
|
|
|
label?: string;
|
|
|
|
InputProps?: InputProps;
|
2019-08-09 11:14:35 +00:00
|
|
|
fetchChoices?: (value: string) => void;
|
|
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
2021-06-14 12:19:23 +00:00
|
|
|
fetchOnFocus?: boolean;
|
2021-01-26 10:21:54 +00:00
|
|
|
FormHelperTextProps?: ExtendedFormHelperTextProps;
|
Add channel shipping zones (#1015)
* Add naked input option to SingleAutocompleteSelectField and update it's stories
* Add new icons - chevron up, down & trash
* Add deletable item component and stories
* Add card add items footer component to be used in warehouses and product stocks assign
* Update schema and types
* Add shipping zones card components
* Update channel details page form to also include shipping zones
* Update makeTopLevelSearch hook files directory and add getSearchFetchMoreProps function to avoid extracting it manually every time
* Update channels types & fragments
* Move getDefaultNotifierSuccessErrorData function to useNotifier utils, update dir etc., also make order discount provider use it from the new dir
* Add shippinh zone to channel update and create and add shipping zone search
* Update messages
* Fix types
* Fix lint, types etc
* Small refactor from review and quick fix styles of shipping zones card
* Refactor a bit and update snapshots
* Refactor a bit and update snapshots
* Addd / refactor channels availability components
* Add useChannelsWithProductVariants hook with utils and types
* Add / refactor more channels availability components
* Move avatar from table cell avatar to separate component for it to be usable outside of tables
* Add channels with variants logic to product create and update pages & views
* Refactor components to use updated channels availability components
* Remove unnecessary comments
* Update storybook
* Update types
* Update messages
* Fix prices for variants / simple product not uodating properly
* Post merge cleanup, update schema, types, etc.
* Change shipping zone details warehouses card into settings card and add ability to assign channels to shipping zone
* Update types
* Update snapshots
* Fix selecting / deselecting all channels in channels with variants modal
* Fixes after review, some types changes etc.
* Update snapshots
* Small types fixes
* Make price rates views use parent shipping method channels instead of all
* Make price rates views use parent shipping method channels instead of all
* Update types
* Fix bugs
* Fixes after review
* Fix channels availability data submission
* Fix lint
* Fix variant pricing card showing not related channels
* Fixes after review
* Fix types
* Hide unaviable variants in add products to draft order dialog
* Fix channels with variants availability modal showing confirm button as enabled when it shouldn't
* Fix types
* Update semi checked icon to match old designs
* Update types
* Update channels icon in channels with variants availability
* Fix product cypress test after product channels mutation changed
* Fix trash and chevron down colors in dark mode
* Fix shipping zones card footer not updating query after click away
* Fix types in schema, add condition not to display shipping zones select in channel details if all zones have already been selected
* Fix products adding in order draft dialog
* Fix simple productupdate
* Update snapshots after merge with master
* Update messages
* Fix product api request for cypress
* Add missing test id
* Fix selecting if product is simple -> form being submitted with empty data sometimes
* Update snapshots, messages and add fix for invalid date at product update
* Remove unnecessary imports
* Fix failing test in saleor 2552 (#1061)
* fix
* fix
* fix
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
Co-authored-by: Karolina <rakoczy.karolina@gmail.com>
2021-04-14 13:44:25 +00:00
|
|
|
nakedInput?: boolean;
|
2021-08-11 14:38:44 +00:00
|
|
|
onBlur?: () => void;
|
2022-04-28 08:43:05 +00:00
|
|
|
popperPlacement?: PopperPlacementType;
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 15:36:45 +00:00
|
|
|
const DebounceAutocomplete: React.ComponentType<DebounceProps<
|
|
|
|
string
|
|
|
|
>> = Debounce;
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2020-01-15 15:36:45 +00:00
|
|
|
const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectFieldProps> = props => {
|
2019-10-30 14:34:24 +00:00
|
|
|
const {
|
2020-02-10 16:07:17 +00:00
|
|
|
add,
|
2019-08-09 11:14:35 +00:00
|
|
|
allowCustomValues,
|
2020-09-23 08:29:13 +00:00
|
|
|
className,
|
2020-01-15 15:36:45 +00:00
|
|
|
choices,
|
2019-06-19 14:40:52 +00:00
|
|
|
disabled,
|
2019-08-09 11:14:35 +00:00
|
|
|
displayValue,
|
|
|
|
emptyOption,
|
2019-06-19 14:40:52 +00:00
|
|
|
error,
|
2019-10-14 14:17:03 +00:00
|
|
|
hasMore,
|
2019-06-19 14:40:52 +00:00
|
|
|
helperText,
|
|
|
|
label,
|
|
|
|
loading,
|
|
|
|
name,
|
|
|
|
placeholder,
|
|
|
|
value,
|
|
|
|
InputProps,
|
|
|
|
fetchChoices,
|
2019-08-27 13:29:00 +00:00
|
|
|
onChange,
|
2019-10-14 14:17:03 +00:00
|
|
|
onFetchMore,
|
2021-06-14 12:19:23 +00:00
|
|
|
fetchOnFocus,
|
2021-01-26 10:21:54 +00:00
|
|
|
FormHelperTextProps,
|
Add channel shipping zones (#1015)
* Add naked input option to SingleAutocompleteSelectField and update it's stories
* Add new icons - chevron up, down & trash
* Add deletable item component and stories
* Add card add items footer component to be used in warehouses and product stocks assign
* Update schema and types
* Add shipping zones card components
* Update channel details page form to also include shipping zones
* Update makeTopLevelSearch hook files directory and add getSearchFetchMoreProps function to avoid extracting it manually every time
* Update channels types & fragments
* Move getDefaultNotifierSuccessErrorData function to useNotifier utils, update dir etc., also make order discount provider use it from the new dir
* Add shippinh zone to channel update and create and add shipping zone search
* Update messages
* Fix types
* Fix lint, types etc
* Small refactor from review and quick fix styles of shipping zones card
* Refactor a bit and update snapshots
* Refactor a bit and update snapshots
* Addd / refactor channels availability components
* Add useChannelsWithProductVariants hook with utils and types
* Add / refactor more channels availability components
* Move avatar from table cell avatar to separate component for it to be usable outside of tables
* Add channels with variants logic to product create and update pages & views
* Refactor components to use updated channels availability components
* Remove unnecessary comments
* Update storybook
* Update types
* Update messages
* Fix prices for variants / simple product not uodating properly
* Post merge cleanup, update schema, types, etc.
* Change shipping zone details warehouses card into settings card and add ability to assign channels to shipping zone
* Update types
* Update snapshots
* Fix selecting / deselecting all channels in channels with variants modal
* Fixes after review, some types changes etc.
* Update snapshots
* Small types fixes
* Make price rates views use parent shipping method channels instead of all
* Make price rates views use parent shipping method channels instead of all
* Update types
* Fix bugs
* Fixes after review
* Fix channels availability data submission
* Fix lint
* Fix variant pricing card showing not related channels
* Fixes after review
* Fix types
* Hide unaviable variants in add products to draft order dialog
* Fix channels with variants availability modal showing confirm button as enabled when it shouldn't
* Fix types
* Update semi checked icon to match old designs
* Update types
* Update channels icon in channels with variants availability
* Fix product cypress test after product channels mutation changed
* Fix trash and chevron down colors in dark mode
* Fix shipping zones card footer not updating query after click away
* Fix types in schema, add condition not to display shipping zones select in channel details if all zones have already been selected
* Fix products adding in order draft dialog
* Fix simple productupdate
* Update snapshots after merge with master
* Update messages
* Fix product api request for cypress
* Add missing test id
* Fix selecting if product is simple -> form being submitted with empty data sometimes
* Update snapshots, messages and add fix for invalid date at product update
* Remove unnecessary imports
* Fix failing test in saleor 2552 (#1061)
* fix
* fix
* fix
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
Co-authored-by: Karolina <rakoczy.karolina@gmail.com>
2021-04-14 13:44:25 +00:00
|
|
|
nakedInput = false,
|
2021-08-11 14:38:44 +00:00
|
|
|
onBlur,
|
2022-04-28 08:43:05 +00:00
|
|
|
popperPlacement = "bottom-end",
|
2019-10-30 14:34:24 +00:00
|
|
|
...rest
|
|
|
|
} = props;
|
|
|
|
const classes = useStyles(props);
|
2022-03-16 09:45:15 +00:00
|
|
|
const anchor = React.useRef<HTMLDivElement | null>(null);
|
|
|
|
const input = React.useRef<HTMLInputElement | null>(null);
|
2019-10-14 11:57:08 +00:00
|
|
|
|
2021-05-24 13:50:41 +00:00
|
|
|
const handleChange = (item: string) => {
|
2019-10-30 14:34:24 +00:00
|
|
|
onChange({
|
|
|
|
target: {
|
|
|
|
name,
|
2022-06-21 09:36:55 +00:00
|
|
|
value: item,
|
|
|
|
},
|
2019-10-30 14:34:24 +00:00
|
|
|
} as any);
|
2020-10-12 10:45:07 +00:00
|
|
|
};
|
2019-08-09 11:14:35 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
return (
|
|
|
|
<DebounceAutocomplete debounceFn={fetchChoices}>
|
|
|
|
{debounceFn => (
|
|
|
|
<Downshift
|
2020-10-12 10:45:07 +00:00
|
|
|
itemToString={() => displayValue || ""}
|
2019-10-30 14:34:24 +00:00
|
|
|
onInputValueChange={value => debounceFn(value)}
|
|
|
|
onSelect={handleChange}
|
2021-05-24 13:50:41 +00:00
|
|
|
selectedItem={value || ""}
|
2021-08-11 14:38:44 +00:00
|
|
|
// 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
|
2021-08-12 09:00:49 +00:00
|
|
|
stateReducer={(_, changes) => {
|
|
|
|
if (changes.isOpen === false) {
|
2021-08-11 14:38:44 +00:00
|
|
|
delete changes.inputValue;
|
|
|
|
}
|
|
|
|
return changes;
|
|
|
|
}}
|
2019-10-30 14:34:24 +00:00
|
|
|
>
|
|
|
|
{({
|
|
|
|
getInputProps,
|
|
|
|
getItemProps,
|
|
|
|
isOpen,
|
|
|
|
inputValue,
|
|
|
|
selectedItem,
|
|
|
|
toggleMenu,
|
|
|
|
closeMenu,
|
|
|
|
highlightedIndex,
|
2022-03-25 12:37:01 +00:00
|
|
|
reset,
|
2019-10-30 14:34:24 +00:00
|
|
|
}) => {
|
|
|
|
const isCustomValueSelected =
|
|
|
|
choices && selectedItem
|
|
|
|
? choices.filter(c => c.value === selectedItem).length === 0
|
|
|
|
: false;
|
2019-08-09 11:14:35 +00:00
|
|
|
|
2020-10-22 08:33:01 +00:00
|
|
|
const choiceFromInputValue = choices.find(
|
2022-06-21 09:36:55 +00:00
|
|
|
({ value: choiceId }) => choiceId === inputValue,
|
2020-10-22 08:33:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const isValueInValues = !!choiceFromInputValue;
|
|
|
|
|
|
|
|
const isValueInLabels = !!choices.find(
|
2022-06-21 09:36:55 +00:00
|
|
|
choice => choice.label === inputValue,
|
2020-10-22 08:33:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const ensureProperValues = (alwaysCheck: boolean = false) => {
|
2020-10-22 10:28:15 +00:00
|
|
|
if ((allowCustomValues || isValueInLabels) && !alwaysCheck) {
|
2020-10-22 08:33:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isValueInValues && !isValueInLabels) {
|
2021-09-21 13:16:21 +00:00
|
|
|
reset({ inputValue: choiceFromInputValue.value });
|
2020-10-22 08:33:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
reset({ inputValue: displayValue });
|
2020-10-22 08:33:01 +00:00
|
|
|
};
|
2019-10-14 11:57:08 +00:00
|
|
|
|
2020-10-22 08:33:01 +00:00
|
|
|
const displayCustomValue = !!(
|
2019-10-30 14:34:24 +00:00
|
|
|
inputValue &&
|
|
|
|
inputValue.length > 0 &&
|
|
|
|
allowCustomValues &&
|
2020-10-22 08:33:01 +00:00
|
|
|
!isValueInLabels
|
|
|
|
);
|
2019-10-30 14:34:24 +00:00
|
|
|
|
2020-10-21 13:07:54 +00:00
|
|
|
const handleBlur = () => {
|
2020-10-22 08:33:01 +00:00
|
|
|
ensureProperValues(true);
|
2021-09-01 11:25:00 +00:00
|
|
|
if (onBlur) {
|
|
|
|
onBlur();
|
|
|
|
}
|
2020-10-22 08:33:01 +00:00
|
|
|
closeMenu();
|
|
|
|
};
|
|
|
|
|
2022-09-23 11:39:25 +00:00
|
|
|
const handleFocus = () => {
|
|
|
|
if (fetchOnFocus) {
|
|
|
|
fetchChoices(inputValue);
|
|
|
|
}
|
|
|
|
input.current.select();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleToggleMenu = () => {
|
|
|
|
if (disabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
toggleMenu();
|
|
|
|
};
|
|
|
|
|
Add channel shipping zones (#1015)
* Add naked input option to SingleAutocompleteSelectField and update it's stories
* Add new icons - chevron up, down & trash
* Add deletable item component and stories
* Add card add items footer component to be used in warehouses and product stocks assign
* Update schema and types
* Add shipping zones card components
* Update channel details page form to also include shipping zones
* Update makeTopLevelSearch hook files directory and add getSearchFetchMoreProps function to avoid extracting it manually every time
* Update channels types & fragments
* Move getDefaultNotifierSuccessErrorData function to useNotifier utils, update dir etc., also make order discount provider use it from the new dir
* Add shippinh zone to channel update and create and add shipping zone search
* Update messages
* Fix types
* Fix lint, types etc
* Small refactor from review and quick fix styles of shipping zones card
* Refactor a bit and update snapshots
* Refactor a bit and update snapshots
* Addd / refactor channels availability components
* Add useChannelsWithProductVariants hook with utils and types
* Add / refactor more channels availability components
* Move avatar from table cell avatar to separate component for it to be usable outside of tables
* Add channels with variants logic to product create and update pages & views
* Refactor components to use updated channels availability components
* Remove unnecessary comments
* Update storybook
* Update types
* Update messages
* Fix prices for variants / simple product not uodating properly
* Post merge cleanup, update schema, types, etc.
* Change shipping zone details warehouses card into settings card and add ability to assign channels to shipping zone
* Update types
* Update snapshots
* Fix selecting / deselecting all channels in channels with variants modal
* Fixes after review, some types changes etc.
* Update snapshots
* Small types fixes
* Make price rates views use parent shipping method channels instead of all
* Make price rates views use parent shipping method channels instead of all
* Update types
* Fix bugs
* Fixes after review
* Fix channels availability data submission
* Fix lint
* Fix variant pricing card showing not related channels
* Fixes after review
* Fix types
* Hide unaviable variants in add products to draft order dialog
* Fix channels with variants availability modal showing confirm button as enabled when it shouldn't
* Fix types
* Update semi checked icon to match old designs
* Update types
* Update channels icon in channels with variants availability
* Fix product cypress test after product channels mutation changed
* Fix trash and chevron down colors in dark mode
* Fix shipping zones card footer not updating query after click away
* Fix types in schema, add condition not to display shipping zones select in channel details if all zones have already been selected
* Fix products adding in order draft dialog
* Fix simple productupdate
* Update snapshots after merge with master
* Update messages
* Fix product api request for cypress
* Add missing test id
* Fix selecting if product is simple -> form being submitted with empty data sometimes
* Update snapshots, messages and add fix for invalid date at product update
* Remove unnecessary imports
* Fix failing test in saleor 2552 (#1061)
* fix
* fix
* fix
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
Co-authored-by: Karolina <rakoczy.karolina@gmail.com>
2021-04-14 13:44:25 +00:00
|
|
|
const TextFieldComponent = nakedInput ? InputBase : TextField;
|
|
|
|
|
|
|
|
const commonInputProps = {
|
|
|
|
...InputProps,
|
|
|
|
endAdornment: (
|
2022-03-25 12:37:01 +00:00
|
|
|
<div
|
2022-09-23 11:39:25 +00:00
|
|
|
onClick={() => {
|
|
|
|
handleToggleMenu();
|
|
|
|
handleFocus();
|
|
|
|
}}
|
2022-03-25 12:37:01 +00:00
|
|
|
className={classNames(classes.adornment, {
|
2022-06-21 09:36:55 +00:00
|
|
|
[classes.adornmentRotate]: isOpen,
|
2022-03-25 12:37:01 +00:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
<ChevronIcon />
|
Add channel shipping zones (#1015)
* Add naked input option to SingleAutocompleteSelectField and update it's stories
* Add new icons - chevron up, down & trash
* Add deletable item component and stories
* Add card add items footer component to be used in warehouses and product stocks assign
* Update schema and types
* Add shipping zones card components
* Update channel details page form to also include shipping zones
* Update makeTopLevelSearch hook files directory and add getSearchFetchMoreProps function to avoid extracting it manually every time
* Update channels types & fragments
* Move getDefaultNotifierSuccessErrorData function to useNotifier utils, update dir etc., also make order discount provider use it from the new dir
* Add shippinh zone to channel update and create and add shipping zone search
* Update messages
* Fix types
* Fix lint, types etc
* Small refactor from review and quick fix styles of shipping zones card
* Refactor a bit and update snapshots
* Refactor a bit and update snapshots
* Addd / refactor channels availability components
* Add useChannelsWithProductVariants hook with utils and types
* Add / refactor more channels availability components
* Move avatar from table cell avatar to separate component for it to be usable outside of tables
* Add channels with variants logic to product create and update pages & views
* Refactor components to use updated channels availability components
* Remove unnecessary comments
* Update storybook
* Update types
* Update messages
* Fix prices for variants / simple product not uodating properly
* Post merge cleanup, update schema, types, etc.
* Change shipping zone details warehouses card into settings card and add ability to assign channels to shipping zone
* Update types
* Update snapshots
* Fix selecting / deselecting all channels in channels with variants modal
* Fixes after review, some types changes etc.
* Update snapshots
* Small types fixes
* Make price rates views use parent shipping method channels instead of all
* Make price rates views use parent shipping method channels instead of all
* Update types
* Fix bugs
* Fixes after review
* Fix channels availability data submission
* Fix lint
* Fix variant pricing card showing not related channels
* Fixes after review
* Fix types
* Hide unaviable variants in add products to draft order dialog
* Fix channels with variants availability modal showing confirm button as enabled when it shouldn't
* Fix types
* Update semi checked icon to match old designs
* Update types
* Update channels icon in channels with variants availability
* Fix product cypress test after product channels mutation changed
* Fix trash and chevron down colors in dark mode
* Fix shipping zones card footer not updating query after click away
* Fix types in schema, add condition not to display shipping zones select in channel details if all zones have already been selected
* Fix products adding in order draft dialog
* Fix simple productupdate
* Update snapshots after merge with master
* Update messages
* Fix product api request for cypress
* Add missing test id
* Fix selecting if product is simple -> form being submitted with empty data sometimes
* Update snapshots, messages and add fix for invalid date at product update
* Remove unnecessary imports
* Fix failing test in saleor 2552 (#1061)
* fix
* fix
* fix
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
Co-authored-by: Karolina <rakoczy.karolina@gmail.com>
2021-04-14 13:44:25 +00:00
|
|
|
</div>
|
|
|
|
),
|
|
|
|
error,
|
|
|
|
id: undefined,
|
2022-09-23 11:39:25 +00:00
|
|
|
onFocus: handleFocus,
|
|
|
|
ref: anchor,
|
Add channel shipping zones (#1015)
* Add naked input option to SingleAutocompleteSelectField and update it's stories
* Add new icons - chevron up, down & trash
* Add deletable item component and stories
* Add card add items footer component to be used in warehouses and product stocks assign
* Update schema and types
* Add shipping zones card components
* Update channel details page form to also include shipping zones
* Update makeTopLevelSearch hook files directory and add getSearchFetchMoreProps function to avoid extracting it manually every time
* Update channels types & fragments
* Move getDefaultNotifierSuccessErrorData function to useNotifier utils, update dir etc., also make order discount provider use it from the new dir
* Add shippinh zone to channel update and create and add shipping zone search
* Update messages
* Fix types
* Fix lint, types etc
* Small refactor from review and quick fix styles of shipping zones card
* Refactor a bit and update snapshots
* Refactor a bit and update snapshots
* Addd / refactor channels availability components
* Add useChannelsWithProductVariants hook with utils and types
* Add / refactor more channels availability components
* Move avatar from table cell avatar to separate component for it to be usable outside of tables
* Add channels with variants logic to product create and update pages & views
* Refactor components to use updated channels availability components
* Remove unnecessary comments
* Update storybook
* Update types
* Update messages
* Fix prices for variants / simple product not uodating properly
* Post merge cleanup, update schema, types, etc.
* Change shipping zone details warehouses card into settings card and add ability to assign channels to shipping zone
* Update types
* Update snapshots
* Fix selecting / deselecting all channels in channels with variants modal
* Fixes after review, some types changes etc.
* Update snapshots
* Small types fixes
* Make price rates views use parent shipping method channels instead of all
* Make price rates views use parent shipping method channels instead of all
* Update types
* Fix bugs
* Fixes after review
* Fix channels availability data submission
* Fix lint
* Fix variant pricing card showing not related channels
* Fixes after review
* Fix types
* Hide unaviable variants in add products to draft order dialog
* Fix channels with variants availability modal showing confirm button as enabled when it shouldn't
* Fix types
* Update semi checked icon to match old designs
* Update types
* Update channels icon in channels with variants availability
* Fix product cypress test after product channels mutation changed
* Fix trash and chevron down colors in dark mode
* Fix shipping zones card footer not updating query after click away
* Fix types in schema, add condition not to display shipping zones select in channel details if all zones have already been selected
* Fix products adding in order draft dialog
* Fix simple productupdate
* Update snapshots after merge with master
* Update messages
* Fix product api request for cypress
* Add missing test id
* Fix selecting if product is simple -> form being submitted with empty data sometimes
* Update snapshots, messages and add fix for invalid date at product update
* Remove unnecessary imports
* Fix failing test in saleor 2552 (#1061)
* fix
* fix
* fix
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
Co-authored-by: Karolina <rakoczy.karolina@gmail.com>
2021-04-14 13:44:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const nakedInputProps = nakedInput
|
|
|
|
? {
|
|
|
|
"aria-label": "naked",
|
|
|
|
...commonInputProps,
|
|
|
|
autoFocus: true,
|
2022-03-25 12:37:01 +00:00
|
|
|
className: classes.nakedInput,
|
2022-06-21 09:36:55 +00:00
|
|
|
onBlur: handleBlur,
|
Add channel shipping zones (#1015)
* Add naked input option to SingleAutocompleteSelectField and update it's stories
* Add new icons - chevron up, down & trash
* Add deletable item component and stories
* Add card add items footer component to be used in warehouses and product stocks assign
* Update schema and types
* Add shipping zones card components
* Update channel details page form to also include shipping zones
* Update makeTopLevelSearch hook files directory and add getSearchFetchMoreProps function to avoid extracting it manually every time
* Update channels types & fragments
* Move getDefaultNotifierSuccessErrorData function to useNotifier utils, update dir etc., also make order discount provider use it from the new dir
* Add shippinh zone to channel update and create and add shipping zone search
* Update messages
* Fix types
* Fix lint, types etc
* Small refactor from review and quick fix styles of shipping zones card
* Refactor a bit and update snapshots
* Refactor a bit and update snapshots
* Addd / refactor channels availability components
* Add useChannelsWithProductVariants hook with utils and types
* Add / refactor more channels availability components
* Move avatar from table cell avatar to separate component for it to be usable outside of tables
* Add channels with variants logic to product create and update pages & views
* Refactor components to use updated channels availability components
* Remove unnecessary comments
* Update storybook
* Update types
* Update messages
* Fix prices for variants / simple product not uodating properly
* Post merge cleanup, update schema, types, etc.
* Change shipping zone details warehouses card into settings card and add ability to assign channels to shipping zone
* Update types
* Update snapshots
* Fix selecting / deselecting all channels in channels with variants modal
* Fixes after review, some types changes etc.
* Update snapshots
* Small types fixes
* Make price rates views use parent shipping method channels instead of all
* Make price rates views use parent shipping method channels instead of all
* Update types
* Fix bugs
* Fixes after review
* Fix channels availability data submission
* Fix lint
* Fix variant pricing card showing not related channels
* Fixes after review
* Fix types
* Hide unaviable variants in add products to draft order dialog
* Fix channels with variants availability modal showing confirm button as enabled when it shouldn't
* Fix types
* Update semi checked icon to match old designs
* Update types
* Update channels icon in channels with variants availability
* Fix product cypress test after product channels mutation changed
* Fix trash and chevron down colors in dark mode
* Fix shipping zones card footer not updating query after click away
* Fix types in schema, add condition not to display shipping zones select in channel details if all zones have already been selected
* Fix products adding in order draft dialog
* Fix simple productupdate
* Update snapshots after merge with master
* Update messages
* Fix product api request for cypress
* Add missing test id
* Fix selecting if product is simple -> form being submitted with empty data sometimes
* Update snapshots, messages and add fix for invalid date at product update
* Remove unnecessary imports
* Fix failing test in saleor 2552 (#1061)
* fix
* fix
* fix
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
Co-authored-by: Karolina <rakoczy.karolina@gmail.com>
2021-04-14 13:44:25 +00:00
|
|
|
}
|
|
|
|
: {};
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
return (
|
2020-09-23 08:29:13 +00:00
|
|
|
<div
|
|
|
|
className={classNames(classes.container, className)}
|
|
|
|
{...rest}
|
|
|
|
>
|
Add channel shipping zones (#1015)
* Add naked input option to SingleAutocompleteSelectField and update it's stories
* Add new icons - chevron up, down & trash
* Add deletable item component and stories
* Add card add items footer component to be used in warehouses and product stocks assign
* Update schema and types
* Add shipping zones card components
* Update channel details page form to also include shipping zones
* Update makeTopLevelSearch hook files directory and add getSearchFetchMoreProps function to avoid extracting it manually every time
* Update channels types & fragments
* Move getDefaultNotifierSuccessErrorData function to useNotifier utils, update dir etc., also make order discount provider use it from the new dir
* Add shippinh zone to channel update and create and add shipping zone search
* Update messages
* Fix types
* Fix lint, types etc
* Small refactor from review and quick fix styles of shipping zones card
* Refactor a bit and update snapshots
* Refactor a bit and update snapshots
* Addd / refactor channels availability components
* Add useChannelsWithProductVariants hook with utils and types
* Add / refactor more channels availability components
* Move avatar from table cell avatar to separate component for it to be usable outside of tables
* Add channels with variants logic to product create and update pages & views
* Refactor components to use updated channels availability components
* Remove unnecessary comments
* Update storybook
* Update types
* Update messages
* Fix prices for variants / simple product not uodating properly
* Post merge cleanup, update schema, types, etc.
* Change shipping zone details warehouses card into settings card and add ability to assign channels to shipping zone
* Update types
* Update snapshots
* Fix selecting / deselecting all channels in channels with variants modal
* Fixes after review, some types changes etc.
* Update snapshots
* Small types fixes
* Make price rates views use parent shipping method channels instead of all
* Make price rates views use parent shipping method channels instead of all
* Update types
* Fix bugs
* Fixes after review
* Fix channels availability data submission
* Fix lint
* Fix variant pricing card showing not related channels
* Fixes after review
* Fix types
* Hide unaviable variants in add products to draft order dialog
* Fix channels with variants availability modal showing confirm button as enabled when it shouldn't
* Fix types
* Update semi checked icon to match old designs
* Update types
* Update channels icon in channels with variants availability
* Fix product cypress test after product channels mutation changed
* Fix trash and chevron down colors in dark mode
* Fix shipping zones card footer not updating query after click away
* Fix types in schema, add condition not to display shipping zones select in channel details if all zones have already been selected
* Fix products adding in order draft dialog
* Fix simple productupdate
* Update snapshots after merge with master
* Update messages
* Fix product api request for cypress
* Add missing test id
* Fix selecting if product is simple -> form being submitted with empty data sometimes
* Update snapshots, messages and add fix for invalid date at product update
* Remove unnecessary imports
* Fix failing test in saleor 2552 (#1061)
* fix
* fix
* fix
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
Co-authored-by: Karolina <rakoczy.karolina@gmail.com>
2021-04-14 13:44:25 +00:00
|
|
|
<TextFieldComponent
|
|
|
|
{...nakedInputProps}
|
|
|
|
InputProps={commonInputProps}
|
2022-03-01 15:04:44 +00:00
|
|
|
// Downshift doesn't seem to be fully compatible with MUI
|
|
|
|
// https://github.com/downshift-js/downshift/issues/718
|
|
|
|
inputProps={{
|
|
|
|
...getInputProps({
|
|
|
|
placeholder,
|
2022-09-23 11:39:25 +00:00
|
|
|
onClick: handleToggleMenu,
|
2022-06-21 09:36:55 +00:00
|
|
|
}),
|
2022-03-01 15:04:44 +00:00
|
|
|
}}
|
2019-10-30 14:34:24 +00:00
|
|
|
error={error}
|
|
|
|
disabled={disabled}
|
|
|
|
helperText={helperText}
|
2021-01-26 10:21:54 +00:00
|
|
|
FormHelperTextProps={FormHelperTextProps}
|
2019-10-30 14:34:24 +00:00
|
|
|
label={label}
|
|
|
|
fullWidth={true}
|
2021-08-12 09:00:49 +00:00
|
|
|
onBlur={onBlur}
|
2022-03-16 09:45:15 +00:00
|
|
|
inputRef={input}
|
2019-10-30 14:34:24 +00:00
|
|
|
/>
|
|
|
|
{isOpen && (!!inputValue || !!choices.length) && (
|
2022-01-28 12:34:20 +00:00
|
|
|
<Popper
|
|
|
|
anchorEl={anchor.current}
|
|
|
|
open={isOpen}
|
|
|
|
style={{ width: anchor.current.clientWidth, zIndex: 1301 }}
|
2022-04-28 08:43:05 +00:00
|
|
|
placement={popperPlacement}
|
2022-01-28 12:34:20 +00:00
|
|
|
>
|
|
|
|
<SingleAutocompleteSelectFieldContent
|
|
|
|
add={
|
|
|
|
!!add && {
|
|
|
|
...add,
|
|
|
|
onClick: () => {
|
|
|
|
add.onClick();
|
|
|
|
closeMenu();
|
2022-06-21 09:36:55 +00:00
|
|
|
},
|
2020-02-11 14:41:56 +00:00
|
|
|
}
|
2020-02-10 16:07:17 +00:00
|
|
|
}
|
2022-01-28 12:34:20 +00:00
|
|
|
choices={choices}
|
|
|
|
displayCustomValue={displayCustomValue}
|
|
|
|
emptyOption={emptyOption}
|
|
|
|
getItemProps={getItemProps}
|
|
|
|
hasMore={hasMore}
|
|
|
|
highlightedIndex={highlightedIndex}
|
|
|
|
loading={loading}
|
|
|
|
inputValue={inputValue}
|
|
|
|
isCustomValueSelected={isCustomValueSelected}
|
|
|
|
selectedItem={selectedItem}
|
|
|
|
onFetchMore={onFetchMore}
|
|
|
|
/>
|
|
|
|
</Popper>
|
2019-10-30 14:34:24 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Downshift>
|
|
|
|
)}
|
|
|
|
</DebounceAutocomplete>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2020-01-15 15:36:45 +00:00
|
|
|
const SingleAutocompleteSelectField: React.FC<SingleAutocompleteSelectFieldProps> = ({
|
|
|
|
choices,
|
|
|
|
fetchChoices,
|
|
|
|
...rest
|
|
|
|
}) => {
|
2019-10-16 15:51:53 +00:00
|
|
|
const [query, setQuery] = React.useState("");
|
2020-10-12 10:45:07 +00:00
|
|
|
|
2019-10-16 15:51:53 +00:00
|
|
|
if (fetchChoices) {
|
2019-06-19 14:40:52 +00:00
|
|
|
return (
|
2021-07-01 08:20:35 +00:00
|
|
|
<SingleAutocompleteSelectFieldComponent
|
|
|
|
choices={choices}
|
|
|
|
{...rest}
|
|
|
|
fetchChoices={fetchChoices}
|
|
|
|
/>
|
2019-06-19 14:40:52 +00:00
|
|
|
);
|
|
|
|
}
|
2019-10-14 14:17:03 +00:00
|
|
|
|
2019-10-16 15:51:53 +00:00
|
|
|
return (
|
|
|
|
<SingleAutocompleteSelectFieldComponent
|
|
|
|
fetchChoices={q => setQuery(q || "")}
|
|
|
|
choices={filter(choices, query, {
|
2022-06-21 09:36:55 +00:00
|
|
|
key: "label",
|
2019-10-16 15:51:53 +00:00
|
|
|
})}
|
2019-10-30 14:34:24 +00:00
|
|
|
{...rest}
|
2019-10-16 15:51:53 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2021-03-19 12:06:17 +00:00
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
export default SingleAutocompleteSelectField;
|