fix for finding execution by index

fixes: #32481

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
(cherry picked from commit 5308313046)
This commit is contained in:
Erik Jan de Wit
2024-10-04 14:11:18 +02:00
committed by GitHub
parent e15e4c679d
commit 67b16a099d
2 changed files with 29 additions and 5 deletions

View File

@@ -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 });
});
});

View File

@@ -82,22 +82,22 @@ 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 undefined;