Skip to content

Commit

Permalink
fix(common): lift compare values from select promises
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 committed Mar 21, 2024
1 parent a3f8df1 commit 30d1a88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 4 additions & 7 deletions packages/common/src/use-select/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const init = ({ propsOptions, optionsTransformer }) => ({
...(optionsTransformer && { originalOptions: propsOptions }),
});

const reducer = (state, { type, payload, options = [], optionsTransformer }) => {
const reducer = (state, { type, payload, options = [], optionsTransformer, compareValues }) => {
switch (type) {
case 'updateOptions':
return {
Expand Down Expand Up @@ -42,14 +42,11 @@ const reducer = (state, { type, payload, options = [], optionsTransformer }) =>
options: optionsTransformer
? optionsTransformer([
...state.options,
...options.filter(({ value }) => !state.options.find((option) => payload.compareValues(option.value, value))),
...options.filter(({ value }) => !state.options.find((option) => compareValues(option.value, value))),

Check warning on line 45 in packages/common/src/use-select/reducer.js

View check run for this annotation

Codecov / codecov/patch

packages/common/src/use-select/reducer.js#L45

Added line #L45 was not covered by tests
])
: [...state.options, ...options.filter(({ value }) => !state.options.find((option) => payload.compareValues(option.value, value)))],
: [...state.options, ...options.filter(({ value }) => !state.options.find((option) => compareValues(option.value, value)))],
...(optionsTransformer && {
originalOptions: [
...state.options,
...options.filter(({ value }) => !state.options.find((option) => payload.compareValues(option.value, value))),
],
originalOptions: [...state.options, ...options.filter(({ value }) => !state.options.find((option) => compareValues(option.value, value)))],

Check warning on line 49 in packages/common/src/use-select/reducer.js

View check run for this annotation

Codecov / codecov/patch

packages/common/src/use-select/reducer.js#L49

Added line #L49 was not covered by tests
}),
};
default:
Expand Down
5 changes: 3 additions & 2 deletions packages/common/src/use-select/use-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ const useSelect = ({

const onInputChange = (inputValue) => {
if (inputValue && loadOptions && state.promises[inputValue] === undefined && isSearchable) {
dispatch({ type: 'setPromises', payload: { [inputValue]: true, compareValues } });
dispatch({ type: 'setPromises', payload: { [inputValue]: true }, compareValues });

loadOptions(inputValue)
.then((options) => {
if (isMounted.current) {
dispatch({
type: 'setPromises',
payload: { [inputValue]: false, compareValues },
payload: { [inputValue]: false },
compareValues,
options,
});
}
Expand Down

0 comments on commit 30d1a88

Please sign in to comment.