From 89a8fafea04aa3a52cd926bc3e6957c0cc570202 Mon Sep 17 00:00:00 2001 From: Nakul Nagargade Date: Thu, 30 Jan 2025 16:12:56 +0530 Subject: [PATCH] Fix intermittently default option when selected not being saved correctly --- .../RightSideBar/Inspector/Components/Select.jsx | 4 +--- .../WidgetManager/widgets/dropdownV2.js | 1 - .../Editor/Components/DropdownV2/DropdownV2.jsx | 16 +++------------- .../Editor/WidgetManager/configs/dropdownV2.js | 1 - .../apps/services/widget-config/dropdownV2.js | 1 - 5 files changed, 4 insertions(+), 19 deletions(-) diff --git a/frontend/src/AppBuilder/RightSideBar/Inspector/Components/Select.jsx b/frontend/src/AppBuilder/RightSideBar/Inspector/Components/Select.jsx index a57c879121..db52205467 100644 --- a/frontend/src/AppBuilder/RightSideBar/Inspector/Components/Select.jsx +++ b/frontend/src/AppBuilder/RightSideBar/Inspector/Components/Select.jsx @@ -37,7 +37,6 @@ export function Select({ componentMeta, darkMode, ...restProps }) { if (!Array.isArray(optionsValue)) { optionsValue = Object.values(optionsValue); } - const valuesToResolve = ['label', 'value']; let options = []; if (isDynamicOptionsEnabled || typeof optionsValue === 'string') { @@ -202,9 +201,8 @@ export function Select({ componentMeta, darkMode, ...restProps }) { } }); setOptions(_options); - updateAllOptionsParams(_options); setMarkedAsDefault(_value); - paramUpdated({ name: 'value' }, 'value', _value, 'properties'); + updateAllOptionsParams(_options); } }; diff --git a/frontend/src/AppBuilder/WidgetManager/widgets/dropdownV2.js b/frontend/src/AppBuilder/WidgetManager/widgets/dropdownV2.js index 247af3ccef..de90dbd0bf 100644 --- a/frontend/src/AppBuilder/WidgetManager/widgets/dropdownV2.js +++ b/frontend/src/AppBuilder/WidgetManager/widgets/dropdownV2.js @@ -299,7 +299,6 @@ export const dropdownV2Config = { ], }, label: { value: 'Select' }, - value: { value: '{{"2"}}' }, optionsLoadingState: { value: '{{false}}' }, placeholder: { value: 'Select an option' }, visibility: { value: '{{true}}' }, diff --git a/frontend/src/Editor/Components/DropdownV2/DropdownV2.jsx b/frontend/src/Editor/Components/DropdownV2/DropdownV2.jsx index ae976e54ea..72e2b39664 100644 --- a/frontend/src/Editor/Components/DropdownV2/DropdownV2.jsx +++ b/frontend/src/Editor/Components/DropdownV2/DropdownV2.jsx @@ -61,7 +61,6 @@ export const DropdownV2 = ({ }) => { const { label, - value, advanced, schema, placeholder, @@ -89,7 +88,7 @@ export const DropdownV2 = ({ padding, } = styles; const isInitialRender = useRef(true); - const [currentValue, setCurrentValue] = useState(() => (advanced ? findDefaultItem(schema) : value)); + const [currentValue, setCurrentValue] = useState(() => findDefaultItem(schema)); const isMandatory = validation?.mandatory ?? false; const options = properties?.options; const [validationStatus, setValidationStatus] = useState(validate(currentValue)); @@ -168,18 +167,9 @@ export const DropdownV2 = ({ }; useEffect(() => { - if (advanced) { - setInputValue(findDefaultItem(schema)); - } + setInputValue(findDefaultItem(advanced ? schema : options)); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [advanced, JSON.stringify(schema)]); - - useEffect(() => { - if (!advanced) { - setInputValue(value); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [advanced, value]); + }, [advanced, JSON.stringify(schema), JSON.stringify(options)]); useEffect(() => { if (visibility !== properties.visibility) setVisibility(properties.visibility); diff --git a/frontend/src/Editor/WidgetManager/configs/dropdownV2.js b/frontend/src/Editor/WidgetManager/configs/dropdownV2.js index 247af3ccef..de90dbd0bf 100644 --- a/frontend/src/Editor/WidgetManager/configs/dropdownV2.js +++ b/frontend/src/Editor/WidgetManager/configs/dropdownV2.js @@ -299,7 +299,6 @@ export const dropdownV2Config = { ], }, label: { value: 'Select' }, - value: { value: '{{"2"}}' }, optionsLoadingState: { value: '{{false}}' }, placeholder: { value: 'Select an option' }, visibility: { value: '{{true}}' }, diff --git a/server/src/modules/apps/services/widget-config/dropdownV2.js b/server/src/modules/apps/services/widget-config/dropdownV2.js index 247af3ccef..de90dbd0bf 100644 --- a/server/src/modules/apps/services/widget-config/dropdownV2.js +++ b/server/src/modules/apps/services/widget-config/dropdownV2.js @@ -299,7 +299,6 @@ export const dropdownV2Config = { ], }, label: { value: 'Select' }, - value: { value: '{{"2"}}' }, optionsLoadingState: { value: '{{false}}' }, placeholder: { value: 'Select an option' }, visibility: { value: '{{true}}' },