From 5308313046b8d110a352172cc2c7f17a68512671 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 3 Sep 2024 14:14:41 +0200 Subject: [PATCH] fix for finding execution by index (#32593) fixes: #32481 Signed-off-by: Erik Jan de Wit --- .../__tests__/ExecutionList.test.ts | 24 +++++++++++++++++++ .../src/authentication/execution-model.ts | 14 +++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/js/apps/admin-ui/src/authentication/__tests__/ExecutionList.test.ts b/js/apps/admin-ui/src/authentication/__tests__/ExecutionList.test.ts index 5e5a55a582..69d4b4edb5 100644 --- a/js/apps/admin-ui/src/authentication/__tests__/ExecutionList.test.ts +++ b/js/apps/admin-ui/src/authentication/__tests__/ExecutionList.test.ts @@ -225,4 +225,28 @@ describe("ExecutionList", () => { }, ]); }); + + it("find item by index", () => { + //given + const list = [ + { id: "0", level: 0, index: 0 }, + { id: "1", level: 0, index: 1 }, + { id: "2", level: 0, index: 2 }, + { id: "3", level: 0, index: 3 }, + { id: "4", level: 1, index: 0 }, + { id: "5", level: 1, index: 1 }, + { id: "6", level: 2, index: 0 }, + { id: "7", level: 2, index: 1 }, + { id: "8", level: 0, index: 4 }, + { id: "9", level: 0, index: 5 }, + { id: "10", level: 0, index: 6 }, + ]; + + //when + const result = new ExecutionList(list); + const item = result.findExecution(10); + + //then + expect(item).toEqual({ id: "10", level: 0, index: 6 }); + }); }); diff --git a/js/apps/admin-ui/src/authentication/execution-model.ts b/js/apps/admin-ui/src/authentication/execution-model.ts index e678aade65..d0683b7d1b 100644 --- a/js/apps/admin-ui/src/authentication/execution-model.ts +++ b/js/apps/admin-ui/src/authentication/execution-model.ts @@ -82,27 +82,25 @@ export class ExecutionList { findExecution( index: number, - currentIndex: number | undefined = 0, + current: { index: number } = { index: 0 }, list?: ExpandableExecution[], ): ExpandableExecution | undefined { const l = list || this.expandableList; for (let i = 0; i < l.length; i++) { const ex = l[i]; - if (currentIndex === index) { + + if (current.index === index) { return ex; } - currentIndex++; + current.index++; if (ex.executionList) { - const found = this.findExecution(index, currentIndex, ex.executionList); + const found = this.findExecution(index, current, ex.executionList); if (found) { return found; } - currentIndex += ex.executionList.length; } } - return currentIndex === index - ? this.expandableList[this.expandableList.length - 1] - : undefined; + return undefined; } #getParentNodes(level: number, index: number) {