From aa1b0de2e916f19c632850fceb7eb907ec8661a9 Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Tue, 17 Nov 2026 14:55:18 +0100 Subject: [PATCH] Agents: fixed form layouts, back navigation and installing applications without templates (#16701) * Fixed Agent UI layout issues and app install type availability * Additional fixes * Fixed notes after merge with lts-4.4 * Additional fixes * Fix agent UI back navigation, layout and arguments state * Fixed PR comments * Agents: merge responses of a previous selection are ignored, back from agent tabs goes to the Agents list --------- Co-authored-by: Vladyslav_Prykhodko --- ui-ngx/angular.json | 5 + .../agent/wizard/_agent-wizard.scss | 5 +- .../agent-app-install-flow.component.html | 28 ++++-- .../agent-app-install-flow.component.ts | 94 ++++++++++++++++--- .../alarm-rules-table.component.scss | 7 -- .../alarm-rules-table.component.ts | 1 - .../calculated-fields-table.component.scss | 7 -- .../calculated-fields-table.component.ts | 1 - .../entity/entities-table.component.ts | 6 +- .../entity/entities-table-config.models.ts | 3 +- .../agent/agent-app-profile.component.html | 5 +- .../agent/agent-application.component.html | 2 +- ...gent-applications-table-config.resolver.ts | 4 +- .../agent/agent-events-page.component.ts | 4 +- .../pages/agent/agent-profile.component.html | 30 +++--- .../home/pages/agent/agent-routing.module.ts | 18 +++- .../home/pages/agent/agent.component.html | 2 +- .../agent-app-arguments.component.ts | 3 +- ...nt-application-details-page.component.scss | 3 +- .../agent-metrics-strip.component.html | 4 +- .../table/agent-app-event-table.component.ts | 2 +- .../table/agent-app-unit-table.component.ts | 2 +- .../pages/agent/util/agent-route-params.ts | 14 +++ .../agent-app-profile-wizard.component.html | 74 +++++++-------- .../agent-app-profile-wizard.component.scss | 9 -- .../agent-app-profile-wizard.component.ts | 39 ++++---- .../wizard/agent-app-wizard-loader.service.ts | 51 ++++++---- .../agent-profile-wizard.component.html | 12 +-- .../agent-profile-wizard.component.scss | 6 -- .../assets/locale/locale.constant-en_US.json | 2 + ui-ngx/src/styles.scss | 4 + 31 files changed, 281 insertions(+), 166 deletions(-) delete mode 100644 ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table.component.scss delete mode 100644 ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table.component.scss diff --git a/ui-ngx/angular.json b/ui-ngx/angular.json index 4228c68d80..283b19b337 100644 --- a/ui-ngx/angular.json +++ b/ui-ngx/angular.json @@ -72,6 +72,11 @@ "input": "./node_modules/ace-builds/src-noconflict/", "output": "/" }, + { + "glob": "worker-yaml.js", + "input": "./node_modules/ace-builds/src-noconflict/", + "output": "/" + }, { "glob": "worker-tbel.js", "input": "./src/app/shared/models/ace/tbel/", diff --git a/ui-ngx/src/app/modules/home/components/agent/wizard/_agent-wizard.scss b/ui-ngx/src/app/modules/home/components/agent/wizard/_agent-wizard.scss index 689721caf0..b1a57cfd06 100644 --- a/ui-ngx/src/app/modules/home/components/agent/wizard/_agent-wizard.scss +++ b/ui-ngx/src/app/modules/home/components/agent/wizard/_agent-wizard.scss @@ -165,7 +165,10 @@ transition: border-color 0.2s, background 0.2s; &:hover { border-color: var(--tb-primary-400); background: color-mix(in srgb, var(--tb-primary-500) 4%, transparent); } &.selected { border-color: var(--tb-primary-500); background: color-mix(in srgb, var(--tb-primary-500) 8%, transparent); } - &.locked-out, &:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; } + &.locked-out, &:disabled { + cursor: not-allowed; pointer-events: none; + mat-icon, h4 { opacity: 0.35; } + } mat-icon { font-size: 36px; width: 36px; height: 36px; color: var(--tb-primary-500); margin-bottom: 8px; } h4 { font-size: 16px; font-weight: 500; margin: 0 0 4px; } p { font-size: 13px; color: $agent-text-secondary; margin: 0; } diff --git a/ui-ngx/src/app/modules/home/components/agent/wizard/agent-app-install-flow.component.html b/ui-ngx/src/app/modules/home/components/agent/wizard/agent-app-install-flow.component.html index 8714ed94dc..a99468da7f 100644 --- a/ui-ngx/src/app/modules/home/components/agent/wizard/agent-app-install-flow.component.html +++ b/ui-ngx/src/app/modules/home/components/agent/wizard/agent-app-install-flow.component.html @@ -12,9 +12,7 @@ }
-

{{ 'agent.app-install-title' | translate }}@if (agent) { - : - }

+

{{ 'agent.app-install-title' | translate }}@if (agent) {:}

@if (agent) { {{ 'agent.app-install-on-agent' | translate: { name: agent?.name } }} @@ -90,11 +88,12 @@ @for (card of typeCards; track card.type) { }
@@ -146,6 +145,12 @@ (relatedEntityNameChange)="onRelatedEntityName($event)"> } + @if (useProfile && typesWithoutTemplates.has(selectedType)) { +
+ warning_amber + agent.app-no-templates +
+ } @if (useProfile) { agent.app-install-select-profile @@ -160,7 +165,7 @@ close } - @if (!profileSelectFormGroup.get('profile').value && canCreateAppProfile) { + @if (!profileSelectFormGroup.get('profile').value && canCreateProfileForType) { -
+
- @@ -57,6 +57,12 @@ agent.app-install-loading-template
} + @if (selectedType && !loadingTemplates && !loadError && !availableTemplates.length) { +
+ warning_amber + agent.app-no-templates +
+ } @if (loadError) {
error_outline @@ -64,13 +70,6 @@
}
- } @@ -90,7 +89,7 @@ agent.app-profile-description - + @@ -127,22 +126,6 @@

agent.app-install-diff-hint

- - @@ -182,22 +165,33 @@ agent.app-profile-wizard-confirm-info - - + + diff --git a/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-profile-wizard.component.scss b/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-profile-wizard.component.scss index e7dc207e67..06ddb621d2 100644 --- a/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-profile-wizard.component.scss +++ b/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-profile-wizard.component.scss @@ -9,15 +9,10 @@ @include wizard-summary; :host { - .tb-install-wizard-body { - min-height: 50vh; - } - .step-content { display: flex; flex-direction: column; gap: 16px; - min-height: calc(50vh - 140px); .hint, .type-cards { @@ -31,10 +26,6 @@ justify-content: center; gap: 16px; } - - .step-footer { - margin-top: auto; - } } .summary-section { diff --git a/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-profile-wizard.component.ts b/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-profile-wizard.component.ts index 573f5d0250..200428b83c 100644 --- a/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-profile-wizard.component.ts +++ b/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-profile-wizard.component.ts @@ -13,7 +13,7 @@ import { AgentService } from '@core/http/agent.service'; import { StepperOrientation } from '@angular/material/stepper'; import { BreakpointObserver } from '@angular/cdk/layout'; import { MediaBreakpoints } from '@shared/models/constants'; -import { Observable } from 'rxjs'; +import { Observable, Subscription } from 'rxjs'; import { map } from 'rxjs/operators'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; import { @@ -32,6 +32,7 @@ import { } from '@home/pages/agent/util/agent-compose-yaml'; import { orderTemplatesNewestFirst } from '@home/pages/agent/util/template-version-order'; import { EdgeTemplateCompatibilityService } from '@home/pages/agent/util/edge-template-compatibility.service'; +import { AgentAppWizardLoaderService } from '@home/pages/agent/wizard/agent-app-wizard-loader.service'; export interface AgentAppProfileWizardData { profile?: AgentAppProfile; @@ -50,6 +51,7 @@ interface TypeCard { selector: 'tb-agent-app-profile-wizard', templateUrl: './agent-app-profile-wizard.component.html', styleUrls: ['./agent-app-profile-wizard.component.scss'], + providers: [AgentAppWizardLoaderService], standalone: false }) export class AgentAppProfileWizardComponent @@ -78,7 +80,8 @@ export class AgentAppProfileWizardComponent availableTemplates: AgentAppTemplate[] = []; selectedTemplateVersion: string | null = null; loadingTemplates = false; - private templatesByTypeCache = new Map(); + private templatesSubscription: Subscription | null = null; + private previewSubscription: Subscription | null = null; profileForm: UntypedFormGroup; composeYaml = ''; @@ -109,6 +112,7 @@ export class AgentAppProfileWizardComponent protected router: Router, protected translate: TranslateService, private agentService: AgentService, + private loader: AgentAppWizardLoaderService, private breakpointObserver: BreakpointObserver, private edgeTemplateCompatibility: EdgeTemplateCompatibilityService, private fb: UntypedFormBuilder, @@ -126,12 +130,9 @@ export class AgentAppProfileWizardComponent } ngOnInit() { - // Prefetch templates for all types so type selection is instant. - this.typeCards.forEach(card => { - this.agentService.getAgentAppTemplatesByAppType(card.type).subscribe({ - next: templates => this.templatesByTypeCache.set(card.type, templates), - error: () => {} - }); + const prefetchTypes = this.lockedAppType ? [this.lockedAppType] : this.typeCards.map(card => card.type); + prefetchTypes.forEach(type => { + this.loader.loadTemplatesByType(type).subscribe({ error: () => {} }); }); if (this.editMode) { this.initForEdit(this.data.profile); @@ -191,6 +192,8 @@ export class AgentAppProfileWizardComponent return; } this.selectedType = type; + this.previewSubscription?.unsubscribe(); + this.previewSubscription = null; this.template = null; this.composeType = null; this.composeTypeKeys = []; @@ -200,17 +203,13 @@ export class AgentAppProfileWizardComponent this.loadTemplatesForType(type); } + // A finished request replays synchronously, so a prefetched type shows no loading state. + // Drops the previous type's request, so its late response cannot apply its template to the newly selected type. private loadTemplatesForType(type: AgentApplicationType) { - const cached = this.templatesByTypeCache.get(type); - if (cached) { - this.availableTemplates = orderTemplatesNewestFirst(this.supportedTemplates(cached)); - this.selectLatestTemplate(); - return; - } + this.templatesSubscription?.unsubscribe(); this.loadingTemplates = true; - this.agentService.getAgentAppTemplatesByAppType(type).subscribe({ + this.templatesSubscription = this.loader.loadTemplatesByType(type).subscribe({ next: templates => { - this.templatesByTypeCache.set(type, templates); this.availableTemplates = orderTemplatesNewestFirst(this.supportedTemplates(templates)); this.loadingTemplates = false; this.selectLatestTemplate(); @@ -275,10 +274,13 @@ export class AgentAppProfileWizardComponent } private rebuildComposePreview() { + this.previewSubscription?.unsubscribe(); + this.previewSubscription = null; const tpl = this.template; if (!tpl) { return; } + const composeType = this.composeType; this.proposedYaml = dumpRawTemplateCompose(tpl, this.composeType); this.currentYaml = this.proposedYaml; this.composeYaml = this.currentYaml; @@ -287,8 +289,11 @@ export class AgentAppProfileWizardComponent appType: this.selectedType, templateVersion: tpl.currentVersion }; - this.agentService.mergeProfileForPreview(tpl.currentVersion, draft, this.composeType || undefined, undefined, !this.editMode).subscribe({ + this.previewSubscription = this.agentService.mergeProfileForPreview(tpl.currentVersion, draft, composeType || undefined, undefined, !this.editMode).subscribe({ next: merged => { + if (this.template !== tpl || this.composeType !== composeType) { + return; + } const compose: any = dockerComposeConfig(merged)?.compose; if (compose) { this.currentYaml = dumpYaml(compose, 0).trimEnd() + '\n'; diff --git a/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-wizard-loader.service.ts b/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-wizard-loader.service.ts index b27bb9ef40..6ca7c76af7 100644 --- a/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-wizard-loader.service.ts +++ b/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-app-wizard-loader.service.ts @@ -1,8 +1,9 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 -import { Injectable } from '@angular/core'; +import { DestroyRef, Injectable } from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { Observable, of, throwError } from 'rxjs'; -import { map, mergeMap, tap } from 'rxjs/operators'; +import { filter, map, mergeMap, shareReplay, tap } from 'rxjs/operators'; import { AgentService } from '@core/http/agent.service'; import { EntityId } from '@shared/models/id/entity-id'; import { @@ -40,19 +41,26 @@ export class AgentAppWizardLoaderService { private templateCache = new Map(); private templateByVersionCache = new Map(); - private templatesByTypeCache = new Map(); - private profilesCache = new Map(); + private templatesByTypeCache = new Map>(); + private profilesCache = new Map>(); constructor(private agentService: AgentService) {} // Warm the per-type template cache so the first type-card click in install - // mode doesn't flash a "Loading template…" state. - prewarmTemplates(types: AgentApplicationType[]): void { + // mode doesn't flash a "Loading template…" state. Background-only: a failed `latest` + // request is silent (the shared per-type list request may still toast), and the + // requests are cancelled when `destroyRef` is destroyed. + prewarmTemplates(types: AgentApplicationType[], destroyRef: DestroyRef): void { types.forEach(type => { if (this.templateCache.has(type)) { return; } - this.agentService.getLatestAgentAppTemplate(type, AgentAppConfigType.DOCKER_COMPOSE).subscribe({ + this.loadTemplatesByType(type).pipe( + filter(templates => templates.length > 0), + mergeMap(() => this.agentService.getLatestAgentAppTemplate(type, AgentAppConfigType.DOCKER_COMPOSE, + { ignoreErrors: true, ignoreLoading: true })), + takeUntilDestroyed(destroyRef) + ).subscribe({ next: tpl => this.templateCache.set(type, tpl), error: () => { /* swallow — loadTemplate retries on demand */ } }); @@ -81,14 +89,16 @@ export class AgentAppWizardLoaderService { ); } + // Caches the request itself, so concurrent callers share one in-flight call; + // shareReplay drops a failed request, so the next caller retries, and cancels it + // once every caller has unsubscribed (e.g. the wizard was closed). loadTemplatesByType(type: AgentApplicationType): Observable { - const cached = this.templatesByTypeCache.get(type); - if (cached) { - return of(cached); + let templates$ = this.templatesByTypeCache.get(type); + if (!templates$) { + templates$ = this.agentService.getAgentAppTemplatesByAppType(type).pipe(shareReplay({ bufferSize: 1, refCount: true })); + this.templatesByTypeCache.set(type, templates$); } - return this.agentService.getAgentAppTemplatesByAppType(type).pipe( - tap(templates => this.templatesByTypeCache.set(type, templates)) - ); + return templates$; } materializeProfile(profile: VirtualAgentAppProfile): Observable { @@ -96,17 +106,18 @@ export class AgentAppWizardLoaderService { } loadProfiles(type: AgentApplicationType): Observable { - const cached = this.profilesCache.get(type); - if (cached) { - return of(cached); + let profiles$ = this.profilesCache.get(type); + if (!profiles$) { + profiles$ = (this.agentService.getAgentAppProfilesByAppType(type) as Observable).pipe( + shareReplay({ bufferSize: 1, refCount: true }) + ); + this.profilesCache.set(type, profiles$); } - return this.agentService.getAgentAppProfilesByAppType(type).pipe( - tap(profiles => this.profilesCache.set(type, profiles)) - ) as Observable; + return profiles$; } cacheProfiles(type: AgentApplicationType, profiles: AgentAppProfile[]): void { - this.profilesCache.set(type, profiles); + this.profilesCache.set(type, of(profiles)); } // Reads the linked profile via the info-by-id endpoint, which is gated by diff --git a/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-profile-wizard.component.html b/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-profile-wizard.component.html index d92595695a..d1b739159f 100644 --- a/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-profile-wizard.component.html +++ b/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-profile-wizard.component.html @@ -16,9 +16,9 @@ } -
+
- +
@@ -32,10 +32,6 @@ } - - agent.description - - agent.provisioning-strategy @@ -59,6 +55,10 @@
+ + agent.description + + diff --git a/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-profile-wizard.component.scss b/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-profile-wizard.component.scss index d5d1388fe3..46d93884bc 100644 --- a/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-profile-wizard.component.scss +++ b/ui-ngx/src/app/modules/home/pages/agent/wizard/agent-profile-wizard.component.scss @@ -10,13 +10,7 @@ min-width: 0; max-width: 95vw; - .tb-install-wizard-body { - min-height: 50vh; - } - .tb-install-wizard-body.tb-install-wizard-embedded { - display: flex; - flex-direction: column; padding: 16px 24px 0 !important; mat-stepper { diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 271a3f9058..0dc1e6cd65 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3758,6 +3758,8 @@ "copy-profile-id": "Copy Profile Id", "profile-id-copied-message": "Profile Id has been copied to clipboard", "app-profile-wizard-title": "Create Application Profile", + "app-no-templates": "No templates available for this application type.", + "app-type-unavailable": "No templates or application profiles available", "app-profile-wizard-edit-title": "Update Application Profile", "app-update-current-config": "Current application configuration", "app-update-future-config": "Future application configuration", diff --git a/ui-ngx/src/styles.scss b/ui-ngx/src/styles.scss index 3d1e3a1165..425c7ee10b 100644 --- a/ui-ngx/src/styles.scss +++ b/ui-ngx/src/styles.scss @@ -258,6 +258,10 @@ pre.tb-highlight { } } +tb-entities-table.white-background { + --mat-sidenav-content-background-color: white; +} + .ace_editor { font-size: 16px !important; letter-spacing: normal;