Removing collection fix (#1764)

* Pass combined choices to autocomplete handler

* Refactor autocomplete handler to use combined choices
This commit is contained in:
Wojciech Mista 2022-01-24 14:58:27 +01:00 committed by GitHub
parent 80f3af4e5e
commit 1e3f3eae8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -1,9 +1,11 @@
import { ThemeType } from "@saleor/macaw-ui";
import uniqBy from "lodash/uniqBy";
import moment from "moment-timezone";
import { MutationFunction, MutationResult } from "react-apollo";
import { IntlShape } from "react-intl";
import { ConfirmButtonTransitionState } from "./components/ConfirmButton";
import { MultiAutocompleteChoiceType } from "./components/MultiAutocompleteSelectField";
import { StatusType } from "./components/StatusChip/types";
import { StatusLabelProps } from "./components/StatusLabel";
import { AddressType, AddressTypeInput } from "./customers/types";
@ -469,3 +471,8 @@ export function PromiseQueue() {
return { queue, add };
}
export const combinedMultiAutocompleteChoices = (
selected: MultiAutocompleteChoiceType[],
choices: MultiAutocompleteChoiceType[]
) => uniqBy([...selected, ...choices], "value");

View file

@ -1,5 +1,6 @@
import { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocompleteSelectField";
import { ChangeEvent, FormChange } from "@saleor/hooks/useForm";
import { combinedMultiAutocompleteChoices } from "@saleor/misc";
import { toggle } from "@saleor/utils/lists";
/**
@ -14,8 +15,10 @@ function createMultiAutocompleteSelectHandler(
return (event: ChangeEvent) => {
change(event);
const combinedChoices = combinedMultiAutocompleteChoices(selected, choices);
const id = event.target.value;
const choice = choices.find(choice => choice.value === id);
const choice = combinedChoices.find(choice => choice.value === id);
setSelected(toggle(choice, selected, (a, b) => a.value === b.value));
};