From 0777a0edbd2c6f7328ea6d834ef1e6fba32eb383 Mon Sep 17 00:00:00 2001 From: dpinkevych Date: Mon, 26 Oct 2026 09:20:33 +0200 Subject: [PATCH] refactor(iot-hub): precompute the hint box per form row The renderer looked a field's row up in a map (rowOf) from the template, and called hasHintBox() / isInHintBoxRow() for every field on each change detection. FormRow now carries hasHintBox, computed in ngOnChanges when the fields or reviewMode change, and fieldTemplate gets the row in its context. The subscriptSizing binding and the mat-hint checks read the flag; the map and both methods are gone. hasFieldError() stays a call, since it depends on the control state. The group doc comment in FormFieldDefinition now describes the panel: consecutive fields with the same group share one. --- .../install-form-renderer.component.html | 24 +++++++-------- .../install-form-renderer.component.ts | 30 +++++++------------ .../models/iot-hub/device-package.models.ts | 2 +- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/install-form-renderer/install-form-renderer.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/install-form-renderer/install-form-renderer.component.html index 31077fa614..2f05caf518 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/install-form-renderer/install-form-renderer.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/install-form-renderer/install-form-renderer.component.html @@ -25,16 +25,16 @@ @for (field of row.fields; track field.key) {
- +
} } @else { - + } @for (field of row.fields; track field.key) { - @if (hasHintBox(field)) { + @if (row.hasHintBox && field.helpPopupId) {
{{ field.helpText }}
- + @switch (field.type) { @case (FormFieldType.BOOLEAN) { {{ field.label }} } @case (FormFieldType.SELECT) { - + {{ field.label }} @for (opt of field.options; track opt.value) { {{ opt.label }} } - @if (field.helpText && !hasHintBox(field)) { + @if (field.helpText && !(row.hasHintBox && field.helpPopupId)) { {{ field.helpText }} } @if (formGroup.controls[field.key]?.hasError('required')) { @@ -74,7 +74,7 @@ } @case (FormFieldType.PASSWORD) { - + {{ field.label }} autorenew } - @if (field.helpText && !hasHintBox(field)) { + @if (field.helpText && !(row.hasHintBox && field.helpPopupId)) { {{ field.helpText }} } @if (formGroup.controls[field.key]?.hasError('required')) { @@ -106,11 +106,11 @@ } @case (FormFieldType.INTEGER) { - + {{ field.label }} - @if (field.helpText && !hasHintBox(field)) { + @if (field.helpText && !(row.hasHintBox && field.helpPopupId)) { {{ field.helpText }} } @if (formGroup.controls[field.key]?.hasError('required')) { @@ -125,7 +125,7 @@ } @default { - + {{ field.label }} @@ -137,7 +137,7 @@ autorenew } - @if (field.helpText && !hasHintBox(field)) { + @if (field.helpText && !(row.hasHintBox && field.helpPopupId)) { {{ field.helpText }} } @if (formGroup.controls[field.key]?.hasError('required')) { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/install-form-renderer/install-form-renderer.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/install-form-renderer/install-form-renderer.component.ts index 47b921fcc6..db2382e5c0 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/install-form-renderer/install-form-renderer.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/install-form-renderer/install-form-renderer.component.ts @@ -7,9 +7,14 @@ import { generateSecret } from '@core/utils'; const DEFAULT_RANDOM_SIZE = 20; -/** Fields shown on one line. */ +/** + * Fields shown on one line. When one of them has a help popup (outside review mode), the row shows + * the field's hint in a box under it, next to the popup trigger, and its fields don't reserve space + * for a hint or an error, so the box sits right under them. + */ interface FormRow { fields: FormFieldDefinition[]; + hasHintBox: boolean; } /** Consecutive rows of one group, shown in a panel with the group as its title; no title for ungrouped fields. */ @@ -45,14 +50,13 @@ export class InstallFormRendererComponent implements OnChanges { // Fields in render order: consecutive fields of a group form a section, and consecutive fields // with the same `row` share one line sections: FormSection[] = []; - private rowOf = new Map(); readonly FormFieldType = FormFieldType; ngOnChanges(changes: SimpleChanges): void { - if (changes.fields) { + // The hint boxes depend on reviewMode too + if (changes.fields || changes.reviewMode) { this.sections = []; - this.rowOf.clear(); let previous: FormFieldDefinition | undefined; for (const field of this.fields ?? []) { if (!previous || field.group !== previous.group) { @@ -60,12 +64,13 @@ export class InstallFormRendererComponent implements OnChanges { } const rows = this.sections[this.sections.length - 1].rows; const last = rows[rows.length - 1]; + const hasHintBox = !!field.helpPopupId && !this.reviewMode; if (field.row && last?.fields[0].row === field.row) { last.fields.push(field); + last.hasHintBox ||= hasHintBox; } else { - rows.push({ fields: [field] }); + rows.push({ fields: [field], hasHintBox }); } - this.rowOf.set(field.key, rows[rows.length - 1]); previous = field; } } @@ -96,19 +101,6 @@ export class InstallFormRendererComponent implements OnChanges { return field.validators?.[0]?.message || 'Invalid format'; } - /** Fields with a help popup show their hint in a box under the row, with the popup trigger. */ - hasHintBox(field: FormFieldDefinition): boolean { - return !!field.helpPopupId && !this.reviewMode; - } - - /** - * True for the fields of a row that has a hint box. They don't reserve space for a hint or an - * error, so the box sits right under them. - */ - isInHintBoxRow(field: FormFieldDefinition): boolean { - return !!this.rowOf.get(field.key)?.fields.some(f => this.hasHintBox(f)); - } - /** True when the field fails a validator other than required and pattern (one the dialog added). */ hasFieldError(field: FormFieldDefinition): boolean { const errors = this.formGroup.controls[field.key]?.errors; diff --git a/ui-ngx/src/app/shared/models/iot-hub/device-package.models.ts b/ui-ngx/src/app/shared/models/iot-hub/device-package.models.ts index 66ece9c418..73c0365d52 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/device-package.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/device-package.models.ts @@ -289,7 +289,7 @@ export interface FormFieldDefinition { randomGenerator?: boolean; randomSize?: number; randomByDefault?: boolean; - // Fields with the same group get one header above the first of them + // Consecutive fields with the same group are shown in one panel titled with the group group?: string; // Set by the install dialog for the fields it adds, not by packages. readOnly?: boolean;