diff --git a/app/portainer/services/stateManager.js b/app/portainer/services/stateManager.js index 5930e82c9..8cb44ae64 100644 --- a/app/portainer/services/stateManager.js +++ b/app/portainer/services/stateManager.js @@ -11,7 +11,20 @@ angular.module('portainer.app').factory('StateManager', [ 'APPLICATION_CACHE_VALIDITY', 'AgentPingService', '$analytics', - function StateManagerFactory($q, $async, SystemService, InfoHelper, LocalStorage, SettingsService, StatusService, APPLICATION_CACHE_VALIDITY, AgentPingService, $analytics) { + 'EndpointProvider', + function StateManagerFactory( + $q, + $async, + SystemService, + InfoHelper, + LocalStorage, + SettingsService, + StatusService, + APPLICATION_CACHE_VALIDITY, + AgentPingService, + $analytics, + EndpointProvider + ) { var manager = {}; var state = { @@ -49,6 +62,11 @@ angular.module('portainer.app').factory('StateManager', [ state.application = {}; }; + manager.cleanEndpoint = function () { + state.endpoint = {}; + EndpointProvider.clean(); + }; + manager.updateLogo = function (logoURL) { state.application.logo = logoURL; LocalStorage.storeApplicationState(state.application); diff --git a/app/portainer/views/endpoints/endpointsController.js b/app/portainer/views/endpoints/endpointsController.js index 0cf881ac7..de39bda59 100644 --- a/app/portainer/views/endpoints/endpointsController.js +++ b/app/portainer/views/endpoints/endpointsController.js @@ -3,7 +3,7 @@ import EndpointHelper from 'Portainer/helpers/endpointHelper'; angular.module('portainer.app').controller('EndpointsController', EndpointsController); -function EndpointsController($q, $scope, $state, $async, EndpointService, GroupService, ModalService, Notifications) { +function EndpointsController($q, $scope, $state, $async, EndpointService, GroupService, ModalService, Notifications, EndpointProvider, StateManager) { $scope.removeAction = removeAction; function removeAction(endpoints) { @@ -26,6 +26,14 @@ function EndpointsController($q, $scope, $state, $async, EndpointService, GroupS } } + const endpointId = EndpointProvider.endpointID(); + // If the current endpoint was deleted, then clean endpoint store + if (endpoints.some((item) => item.Id === endpointId)) { + StateManager.cleanEndpoint(); + // trigger sidebar rerender + $scope.applicationState.endpoint = {}; + } + $state.reload(); }