Browse Source

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

pull/16833/head
Igor Kulikov 2 weeks ago
parent
commit
6159bdcd2e
  1. 16
      ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts
  2. 18
      ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol.component.ts

16
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) {

18
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<AppState>,
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']);
}
}
});
}

Loading…
Cancel
Save