From aeee6aed51b7052ac95b8a0a0efff65cb8d6046c Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Thu, 10 Apr 2025 21:58:37 +0000 Subject: [PATCH] Fix nested condition display in dynamic group builder 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/fcf50376-b9ed-4d4a-a1cf-906b0aa23dae.jpg --- .../dynamic-groups/condition-builder.tsx | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/client/src/components/dynamic-groups/condition-builder.tsx b/client/src/components/dynamic-groups/condition-builder.tsx index ded5114..ecfcef5 100644 --- a/client/src/components/dynamic-groups/condition-builder.tsx +++ b/client/src/components/dynamic-groups/condition-builder.tsx @@ -83,6 +83,7 @@ const ConditionBuilder: React.FC = ({ const addCondition = (parentId?: number | null) => { const newCondition: Condition = { ...defaultCondition, + id: Math.max(0, ...conditions.map(c => c.id || 0)) + 1, // Generate a new ID parentId }; @@ -105,8 +106,12 @@ const ConditionBuilder: React.FC = ({ // Handle adding a new condition group const addConditionGroup = (parentId?: number | null) => { + // Generate a new ID for the group + const newId = Math.max(0, ...conditions.map(c => c.id || 0)) + 1; + const newGroup: Condition = { ...defaultGroup, + id: newId, // Assign the new ID parentId }; @@ -122,16 +127,14 @@ const ConditionBuilder: React.FC = ({ const newConditions = [...conditions]; newConditions.splice(insertIndex, 0, newGroup); onChange(newConditions); - - // Automatically expand the new group - if (newGroup.id) { - setExpandedGroups(prev => { - const expanded = new Set(prev); - expanded.add(newGroup.id!); - return expanded; - }); - } } + + // Automatically expand the new group + setExpandedGroups(prev => { + const expanded = new Set(prev); + expanded.add(newId); + return expanded; + }); }; // Handle updating a condition