From 9c1ac201ecd34378f913c896d9803b77b0aba6e4 Mon Sep 17 00:00:00 2001 From: Loki Elble <69210919+Elblinator@users.noreply.github.com> Date: Wed, 2 Dec 2026 15:54:39 +0100 Subject: [PATCH] Fix double entries in consultation sequence (#6756) --- .../motion-meta-data.component.ts | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/client/src/app/site/pages/meetings/pages/motions/pages/motion-detail/pages/motion-view/components/motion-meta-data/motion-meta-data.component.ts b/client/src/app/site/pages/meetings/pages/motions/pages/motion-detail/pages/motion-view/components/motion-meta-data/motion-meta-data.component.ts index 6835f6db06..3a0f76d1fc 100644 --- a/client/src/app/site/pages/meetings/pages/motions/pages/motion-detail/pages/motion-view/components/motion-meta-data/motion-meta-data.component.ts +++ b/client/src/app/site/pages/meetings/pages/motions/pages/motion-detail/pages/motion-view/components/motion-meta-data/motion-meta-data.component.ts @@ -448,16 +448,24 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl } private createForwardTree(list: ViewMotion[], origins: ViewMotion[]): ViewMotion[][] { - const childrenIds = new Set(list.filter(motion => !!motion.origin_id).map(motion => motion.origin_id)); - const leaves = list.filter(motion => !childrenIds.has(motion.id)); + const cleanList = this.returnBasedOnId(list); + const cleanOrigin = this.returnBasedOnId(origins); + + const childrenIds = new Set(cleanList.filter(motion => !!motion.origin_id).map(motion => motion.origin_id)); + const leaves = cleanList.filter(motion => !childrenIds.has(motion.id)); + + const listIds = new Set(cleanList.map(motion => motion.id)); + const appendableOrigins = cleanOrigin.filter(origin => !listIds.has(origin.id)).reverse(); const tree: ViewMotion[][] = []; if (leaves.length > 0) { for (const leaf of leaves) { const branch: ViewMotion[] = []; let currentId: number | null = leaf.id; + const visited = new Set(); - while (currentId !== null) { + while (currentId !== null && !visited.has(currentId)) { + visited.add(currentId); const motion = list.find(m => m.id === currentId); if (!motion) break; @@ -465,12 +473,26 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl currentId = motion.origin_id; } - branch.push(...[...origins].reverse()); + branch.push(...appendableOrigins); tree.push(branch); } } else { - tree.push(origins); + tree.push(cleanOrigin); } return tree; } + + /** + * returns Set of motions based on motion.id + */ + private returnBasedOnId(motions: ViewMotion[]): ViewMotion[] { + const seen = new Set(); + return motions.filter(motion => { + if (seen.has(motion.id)) { + return false; + } + seen.add(motion.id); + return true; + }); + } }