saleor-dashboard/src/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx

276 lines
7.6 KiB
TypeScript
Raw Normal View History

import { InputBase, TextField } from "@material-ui/core";
2019-06-19 14:40:52 +00:00
import { InputProps } from "@material-ui/core/Input";
import { ExtendedFormHelperTextProps } from "@saleor/channels/components/ChannelForm/types";
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
import { makeStyles } from "@saleor/macaw-ui";
import { FetchMoreProps } from "@saleor/types";
2020-09-23 08:29:13 +00:00
import classNames from "classnames";
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 ArrowDropdownIcon from "../../icons/ArrowDropdown";
import Debounce, { DebounceProps } from "../Debounce";
2019-12-02 10:49:14 +00:00
import SingleAutocompleteSelectFieldContent, {
SingleAutocompleteActionType,
SingleAutocompleteChoiceType
2019-12-02 10:49:14 +00:00
} from "./SingleAutocompleteSelectFieldContent";
2019-06-19 14:40:52 +00:00
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
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
theme => ({
2019-12-03 15:28:40 +00:00
container: {
flexGrow: 1,
position: "relative"
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: {
padding: theme.spacing(2, 3)
2019-12-03 15:28:40 +00:00
}
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-12-03 15:28:40 +00:00
{ name: "SingleAutocompleteSelectField" }
);
2019-06-19 14:40:52 +00:00
2019-10-14 14:17:03 +00:00
export interface SingleAutocompleteSelectFieldProps
extends Partial<FetchMoreProps> {
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;
choices: SingleAutocompleteChoiceType[];
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;
fetchOnFocus?: boolean;
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;
onBlur?: () => void;
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,
fetchOnFocus,
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,
onBlur,
2019-10-30 14:34:24 +00:00
...rest
} = props;
const classes = useStyles(props);
2019-10-14 11:57:08 +00:00
const handleChange = (item: string) => {
2019-10-30 14:34:24 +00:00
onChange({
target: {
name,
value: item
}
} 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
defaultInputValue={displayValue}
2020-10-12 10:45:07 +00:00
itemToString={() => displayValue || ""}
2019-10-30 14:34:24 +00:00
onInputValueChange={value => debounceFn(value)}
onSelect={handleChange}
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={(state, changes) => {
if (changes.isOpen === false && state.inputValue === "") {
delete changes.inputValue;
}
return changes;
}}
2019-10-30 14:34:24 +00:00
>
{({
getInputProps,
getItemProps,
isOpen,
inputValue,
selectedItem,
toggleMenu,
closeMenu,
highlightedIndex,
reset
}) => {
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(
({ value: choiceId }) => choiceId === inputValue
);
const isValueInValues = !!choiceFromInputValue;
const isValueInLabels = !!choices.find(
choice => choice.label === inputValue
);
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) {
reset({ inputValue: choiceFromInputValue.label });
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);
onBlur();
2020-10-22 08:33:01 +00:00
closeMenu();
};
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,
...getInputProps({
placeholder
}),
endAdornment: (
<div>
<ArrowDropdownIcon />
</div>
),
error,
id: undefined,
onBlur: handleBlur,
onClick: toggleMenu,
onFocus: () => {
if (fetchOnFocus) {
fetchChoices(inputValue);
}
}
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,
className: classes.nakedInput
}
: {};
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}
2019-10-30 14:34:24 +00:00
error={error}
disabled={disabled}
helperText={helperText}
FormHelperTextProps={FormHelperTextProps}
2019-10-30 14:34:24 +00:00
label={label}
fullWidth={true}
/>
{isOpen && (!!inputValue || !!choices.length) && (
<SingleAutocompleteSelectFieldContent
add={
!!add && {
...add,
onClick: () => {
add.onClick();
closeMenu();
}
2020-02-10 16:07:17 +00:00
}
}
2019-10-30 14:34:24 +00:00
choices={choices}
displayCustomValue={displayCustomValue}
emptyOption={emptyOption}
getItemProps={getItemProps}
hasMore={hasMore}
highlightedIndex={highlightedIndex}
loading={loading}
inputValue={inputValue}
isCustomValueSelected={isCustomValueSelected}
selectedItem={selectedItem}
onFetchMore={onFetchMore}
/>
)}
</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 (
<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, {
key: "label"
})}
2019-10-30 14:34:24 +00:00
{...rest}
2019-10-16 15:51:53 +00:00
/>
);
};
2019-06-19 14:40:52 +00:00
export default SingleAutocompleteSelectField;