Removing collection fix (#1764)
* Pass combined choices to autocomplete handler * Refactor autocomplete handler to use combined choices
This commit is contained in:
parent
80f3af4e5e
commit
1e3f3eae8d
2 changed files with 11 additions and 1 deletions
|
@ -1,9 +1,11 @@
|
||||||
import { ThemeType } from "@saleor/macaw-ui";
|
import { ThemeType } from "@saleor/macaw-ui";
|
||||||
|
import uniqBy from "lodash/uniqBy";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { MutationFunction, MutationResult } from "react-apollo";
|
import { MutationFunction, MutationResult } from "react-apollo";
|
||||||
import { IntlShape } from "react-intl";
|
import { IntlShape } from "react-intl";
|
||||||
|
|
||||||
import { ConfirmButtonTransitionState } from "./components/ConfirmButton";
|
import { ConfirmButtonTransitionState } from "./components/ConfirmButton";
|
||||||
|
import { MultiAutocompleteChoiceType } from "./components/MultiAutocompleteSelectField";
|
||||||
import { StatusType } from "./components/StatusChip/types";
|
import { StatusType } from "./components/StatusChip/types";
|
||||||
import { StatusLabelProps } from "./components/StatusLabel";
|
import { StatusLabelProps } from "./components/StatusLabel";
|
||||||
import { AddressType, AddressTypeInput } from "./customers/types";
|
import { AddressType, AddressTypeInput } from "./customers/types";
|
||||||
|
@ -469,3 +471,8 @@ export function PromiseQueue() {
|
||||||
|
|
||||||
return { queue, add };
|
return { queue, add };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const combinedMultiAutocompleteChoices = (
|
||||||
|
selected: MultiAutocompleteChoiceType[],
|
||||||
|
choices: MultiAutocompleteChoiceType[]
|
||||||
|
) => uniqBy([...selected, ...choices], "value");
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocompleteSelectField";
|
import { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocompleteSelectField";
|
||||||
import { ChangeEvent, FormChange } from "@saleor/hooks/useForm";
|
import { ChangeEvent, FormChange } from "@saleor/hooks/useForm";
|
||||||
|
import { combinedMultiAutocompleteChoices } from "@saleor/misc";
|
||||||
import { toggle } from "@saleor/utils/lists";
|
import { toggle } from "@saleor/utils/lists";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,8 +15,10 @@ function createMultiAutocompleteSelectHandler(
|
||||||
return (event: ChangeEvent) => {
|
return (event: ChangeEvent) => {
|
||||||
change(event);
|
change(event);
|
||||||
|
|
||||||
|
const combinedChoices = combinedMultiAutocompleteChoices(selected, choices);
|
||||||
|
|
||||||
const id = event.target.value;
|
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));
|
setSelected(toggle(choice, selected, (a, b) => a.value === b.value));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue