From 6159bdcd2e03eeb2861ddfcb2a56b09099ae0251 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Wed, 18 Nov 2026 19:24:06 +0200 Subject: [PATCH] feat: when the AI chat deletes the SCADA symbol open in the editor, the page returns to the SCADA symbols list with the chat; the editor also leaves a symbol that no longer exists --- .../home/components/ai/ai-chat.component.ts | 16 ++++++++++++++++ .../scada-symbol/scada-symbol.component.ts | 18 +++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts index 7e1432010e..1227fa595c 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts @@ -1006,6 +1006,7 @@ export class AiChatComponent implements OnInit, OnDestroy { this.openCreatedDashboard(call.data.tool, event.data.affectedEntities); this.openCreatedWidget(call.data.tool, event.data.affectedEntities); this.openCreatedScadaSymbol(call.data.tool, call.data.arguments, event.data.result); + this.leaveDeletedScadaSymbol(call.data.tool, call.data.arguments); } } if (event.data.affectedEntities?.length) { @@ -1179,6 +1180,21 @@ export class AiChatComponent implements OnInit, OnDestroy { this.router.navigate(['/resources/scada-symbols', ...path.split('/')]); } + private leaveDeletedScadaSymbol(tool: string | undefined, args: unknown): void { + const chatId = this.chatId(); + const values = (aiParse(args) ?? {}) as {targetType?: string; targetId?: string}; + const shown = /^\/resources\/scada-symbols\/tenant\/([^/?#]+)/.exec(this.router.url || '')?.[1]; + if (tool !== 'delete' || values.targetType !== 'IMAGE' || !chatId || !shown) { + return; + } + const deleted = (values.targetId ?? '').trim().replace(/^tb-image;/, '').split('/').pop(); + if (deleted !== decodeURIComponent(shown)) { + return; + } + this.panelService.carryChat(chatId); + this.router.navigate(['/resources/scada-symbols']); + } + private emitDashboards(entities: EntityId[]): void { const edited = entities.filter(entity => LIVE_EDITED_TYPES.has(entity.entityType as EntityType)); if (edited.length) { diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol.component.ts b/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol.component.ts index 1b0e0392b6..3fcb2990cb 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol.component.ts +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol.component.ts @@ -14,7 +14,7 @@ import { import { PageComponent } from '@shared/components/page.component'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { buffer, debounceTime, map, switchMap, takeUntil } from 'rxjs/operators'; import { Subject } from 'rxjs'; import { ScadaSymbolData, ScadaSymbolEditObjectCallbacks } from '@home/pages/scada-symbol/scada-symbol-editor.models'; @@ -154,6 +154,7 @@ export class ScadaSymbolComponent extends PageComponent constructor(protected store: Store, private route: ActivatedRoute, + private router: Router, private fb: UntypedFormBuilder, private cd: ChangeDetectorRef, private entityService: EntityService, @@ -256,10 +257,17 @@ export class ScadaSymbolComponent extends PageComponent `${IMAGES_URL_PREFIX}/${type}/${encodeURIComponent(imageInfo.resourceKey)}`).pipe( map(content => ({imageResource: imageInfo, scadaSymbolContent: content})) )) - ).subscribe(data => { - this.previewMode = false; - this.init(data); - this.updateBreadcrumbs.emit(); + ).subscribe({ + next: data => { + this.previewMode = false; + this.init(data); + this.updateBreadcrumbs.emit(); + }, + error: err => { + if (err?.status === 404) { + this.router.navigate(['/resources/scada-symbols']); + } + } }); }