From cc76db4a6f4681e2c665c9b37b66008d64167f8d Mon Sep 17 00:00:00 2001 From: Amal K Joy <153802538+amal-k-joy@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:15:01 +0530 Subject: [PATCH] Update ConditionBuilderContent.tsx --- .../ConditionBuilderContent.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/ibm-products/src/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.tsx b/packages/ibm-products/src/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.tsx index 460c6235e9..fd86105ec9 100644 --- a/packages/ibm-products/src/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.tsx +++ b/packages/ibm-products/src/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.tsx @@ -99,7 +99,8 @@ const ConditionBuilderContent = ({ }, [actionState]); useEffect(() => { if (initialState?.enabledDefault) { - setRootState?.(initialState.state); + setRootState?.(initialConditionState.current as ConditionBuilderState); + initialConditionState.current = null; } // eslint-disable-next-line react-hooks/exhaustive-deps }, [initialState]); @@ -119,17 +120,12 @@ const ConditionBuilderContent = ({ const onRemove = useCallback( (groupId) => { - const groups = rootState?.groups?.filter( - (group) => groupId !== group?.id - ); setRootState?.({ ...rootState, - groups: rootState ? groups : [], + groups: rootState + ? rootState?.groups?.filter((group) => groupId !== group?.id) + : [], }); - //set the initial state to empty. - if (groups?.length === 0) { - initialConditionState.current = null; - } }, [setRootState, rootState] );