From 284907c300aa05384e16a3ecbc2dd5bba817fd6f Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 3 Dec 2026 12:27:53 +0200 Subject: [PATCH] Fixed the docked AI panel not appearing after a user switch without a page reload (e.g. Login as from the system administrator): AI availability now follows the auth state, and the panel is mounted again when its host comes back --- .../src/app/modules/home/home.component.html | 2 +- ui-ngx/src/app/modules/home/home.component.ts | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ui-ngx/src/app/modules/home/home.component.html b/ui-ngx/src/app/modules/home/home.component.html index e4a2d3177a..c7626e2a10 100644 --- a/ui-ngx/src/app/modules/home/home.component.html +++ b/ui-ngx/src/app/modules/home/home.component.html @@ -118,7 +118,7 @@ - @if (aiAvailable) { + @if (aiAvailable()) { } diff --git a/ui-ngx/src/app/modules/home/home.component.ts b/ui-ngx/src/app/modules/home/home.component.ts index 0bee0037c9..8577aa4968 100644 --- a/ui-ngx/src/app/modules/home/home.component.ts +++ b/ui-ngx/src/app/modules/home/home.component.ts @@ -4,12 +4,13 @@ import { AfterViewInit, Component, computed, createNgModule, ElementRef, Inject, Injector, OnDestroy, OnInit, Renderer2, signal, ViewChild, ViewContainerRef, inject } from '@angular/core'; import { combineLatest, Observable, skip, startWith, Subject } from 'rxjs'; import { select, Store } from '@ngrx/store'; +import { toSignal } from '@angular/core/rxjs-interop'; import { debounceTime, distinctUntilChanged, map, share, take, takeUntil } from 'rxjs/operators'; import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout'; import { PageComponent } from '@shared/components/page.component'; import { AppState } from '@core/core.state'; -import { getCurrentAuthState, selectUserSettingsProperty } from '@core/auth/auth.selectors'; +import { getCurrentAuthState, selectAuth, selectUserSettingsProperty } from '@core/auth/auth.selectors'; import { MediaBreakpoints } from '@shared/models/constants'; import screenfull from 'screenfull'; import { MatSidenav } from '@angular/material/sidenav'; @@ -74,17 +75,27 @@ export class HomeComponent extends PageComponent implements AfterViewInit, OnIni private tourService = inject(TourService); - readonly aiAvailable = this.tourService.aiAvailable(); + readonly aiAvailable = toSignal(inject(Store).select(selectAuth).pipe( + map(() => this.tourService.aiAvailable()), + distinctUntilChanged() + ), {initialValue: this.tourService.aiAvailable()}); readonly aiPanelLoaded = signal(false); private injector = inject(Injector); - @ViewChild('aiPanelHost', {read: ViewContainerRef}) set aiPanelHost(host: ViewContainerRef) { - if (host && !this.aiPanelLoaded()) { + private panelHost: ViewContainerRef | undefined; + + @ViewChild('aiPanelHost', {read: ViewContainerRef}) set aiPanelHost(host: ViewContainerRef | undefined) { + this.panelHost = host; + if (!host) { + this.aiPanelLoaded.set(false); + return; + } + if (!this.aiPanelLoaded()) { Promise.all([import('@home/components/ai/ai.module'), import('@home/components/ai/ai-assistant-panel.component')]) .then(([{AiModule}, {AiAssistantPanelComponent}]) => { - if (!this.aiPanelLoaded()) { + if (this.panelHost === host && !this.aiPanelLoaded()) { host.createComponent(AiAssistantPanelComponent, {ngModuleRef: createNgModule(AiModule, this.injector)}); this.aiPanelLoaded.set(true); }