From 356e73b9e874677cfd044109fb13564e975705a0 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 3 Dec 2026 12:39:46 +0200 Subject: [PATCH] Fixed the AI Assistant button missing from the header after Login as from the system administrator until another page was opened: AI availability is one signal in UserPermissionsService that follows the auth state, read by the header button, the docked panel host and the tour --- .../app/core/http/user-permissions.service.ts | 12 +++++++++--- ui-ngx/src/app/core/services/tour.service.ts | 2 +- .../ai/ai-assistant-button.component.ts | 17 ++++++++++------- ui-ngx/src/app/modules/home/home.component.ts | 9 +++------ 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/ui-ngx/src/app/core/http/user-permissions.service.ts b/ui-ngx/src/app/core/http/user-permissions.service.ts index d31ddfe2b4..6504cbf561 100644 --- a/ui-ngx/src/app/core/http/user-permissions.service.ts +++ b/ui-ngx/src/app/core/http/user-permissions.service.ts @@ -1,9 +1,10 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 -import { Injectable } from '@angular/core'; +import { inject, Injectable } from '@angular/core'; +import { toSignal } from '@angular/core/rxjs-interop'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; -import { tap } from 'rxjs/operators'; +import { distinctUntilChanged, map, tap } from 'rxjs/operators'; import { AllowedPermissionsInfo, groupResourceByGroupType, @@ -19,7 +20,7 @@ import { isArray } from '@core/utils'; import { defaultHttpOptionsFromConfig, RequestConfig } from '@core/http/http-utils'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; -import { getCurrentAuthState } from '@core/auth/auth.selectors'; +import { getCurrentAuthState, selectAuth } from '@core/auth/auth.selectors'; import { Authority } from '@shared/models/authority.enum'; @Injectable({ @@ -35,6 +36,11 @@ export class UserPermissionsService { private userPermissions: MergedUserPermissions; private userOwnerId: EntityId; + readonly aiAvailable = toSignal(inject(Store).select(selectAuth).pipe( + map(() => this.isAiAvailable()), + distinctUntilChanged() + ), {initialValue: false}); + constructor( private http: HttpClient, private store: Store diff --git a/ui-ngx/src/app/core/services/tour.service.ts b/ui-ngx/src/app/core/services/tour.service.ts index 5e6b27768a..5d59332a92 100644 --- a/ui-ngx/src/app/core/services/tour.service.ts +++ b/ui-ngx/src/app/core/services/tour.service.ts @@ -32,7 +32,7 @@ export class TourService { private offered = false; aiAvailable(): boolean { - return this.userPermissions.isAiAvailable(); + return this.userPermissions.aiAvailable(); } offerWelcome(): void { diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-assistant-button.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-assistant-button.component.ts index 7376bd7717..0b2439f73e 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-assistant-button.component.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-assistant-button.component.ts @@ -41,7 +41,7 @@ const intro: { owner: AiAssistantButtonComponent | null } = {owner: null}; @Component({ selector: 'tb-ai-assistant-button', template: ` - @if (available && !panelService.open() && !panelService.suppressed()) { + @if (available() && !panelService.open() && !panelService.suppressed()) { @let status = cue();