Skip already processed lines (#2568)
This commit is contained in:
parent
1c23a0f1a7
commit
c2df6e7dfb
2 changed files with 61 additions and 19 deletions
|
@ -147,4 +147,44 @@ describe("ExecutionList", () => {
|
||||||
expect(diff).toBeInstanceOf(LevelChange);
|
expect(diff).toBeInstanceOf(LevelChange);
|
||||||
expect((diff as LevelChange).parent).toBeUndefined();
|
expect((diff as LevelChange).parent).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Construct list", () => {
|
||||||
|
//given
|
||||||
|
const list = [
|
||||||
|
{ id: "0", level: 0, index: 0 },
|
||||||
|
{ id: "1", level: 1, index: 0 },
|
||||||
|
{ id: "2", level: 0, index: 1 },
|
||||||
|
{ id: "3", level: 1, index: 0 },
|
||||||
|
{ id: "4", level: 0, index: 2 },
|
||||||
|
{ id: "5", level: 1, index: 0 },
|
||||||
|
];
|
||||||
|
|
||||||
|
//when
|
||||||
|
const result = new ExecutionList(list);
|
||||||
|
|
||||||
|
//then
|
||||||
|
expect(result.expandableList).toEqual([
|
||||||
|
{
|
||||||
|
executionList: [{ id: "1", index: 0, level: 1 }],
|
||||||
|
id: "0",
|
||||||
|
index: 0,
|
||||||
|
isCollapsed: false,
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
executionList: [{ id: "3", index: 0, level: 1 }],
|
||||||
|
id: "2",
|
||||||
|
index: 1,
|
||||||
|
isCollapsed: false,
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
executionList: [{ id: "5", index: 0, level: 1 }],
|
||||||
|
id: "4",
|
||||||
|
index: 2,
|
||||||
|
isCollapsed: false,
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,38 +34,40 @@ export class ExecutionList {
|
||||||
|
|
||||||
constructor(list: AuthenticationExecutionInfoRepresentation[]) {
|
constructor(list: AuthenticationExecutionInfoRepresentation[]) {
|
||||||
this.list = list as ExpandableExecution[];
|
this.list = list as ExpandableExecution[];
|
||||||
this.expandableList =
|
|
||||||
this.transformToExpandableList(0, 0, {
|
const exList = {
|
||||||
executionList: [],
|
executionList: [],
|
||||||
isCollapsed: false,
|
isCollapsed: false,
|
||||||
}).executionList || [];
|
};
|
||||||
|
this.transformToExpandableList(0, exList);
|
||||||
|
this.expandableList = exList.executionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private transformToExpandableList(
|
private transformToExpandableList(
|
||||||
level: number,
|
|
||||||
currIndex: number,
|
currIndex: number,
|
||||||
execution: ExpandableExecution
|
execution: ExpandableExecution
|
||||||
) {
|
) {
|
||||||
for (let index = currIndex; index < this.list.length; index++) {
|
for (let index = currIndex; index < this.list.length; index++) {
|
||||||
const ex = this.list[index];
|
const ex = this.list[index];
|
||||||
|
const level = ex.level || 0;
|
||||||
const nextRowLevel = this.list[index + 1]?.level || 0;
|
const nextRowLevel = this.list[index + 1]?.level || 0;
|
||||||
|
const isLeaf = level > nextRowLevel;
|
||||||
|
const hasChild = level < nextRowLevel;
|
||||||
|
|
||||||
if (ex.level === level && nextRowLevel <= level) {
|
if (isLeaf) {
|
||||||
execution.executionList?.push(ex);
|
execution.executionList?.push(ex);
|
||||||
} else if (ex.level === level && nextRowLevel > level) {
|
return index;
|
||||||
const expandable = this.transformToExpandableList(
|
}
|
||||||
nextRowLevel,
|
|
||||||
index + 1,
|
if (ex.level === level && !hasChild) {
|
||||||
{
|
execution.executionList?.push(ex);
|
||||||
...ex,
|
} else {
|
||||||
executionList: [],
|
const subLevel = { ...ex, executionList: [], isCollapsed: false };
|
||||||
isCollapsed: false,
|
index = this.transformToExpandableList(index + 1, subLevel);
|
||||||
}
|
execution.executionList?.push(subLevel);
|
||||||
);
|
|
||||||
execution.executionList?.push(expandable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return execution;
|
return this.list.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
order(list?: ExpandableExecution[]) {
|
order(list?: ExpandableExecution[]) {
|
||||||
|
|
Loading…
Reference in a new issue