diff --git a/apps/admin-ui/src/authentication/__tests__/ExecutionList.test.ts b/apps/admin-ui/src/authentication/__tests__/ExecutionList.test.ts index abadc561ba..5e5a55a582 100644 --- a/apps/admin-ui/src/authentication/__tests__/ExecutionList.test.ts +++ b/apps/admin-ui/src/authentication/__tests__/ExecutionList.test.ts @@ -188,4 +188,41 @@ describe("ExecutionList", () => { }, ]); }); + + it("When a sub-list has a sub-list all root nodes should not become part of first list", () => { + //given + const list = [ + { id: "0", level: 0, index: 0 }, + { id: "1", level: 1, index: 0 }, + { id: "2", level: 2, index: 0 }, + { id: "3", level: 0, index: 1 }, + ]; + + //when + const result = new ExecutionList(list); + + //then + expect(result.expandableList).toEqual([ + { + executionList: [ + { + id: "1", + index: 0, + isCollapsed: false, + level: 1, + executionList: [{ id: "2", level: 2, index: 0 }], + }, + ], + id: "0", + index: 0, + isCollapsed: false, + level: 0, + }, + { + id: "3", + level: 0, + index: 1, + }, + ]); + }); }); diff --git a/apps/admin-ui/src/authentication/execution-model.ts b/apps/admin-ui/src/authentication/execution-model.ts index 7a6a8fa55c..cbf010ec04 100644 --- a/apps/admin-ui/src/authentication/execution-model.ts +++ b/apps/admin-ui/src/authentication/execution-model.ts @@ -39,32 +39,31 @@ export class ExecutionList { executionList: [], isCollapsed: false, }; - this.transformToExpandableList(0, exList); + this.transformToExpandableList(0, -1, exList); this.expandableList = exList.executionList; } private transformToExpandableList( - currIndex: number, + currentIndex: number, + currentLevel: number, execution: ExpandableExecution ) { - for (let index = currIndex; index < this.list.length; index++) { + for (let index = currentIndex; index < this.list.length; index++) { const ex = this.list[index]; const level = ex.level || 0; - const nextRowLevel = this.list[index + 1]?.level || 0; - const isLeaf = level > nextRowLevel; - const hasChild = level < nextRowLevel; - - if (isLeaf) { - execution.executionList?.push(ex); - return index; + if (level <= currentLevel) { + return index - 1; } - if (ex.level === level && !hasChild) { - execution.executionList?.push(ex); - } else { + const nextRowLevel = this.list[index + 1]?.level || 0; + const hasChild = level < nextRowLevel; + + if (hasChild) { const subLevel = { ...ex, executionList: [], isCollapsed: false }; - index = this.transformToExpandableList(index + 1, subLevel); + index = this.transformToExpandableList(index + 1, level, subLevel); execution.executionList?.push(subLevel); + } else { + execution.executionList?.push(ex); } } return this.list.length;