mirror of
https://github.com/freedbygrace/ActiveDirectoryManager.git
synced 2026-08-24 08:56:26 +00:00
Improve dynamic group removal to correctly handle nested groups.
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/6b72a278-9794-4f7e-82b8-31b11f924c8e.jpg
This commit is contained in:
@@ -141,11 +141,11 @@ const ConditionBuilder: React.FC<ConditionBuilderProps> = ({
|
|||||||
onChange(newConditions);
|
onChange(newConditions);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle removing a condition
|
// Handle removing a condition or group
|
||||||
const removeCondition = (index: number) => {
|
const removeCondition = (index: number) => {
|
||||||
const conditionToRemove = conditions[index];
|
const conditionToRemove = conditions[index];
|
||||||
|
|
||||||
// If it's a group, also remove all child conditions
|
// If it's a group, also check for child conditions
|
||||||
if (conditionToRemove.isGroup) {
|
if (conditionToRemove.isGroup) {
|
||||||
const childConditions = conditions.filter(c => c.parentId === conditionToRemove.id);
|
const childConditions = conditions.filter(c => c.parentId === conditionToRemove.id);
|
||||||
|
|
||||||
@@ -160,29 +160,41 @@ const ConditionBuilder: React.FC<ConditionBuilderProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find just this group's children (not all groups with the same parent)
|
// Find just this group's children (not all groups with the same parent)
|
||||||
const childrenToRemove = conditions.filter(c => c.parentId === conditionToRemove.id);
|
const childrenToRemove = getAllDescendants(conditionToRemove.id);
|
||||||
|
|
||||||
// Create a list of IDs to remove (the group and its direct children)
|
// Create a list of IDs to remove (the group and all its descendants)
|
||||||
const idsToRemove = new Set([
|
const idsToRemove = new Set([
|
||||||
conditionToRemove.id,
|
conditionToRemove.id,
|
||||||
...childrenToRemove.map(c => c.id).filter(Boolean)
|
...childrenToRemove.map(c => c.id).filter(Boolean)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Only remove this specific group and its direct children
|
// Only remove this specific group and its descendants
|
||||||
const newConditions = conditions.filter(c => {
|
const newConditions = conditions.filter(c => {
|
||||||
// Keep the condition if its ID is not in our removal list
|
// 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
|
// and its parent ID is not in our removal list
|
||||||
return !idsToRemove.has(c.id) && c.parentId !== conditionToRemove.id;
|
return !idsToRemove.has(c.id) &&
|
||||||
|
!idsToRemove.has(c.parentId);
|
||||||
});
|
});
|
||||||
|
|
||||||
onChange(newConditions);
|
onChange(newConditions);
|
||||||
} else {
|
} else {
|
||||||
// Just remove the single condition
|
// Just remove the single condition, more carefully
|
||||||
const newConditions = [...conditions];
|
const newConditions = conditions.filter((c, i) => i !== index);
|
||||||
newConditions.splice(index, 1);
|
|
||||||
onChange(newConditions);
|
onChange(newConditions);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper function to get all descendants of a condition group
|
||||||
|
const getAllDescendants = (parentId: number): Condition[] => {
|
||||||
|
const directChildren = conditions.filter(c => c.parentId === parentId);
|
||||||
|
|
||||||
|
// Get all children of groups within this group (recursively)
|
||||||
|
const groupChildren = directChildren
|
||||||
|
.filter(c => c.isGroup && c.id)
|
||||||
|
.flatMap(group => getAllDescendants(group.id!));
|
||||||
|
|
||||||
|
return [...directChildren, ...groupChildren];
|
||||||
|
};
|
||||||
|
|
||||||
// Toggle group expansion
|
// Toggle group expansion
|
||||||
const toggleGroupExpand = (groupId: number) => {
|
const toggleGroupExpand = (groupId: number) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user