From 45c2874cf4be232a19262ad1626f8bd1df52f6a1 Mon Sep 17 00:00:00 2001 From: rhenck <richard.henck@iqb.hu-berlin.de> Date: Wed, 1 Jun 2022 20:50:17 +0200 Subject: [PATCH] Fix element ID initialization There were some cases where elements could end up without an ID. Also just in case an error is thrown when no ID is present. --- projects/common/models/elements/element.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/projects/common/models/elements/element.ts b/projects/common/models/elements/element.ts index b1e406035..f33d0b191 100644 --- a/projects/common/models/elements/element.ts +++ b/projects/common/models/elements/element.ts @@ -28,7 +28,6 @@ export abstract class UIElement { constructor(element: Partial<UIElement>, ...args: unknown[]) { if (!element.type) throw Error('Element has no type!'); this.type = element.type; - if (element.id) this.id = element.id; // IDManager is an optional parameter. When given, check/repair and register the ID. if (args[0]) { @@ -37,9 +36,14 @@ export abstract class UIElement { this.id = idManager.getNewID(element.type as string); } else if (!IDManager.getInstance().isIdAvailable(element.id)) { this.id = idManager.getNewID(element.type as string); + } else { + this.id = element.id; } idManager.addID(this.id); - this.height = 1000; + } else if (element.id) { + this.id = element.id; + } else { + throw Error('No ID for element!'); } if (element.width) this.width = element.width; -- GitLab