fix for finding execution by index (#32593)
fixes: #32481 Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
parent
db7694e7be
commit
5308313046
2 changed files with 30 additions and 8 deletions
|
@ -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 });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -82,27 +82,25 @@ export class ExecutionList {
|
||||||
|
|
||||||
findExecution(
|
findExecution(
|
||||||
index: number,
|
index: number,
|
||||||
currentIndex: number | undefined = 0,
|
current: { index: number } = { index: 0 },
|
||||||
list?: ExpandableExecution[],
|
list?: ExpandableExecution[],
|
||||||
): ExpandableExecution | undefined {
|
): ExpandableExecution | undefined {
|
||||||
const l = list || this.expandableList;
|
const l = list || this.expandableList;
|
||||||
for (let i = 0; i < l.length; i++) {
|
for (let i = 0; i < l.length; i++) {
|
||||||
const ex = l[i];
|
const ex = l[i];
|
||||||
if (currentIndex === index) {
|
|
||||||
|
if (current.index === index) {
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
currentIndex++;
|
current.index++;
|
||||||
if (ex.executionList) {
|
if (ex.executionList) {
|
||||||
const found = this.findExecution(index, currentIndex, ex.executionList);
|
const found = this.findExecution(index, current, ex.executionList);
|
||||||
if (found) {
|
if (found) {
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
currentIndex += ex.executionList.length;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return currentIndex === index
|
return undefined;
|
||||||
? this.expandableList[this.expandableList.length - 1]
|
|
||||||
: undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#getParentNodes(level: number, index: number) {
|
#getParentNodes(level: number, index: number) {
|
||||||
|
|
Loading…
Reference in a new issue