From 30d1a8869f01543ef169d00c9ccbdcbf07b3bc3c Mon Sep 17 00:00:00 2001 From: Martin Marosi Date: Thu, 21 Mar 2024 09:42:24 +0100 Subject: [PATCH] fix(common): lift compare values from select promises --- packages/common/src/use-select/reducer.js | 11 ++++------- packages/common/src/use-select/use-select.js | 5 +++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/common/src/use-select/reducer.js b/packages/common/src/use-select/reducer.js index 688fcd51d..458755534 100644 --- a/packages/common/src/use-select/reducer.js +++ b/packages/common/src/use-select/reducer.js @@ -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 { @@ -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))), ]) - : [...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)))], }), }; default: diff --git a/packages/common/src/use-select/use-select.js b/packages/common/src/use-select/use-select.js index 07503438a..614c4bcd0 100644 --- a/packages/common/src/use-select/use-select.js +++ b/packages/common/src/use-select/use-select.js @@ -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, }); }