fixed change calculation (#28342)

fixes: #28187

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2024-04-02 14:03:47 +02:00 committed by GitHub
parent c5bf161cfb
commit c86620963d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -98,17 +98,15 @@ export class ExecutionList {
return found;
}
#getParentNodes(level?: number) {
for (let index = 0; index < this.#list.length; index++) {
const ex = this.#list[index];
if (
index + 1 < this.#list.length &&
this.#list[index + 1].level! > ex.level! &&
ex.level! + 1 === level
) {
return ex;
#getParentNodes(level: number, index: number) {
let parent = undefined;
for (let i = 0; i < index; i++) {
const ex = this.#list[i];
if (level - 1 === ex.level) {
parent = ex;
}
}
return parent;
}
getChange(
@ -117,13 +115,14 @@ export class ExecutionList {
) {
const currentOrder = this.order();
const newLocIndex = order.findIndex((id) => id === changed.id);
const oldLocation =
currentOrder[currentOrder.findIndex((ex) => ex.id === changed.id)];
const oldLocIndex = currentOrder.findIndex((ex) => ex.id === changed.id);
const oldLocation = currentOrder[oldLocIndex];
const newLocation = currentOrder[newLocIndex];
if (newLocation.level !== oldLocation.level) {
const currentParent = this.#getParentNodes(oldLocation.level!, oldLocIndex);
const parent = this.#getParentNodes(newLocation.level!, newLocIndex);
if (currentParent?.id !== parent?.id) {
if (newLocation.level! > 0) {
const parent = this.#getParentNodes(newLocation.level);
return new LevelChange(
parent?.executionList?.length || 0,
newLocation.index!,