From 77c3f9131b63b034d6aa9d8b5e59c3faff535137 Mon Sep 17 00:00:00 2001 From: fhanportainer <79428273+fhanportainer@users.noreply.github.com> Date: Wed, 7 Sep 2022 11:08:45 +1200 Subject: [PATCH] fix(environment): update page title when no environment selected. (#7606) * fix(environment): update page title when no environment selected. * fix(environment): update page title when clearing environment from side bar. * fix(environment): update page title when clearing environment from a non-environment page. --- app/app.js | 4 +--- app/portainer/services/authentication.js | 1 + app/portainer/services/types.ts | 1 + app/react/sidebar/EnvironmentSidebar.tsx | 12 ++++++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/app.js b/app/app.js index d856b09ea..5476a3734 100644 --- a/app/app.js +++ b/app/app.js @@ -10,9 +10,7 @@ export function onStartupAngular($rootScope, $state, $interval, LocalStorage, En $transitions.onEnter({}, () => { const endpoint = EndpointProvider.currentEndpoint(); - if (endpoint) { - document.title = `${defaultTitle} | ${endpoint.Name}`; - } + document.title = endpoint ? `${defaultTitle} | ${endpoint.Name}` : `${defaultTitle}`; }); // Workaround to prevent the loading bar from going backward diff --git a/app/portainer/services/authentication.js b/app/portainer/services/authentication.js index bf777be45..e4d9dde2a 100644 --- a/app/portainer/services/authentication.js +++ b/app/portainer/services/authentication.js @@ -50,6 +50,7 @@ angular.module('portainer.app').factory('Authentication', [ clearSessionStorage(); StateManager.clean(); EndpointProvider.clean(); + EndpointProvider.setCurrentEndpoint(null); LocalStorage.cleanAuthData(); LocalStorage.storeLoginStateUUID(''); tryAutoLoginExtension(); diff --git a/app/portainer/services/types.ts b/app/portainer/services/types.ts index c3c2e63d9..a4e17ef59 100644 --- a/app/portainer/services/types.ts +++ b/app/portainer/services/types.ts @@ -4,6 +4,7 @@ export interface EndpointProvider { setEndpointID(id: Environment['Id']): void; setEndpointPublicURL(url?: string): void; setOfflineModeFromStatus(status: Environment['Status']): void; + setCurrentEndpoint(endpoint: Environment | undefined): void; } export interface StateManager { diff --git a/app/react/sidebar/EnvironmentSidebar.tsx b/app/react/sidebar/EnvironmentSidebar.tsx index cf2f8b83c..6834bc01c 100644 --- a/app/react/sidebar/EnvironmentSidebar.tsx +++ b/app/react/sidebar/EnvironmentSidebar.tsx @@ -2,6 +2,7 @@ import { useCurrentStateAndParams, useRouter } from '@uirouter/react'; import { useEffect } from 'react'; import { X, Slash } from 'react-feather'; import clsx from 'clsx'; +import angular from 'angular'; import { PlatformType, @@ -11,6 +12,7 @@ import { import { getPlatformType } from '@/portainer/environments/utils'; import { useEnvironment } from '@/portainer/environments/queries/useEnvironment'; import { useLocalStorage } from '@/portainer/hooks/useLocalStorage'; +import { EndpointProvider } from '@/portainer/services/types'; import { getPlatformIcon } from '../portainer/environments/utils/get-platform-icon'; @@ -108,6 +110,16 @@ function useCurrentEnvironment() { return { query: useEnvironment(environmentId), clearEnvironment }; function clearEnvironment() { + const $injector = angular.element(document).injector(); + $injector.invoke( + /* @ngInject */ (EndpointProvider: EndpointProvider) => { + EndpointProvider.setCurrentEndpoint(undefined); + if (!params.endpointId) { + document.title = 'Portainer'; + } + } + ); + if (params.endpointId) { router.stateService.go('portainer.home'); }