Skip to content

Commit

Permalink
fix(Condition builder): initial state getting reset on re-rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
amal-k-joy committed Dec 9, 2024
1 parent 6e58e9d commit 5c32463
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ const ConditionBuilderContent = ({
}, [actionState]);
useEffect(() => {
if (initialState?.enabledDefault) {
setRootState?.(initialConditionState.current as ConditionBuilderState);
initialConditionState.current = null;
setRootState?.(initialState.state);

Check warning on line 102 in packages/ibm-products/src/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.tsx#L102

Added line #L102 was not covered by tests
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [initialState]);
Expand All @@ -120,12 +119,17 @@ const ConditionBuilderContent = ({

const onRemove = useCallback(
(groupId) => {
const groups = rootState?.groups?.filter(
(group) => groupId !== group?.id
);
setRootState?.({
...rootState,
groups: rootState
? rootState?.groups?.filter((group) => groupId !== group?.id)
: [],
groups: rootState ? groups : [],
});
//set the initial state to empty.
if (groups?.length === 0) {
initialConditionState.current = null;
}
},
[setRootState, rootState]
);
Expand Down

0 comments on commit 5c32463

Please sign in to comment.