From 6fea8373c654bec24ad246e2c3b01e4df29b15f3 Mon Sep 17 00:00:00 2001 From: LP B Date: Mon, 6 Sep 2021 07:25:02 +0200 Subject: [PATCH] feat(app/registries): add warning modal on registries deletion (#5396) * feat(app/registries): add warning modal on registries deletion feat(app/namespace): add confirmation modal on registry removal feat(app/registry-access): add confirmation modal on namespace removal fix(app/registry-access): change update to remove in confirmation modal refactor(app/registries): generic message on registry access removal * fix(app/registries): typo in warning messages --- .../kube-registry-access-view.controller.js | 12 ++++++++++-- .../edit/resourcePoolController.js | 17 ++++++++++++----- .../views/registries/registriesController.js | 6 +++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/kubernetes/registries/kube-registry-access-view/kube-registry-access-view.controller.js b/app/kubernetes/registries/kube-registry-access-view/kube-registry-access-view.controller.js index 9367f5aef..97db67ae8 100644 --- a/app/kubernetes/registries/kube-registry-access-view/kube-registry-access-view.controller.js +++ b/app/kubernetes/registries/kube-registry-access-view/kube-registry-access-view.controller.js @@ -2,9 +2,10 @@ import KubernetesNamespaceHelper from 'Kubernetes/helpers/namespaceHelper'; export default class KubernetesRegistryAccessController { /* @ngInject */ - constructor($async, $state, EndpointService, Notifications, KubernetesResourcePoolService) { + constructor($async, $state, ModalService, EndpointService, Notifications, KubernetesResourcePoolService) { this.$async = $async; this.$state = $state; + this.ModalService = ModalService; this.Notifications = Notifications; this.KubernetesResourcePoolService = KubernetesResourcePoolService; this.EndpointService = EndpointService; @@ -26,8 +27,15 @@ export default class KubernetesRegistryAccessController { handleRemove(namespaces) { const removeNamespaces = namespaces.map(({ value }) => value); + const nsToUpdate = this.savedResourcePools.map(({ value }) => value).filter((value) => !removeNamespaces.includes(value)); - return this.updateNamespaces(this.savedResourcePools.map(({ value }) => value).filter((value) => !removeNamespaces.includes(value))); + const displayedMessage = + 'This registry might be used by one or more applications inside this environment. Removing the registry access could lead to a service interruption for these applications.

Do you wish to continue?'; + this.ModalService.confirmDeletion(displayedMessage, (confirmed) => { + if (confirmed) { + return this.updateNamespaces(nsToUpdate); + } + }); } updateNamespaces(namespaces) { diff --git a/app/kubernetes/views/resource-pools/edit/resourcePoolController.js b/app/kubernetes/views/resource-pools/edit/resourcePoolController.js index 1fe6e844d..f611a5b9d 100644 --- a/app/kubernetes/views/resource-pools/edit/resourcePoolController.js +++ b/app/kubernetes/views/resource-pools/edit/resourcePoolController.js @@ -185,20 +185,26 @@ class KubernetesResourcePoolController { } updateResourcePool() { - const willBeDeleted = _.filter(this.formValues.IngressClasses, { WasSelected: true, Selected: false }); + const ingressesToDelete = _.filter(this.formValues.IngressClasses, { WasSelected: true, Selected: false }); + const registriesToDelete = _.filter(this.registries, { WasChecked: true, Checked: false }); const warnings = { quota: this.hasResourceQuotaBeenReduced(), - ingress: willBeDeleted.length !== 0, + ingress: ingressesToDelete.length !== 0, + registries: registriesToDelete.length !== 0, }; - if (warnings.quota || warnings.ingress) { + if (warnings.quota || warnings.ingress || warnings.registries) { const messages = { quota: 'Reducing the quota assigned to an "in-use" namespace may have unintended consequences, including preventing running applications from functioning correctly and potentially even blocking them from running at all.', ingress: 'Deactivating ingresses may cause applications to be unaccessible. All ingress configurations from affected applications will be removed.', + registries: + 'Some registries you removed might be used by one or more applications inside this environment. Removing the registries access could lead to a service interruption for these applications.', }; - const displayedMessage = `${warnings.quota ? messages.quota : ''}${warnings.quota && warnings.ingress ? '

' : ''} - ${warnings.ingress ? messages.ingress : ''}

Do you wish to continue?`; + const displayedMessage = `${warnings.quota ? messages.quota + '

' : ''} + ${warnings.ingress ? messages.ingress + '

' : ''} + ${warnings.registries ? messages.registries + '

' : ''} + Do you wish to continue?`; this.ModalService.confirmUpdate(displayedMessage, (confirmed) => { if (confirmed) { return this.$async(this.updateResourcePoolAsync, this.savedFormValues, this.formValues); @@ -322,6 +328,7 @@ class KubernetesResourcePoolController { this.registries.forEach((reg) => { if (reg.RegistryAccesses && reg.RegistryAccesses[this.endpoint.Id] && reg.RegistryAccesses[this.endpoint.Id].Namespaces.includes(namespace)) { reg.Checked = true; + reg.WasChecked = true; this.formValues.Registries.push(reg); } }); diff --git a/app/portainer/views/registries/registriesController.js b/app/portainer/views/registries/registriesController.js index 83e3cbafc..568516de7 100644 --- a/app/portainer/views/registries/registriesController.js +++ b/app/portainer/views/registries/registriesController.js @@ -21,7 +21,11 @@ angular.module('portainer.app').controller('RegistriesController', [ }; $scope.removeAction = function (selectedItems) { - ModalService.confirmDeletion('Do you want to remove the selected registries?', function onConfirm(confirmed) { + const regAttrMsg = selectedItems.length > 1 ? 'hese' : 'his'; + const registriesMsg = selectedItems.length > 1 ? 'registries' : 'registry'; + const msg = `T${regAttrMsg} ${registriesMsg} might be used by applications inside one or more endpoints. Removing the ${registriesMsg} could lead to a service interruption for the applications using t${regAttrMsg} ${registriesMsg}. Do you want to remove the selected ${registriesMsg}?`; + + ModalService.confirmDeletion(msg, function onConfirm(confirmed) { if (!confirmed) { return; }