fix(sidebar): clear current endpoint if deleted [EE-873] (#6052)

pull/6120/head
Hao Zhang 2021-11-19 12:21:46 +08:00 committed by GitHub
parent b596d0febd
commit 17a20cb2c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -11,7 +11,20 @@ angular.module('portainer.app').factory('StateManager', [
'APPLICATION_CACHE_VALIDITY', 'APPLICATION_CACHE_VALIDITY',
'AgentPingService', 'AgentPingService',
'$analytics', '$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 manager = {};
var state = { var state = {
@ -49,6 +62,11 @@ angular.module('portainer.app').factory('StateManager', [
state.application = {}; state.application = {};
}; };
manager.cleanEndpoint = function () {
state.endpoint = {};
EndpointProvider.clean();
};
manager.updateLogo = function (logoURL) { manager.updateLogo = function (logoURL) {
state.application.logo = logoURL; state.application.logo = logoURL;
LocalStorage.storeApplicationState(state.application); LocalStorage.storeApplicationState(state.application);

View File

@ -3,7 +3,7 @@ import EndpointHelper from 'Portainer/helpers/endpointHelper';
angular.module('portainer.app').controller('EndpointsController', EndpointsController); 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; $scope.removeAction = removeAction;
function removeAction(endpoints) { 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(); $state.reload();
} }