Fixes parsing the list into sub-lists (#3815)
This commit is contained in:
parent
fb01fefe60
commit
03520dc30a
2 changed files with 50 additions and 14 deletions
|
@ -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,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue