From 030cf5fb85bd65012f6c7431fc7b923073c4d9ce Mon Sep 17 00:00:00 2001 From: Jagankumar <53823168+jagankumar-egov@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:36:59 +0530 Subject: [PATCH] Update micro-ui/web/micro-ui-internals/packages/modules/workbench/src/components/MultiSelect.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../modules/workbench/src/components/MultiSelect.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/components/MultiSelect.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/components/MultiSelect.js index bbf99e96139..cee29cd217c 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/components/MultiSelect.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/components/MultiSelect.js @@ -133,16 +133,11 @@ const CustomSelectWidget = (props) => { setSelectedDetails(mainData?.filter((obj) => (multiple ? value?.includes(obj.uniqueIdentifier) : obj.uniqueIdentifier == value))); // Update formattedOptions2 - let newFormattedOptions2 = [...formattedOptions]; - if (value && value !== "") { - const existingOption = formattedOptions.find((option) => option.value === value); - if (!existingOption) { - newFormattedOptions2.push({ value, label: `${schemaCode}_${value}` }); - // const updatedSelectedDetails = mainData?.filter((obj) => (multiple ? value?.includes(obj.uniqueIdentifier) : obj.uniqueIdentifier == value)); - // setSelectedDetails(updatedSelectedDetails); + useEffect(() => { + if (value && !formattedOptions.some(option => option.value === value)) { + setFormattedOptions2(prevOptions => [...prevOptions, { value, label: `${schemaCode}_${value}` }]); } - } - setFormattedOptions2(newFormattedOptions2); + }, [value, formattedOptions]); }, [formattedOptions, optionsLimit,value]); const onClickSelect = (selectedValue) => {