From 84704bff45709bde5c494a4cb2872a399fd4e562 Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Thu, 10 Apr 2025 14:59:43 +0000 Subject: [PATCH] Fix: Correctly remove individual condition groups in dynamic group management. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/db1eab1f-8099-4fb2-b481-6a4be55316dc.jpg --- .../dynamic-groups/condition-builder.tsx | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/client/src/components/dynamic-groups/condition-builder.tsx b/client/src/components/dynamic-groups/condition-builder.tsx index 9f4b6a5..fce2710 100644 --- a/client/src/components/dynamic-groups/condition-builder.tsx +++ b/client/src/components/dynamic-groups/condition-builder.tsx @@ -159,10 +159,22 @@ const ConditionBuilder: React.FC = ({ } } - // Remove the group and all its children - const newConditions = conditions.filter( - c => c.id !== conditionToRemove.id && c.parentId !== conditionToRemove.id - ); + // Find just this group's children (not all groups with the same parent) + const childrenToRemove = conditions.filter(c => c.parentId === conditionToRemove.id); + + // Create a list of IDs to remove (the group and its direct children) + const idsToRemove = new Set([ + conditionToRemove.id, + ...childrenToRemove.map(c => c.id).filter(Boolean) + ]); + + // Only remove this specific group and its direct children + const newConditions = conditions.filter(c => { + // Keep the condition if its ID is not in our removal list + // and its parent ID is not the ID of the group we're removing + return !idsToRemove.has(c.id) && c.parentId !== conditionToRemove.id; + }); + onChange(newConditions); } else { // Just remove the single condition