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(
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue