From 7d40a83d03acec8be7b7e3c6c12972fa8424e9a0 Mon Sep 17 00:00:00 2001 From: zees-dev <63374656+zees-dev@users.noreply.github.com> Date: Fri, 24 Sep 2021 20:21:50 +1200 Subject: [PATCH] feat(kubectl-shell): page state refreshes in k8s endpoint do not close shell EE-1628 (#5685) * converting all kubernetes view reload to partial state heirarchy refresh * updated helm and kube kustom templates headers to use the reusable k8s page header component --- .../helm-add-repository.controller.js | 2 +- .../helm/helm-templates/helm-templates.html | 11 +++-------- .../kubectl-shell/kubectl-shell.controller.js | 6 ++++++ app/kubernetes/components/view-header/viewHeader.html | 2 +- .../kube-custom-templates-view.html | 11 +++-------- .../kube-registry-access-view.controller.js | 2 +- .../views/applications/applicationsController.js | 4 ++-- .../create/createApplicationController.js | 2 +- .../views/applications/edit/applicationController.js | 6 +++--- .../views/applications/helm/helm.controller.js | 2 +- app/kubernetes/views/cluster/node/nodeController.js | 2 +- .../views/configurations/configurationsController.js | 2 +- .../configurations/edit/configurationController.js | 2 +- .../access/resourcePoolAccessController.js | 4 ++-- .../resource-pools/edit/resourcePoolController.js | 4 ++-- .../views/resource-pools/resourcePoolsController.js | 2 +- app/kubernetes/views/volumes/edit/volumeController.js | 2 +- app/kubernetes/views/volumes/volumesController.js | 2 +- .../kubernetes-app-git-form.controller.js | 2 +- .../endpoints/access/endpointAccessController.js | 2 +- 20 files changed, 34 insertions(+), 38 deletions(-) diff --git a/app/kubernetes/components/helm/helm-templates/helm-add-repository/helm-add-repository.controller.js b/app/kubernetes/components/helm/helm-templates/helm-add-repository/helm-add-repository.controller.js index 068e1ab74..ac9ba546f 100644 --- a/app/kubernetes/components/helm/helm-templates/helm-add-repository/helm-add-repository.controller.js +++ b/app/kubernetes/components/helm/helm-templates/helm-add-repository/helm-add-repository.controller.js @@ -21,7 +21,7 @@ export default class HelmAddRepositoryController { try { await this.HelmService.addHelmRepository(this.EndpointProvider.currentEndpoint().Id, { url: this.state.repository }); this.Notifications.success('Helm repository added successfully'); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Installation error', err); } finally { diff --git a/app/kubernetes/components/helm/helm-templates/helm-templates.html b/app/kubernetes/components/helm/helm-templates/helm-templates.html index 1cdae0d32..360d3ec05 100644 --- a/app/kubernetes/components/helm/helm-templates/helm-templates.html +++ b/app/kubernetes/components/helm/helm-templates/helm-templates.html @@ -1,11 +1,6 @@ - - - - - - - Charts - + + Charts + diff --git a/app/kubernetes/components/kubectl-shell/kubectl-shell.controller.js b/app/kubernetes/components/kubectl-shell/kubectl-shell.controller.js index bf2bdde7c..983453f9d 100644 --- a/app/kubernetes/components/kubectl-shell/kubectl-shell.controller.js +++ b/app/kubernetes/components/kubectl-shell/kubectl-shell.controller.js @@ -10,6 +10,12 @@ export default class KubectlShellController { this.EndpointProvider = EndpointProvider; this.LocalStorage = LocalStorage; this.Notifications = Notifications; + + $window.onbeforeunload = () => { + if (this.state.shell.connected) { + return ''; + } + }; } disconnect() { diff --git a/app/kubernetes/components/view-header/viewHeader.html b/app/kubernetes/components/view-header/viewHeader.html index 13838a458..cda3d86f8 100644 --- a/app/kubernetes/components/view-header/viewHeader.html +++ b/app/kubernetes/components/view-header/viewHeader.html @@ -1,6 +1,6 @@ - + diff --git a/app/kubernetes/custom-templates/kube-custom-templates-view/kube-custom-templates-view.html b/app/kubernetes/custom-templates/kube-custom-templates-view/kube-custom-templates-view.html index 75eae315a..762474c74 100644 --- a/app/kubernetes/custom-templates/kube-custom-templates-view/kube-custom-templates-view.html +++ b/app/kubernetes/custom-templates/kube-custom-templates-view/kube-custom-templates-view.html @@ -1,11 +1,6 @@ - - - - - - - Custom Templates - + + Custom Templates +
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 97db67ae8..3eb4e1c85 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 @@ -44,7 +44,7 @@ export default class KubernetesRegistryAccessController { await this.EndpointService.updateRegistryAccess(this.endpoint.Id, this.registry.Id, { namespaces, }); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Failed saving registry access'); } diff --git a/app/kubernetes/views/applications/applicationsController.js b/app/kubernetes/views/applications/applicationsController.js index 36f91fc4f..dd5e089b0 100644 --- a/app/kubernetes/views/applications/applicationsController.js +++ b/app/kubernetes/views/applications/applicationsController.js @@ -45,7 +45,7 @@ class KubernetesApplicationsController { } finally { --actionCount; if (actionCount === 0) { - this.$state.reload(); + this.$state.reload(this.$state.current); } } } @@ -79,7 +79,7 @@ class KubernetesApplicationsController { } finally { --actionCount; if (actionCount === 0) { - this.$state.reload(); + this.$state.reload(this.$state.current); } } } diff --git a/app/kubernetes/views/applications/create/createApplicationController.js b/app/kubernetes/views/applications/create/createApplicationController.js index c3903cf89..50bdc685f 100644 --- a/app/kubernetes/views/applications/create/createApplicationController.js +++ b/app/kubernetes/views/applications/create/createApplicationController.js @@ -169,7 +169,7 @@ class KubernetesCreateApplicationController { this.state.updateWebEditorInProgress = true; await this.StackService.updateKubeStack({ EndpointId: this.endpoint.Id, Id: this.application.StackId }, this.stackFileContent, null); this.state.isEditorDirty = false; - await this.$state.reload(); + await this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Failed redeploying application'); } finally { diff --git a/app/kubernetes/views/applications/edit/applicationController.js b/app/kubernetes/views/applications/edit/applicationController.js index 935de40aa..eb3f88094 100644 --- a/app/kubernetes/views/applications/edit/applicationController.js +++ b/app/kubernetes/views/applications/edit/applicationController.js @@ -215,7 +215,7 @@ class KubernetesApplicationController { const revision = _.nth(this.application.Revisions, -2); await this.KubernetesApplicationService.rollback(this.application, revision); this.Notifications.success('Application successfully rolled back'); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Unable to rollback the application'); } @@ -236,7 +236,7 @@ class KubernetesApplicationController { const promises = _.map(this.application.Pods, (item) => this.KubernetesPodService.delete(item)); await Promise.all(promises); this.Notifications.success('Application successfully redeployed'); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Unable to redeploy the application'); } @@ -259,7 +259,7 @@ class KubernetesApplicationController { application.Note = this.formValues.Note; await this.KubernetesApplicationService.patch(this.application, application, true); this.Notifications.success('Application successfully updated'); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Unable to update application'); } diff --git a/app/kubernetes/views/applications/helm/helm.controller.js b/app/kubernetes/views/applications/helm/helm.controller.js index df889d4c2..431589398 100644 --- a/app/kubernetes/views/applications/helm/helm.controller.js +++ b/app/kubernetes/views/applications/helm/helm.controller.js @@ -20,7 +20,7 @@ export default class KubernetesHelmApplicationController { if (releases.length > 0) { this.state.release = releases[0]; } else { - throw PortainerError(`Release ${this.state.params.name} not found`); + throw new PortainerError(`Release ${this.state.params.name} not found`); } } catch (err) { this.Notifications.error('Failure', err, 'Unable to retrieve helm application details'); diff --git a/app/kubernetes/views/cluster/node/nodeController.js b/app/kubernetes/views/cluster/node/nodeController.js index 9a726add7..d08b949c5 100644 --- a/app/kubernetes/views/cluster/node/nodeController.js +++ b/app/kubernetes/views/cluster/node/nodeController.js @@ -253,7 +253,7 @@ class KubernetesNodeController { await this.drainNode(); } this.Notifications.success('Node updated successfully'); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Unable to update node'); } diff --git a/app/kubernetes/views/configurations/configurationsController.js b/app/kubernetes/views/configurations/configurationsController.js index 931a7fac6..2fa24c9dc 100644 --- a/app/kubernetes/views/configurations/configurationsController.js +++ b/app/kubernetes/views/configurations/configurationsController.js @@ -51,7 +51,7 @@ class KubernetesConfigurationsController { } finally { --actionCount; if (actionCount === 0) { - this.$state.reload(); + this.$state.reload(this.$state.current); } } } diff --git a/app/kubernetes/views/configurations/edit/configurationController.js b/app/kubernetes/views/configurations/edit/configurationController.js index cb2e16f45..9c8f5615f 100644 --- a/app/kubernetes/views/configurations/edit/configurationController.js +++ b/app/kubernetes/views/configurations/edit/configurationController.js @@ -107,7 +107,7 @@ class KubernetesConfigurationController { } else { await this.KubernetesConfigurationService.update(this.formValues, this.configuration); this.Notifications.success('Configuration succesfully updated'); - this.$state.reload(); + this.$state.reload(this.$state.current); } } catch (err) { this.Notifications.error('Failure', err, 'Unable to update configuration'); diff --git a/app/kubernetes/views/resource-pools/access/resourcePoolAccessController.js b/app/kubernetes/views/resource-pools/access/resourcePoolAccessController.js index daed229d5..88748e92f 100644 --- a/app/kubernetes/views/resource-pools/access/resourcePoolAccessController.js +++ b/app/kubernetes/views/resource-pools/access/resourcePoolAccessController.js @@ -98,7 +98,7 @@ class KubernetesResourcePoolAccessController { const accessConfigMap = KubernetesConfigMapHelper.modifiyNamespaceAccesses(angular.copy(this.accessConfigMap), this.pool.Namespace.Name, newAccesses); await this.KubernetesConfigMapService.updateAccess(accessConfigMap); this.Notifications.success('Access successfully created'); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Unable to create accesses'); } @@ -118,7 +118,7 @@ class KubernetesResourcePoolAccessController { const accessConfigMap = KubernetesConfigMapHelper.modifiyNamespaceAccesses(angular.copy(this.accessConfigMap), this.pool.Namespace.Name, newAccesses); await this.KubernetesConfigMapService.updateAccess(accessConfigMap); this.Notifications.success('Access successfully removed'); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Unable to remove accesses'); } finally { diff --git a/app/kubernetes/views/resource-pools/edit/resourcePoolController.js b/app/kubernetes/views/resource-pools/edit/resourcePoolController.js index f611a5b9d..d35600c32 100644 --- a/app/kubernetes/views/resource-pools/edit/resourcePoolController.js +++ b/app/kubernetes/views/resource-pools/edit/resourcePoolController.js @@ -176,7 +176,7 @@ class KubernetesResourcePoolController { this.checkDefaults(); await this.KubernetesResourcePoolService.patch(oldFormValues, newFormValues); this.Notifications.success('Namespace successfully updated', this.pool.Namespace.Name); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Unable to create namespace'); } finally { @@ -238,7 +238,7 @@ class KubernetesResourcePoolController { await this.KubernetesResourcePoolService.toggleSystem(this.endpoint.Id, namespaceName, !this.isSystem); this.Notifications.success('Namespace successfully updated', namespaceName); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Unable to create namespace'); } finally { diff --git a/app/kubernetes/views/resource-pools/resourcePoolsController.js b/app/kubernetes/views/resource-pools/resourcePoolsController.js index 2ff466800..cd5403946 100644 --- a/app/kubernetes/views/resource-pools/resourcePoolsController.js +++ b/app/kubernetes/views/resource-pools/resourcePoolsController.js @@ -29,7 +29,7 @@ class KubernetesResourcePoolsController { } finally { --actionCount; if (actionCount === 0) { - this.$state.reload(); + this.$state.reload(this.$state.current); } } } diff --git a/app/kubernetes/views/volumes/edit/volumeController.js b/app/kubernetes/views/volumes/edit/volumeController.js index 332c58c84..8d52bb9a3 100644 --- a/app/kubernetes/views/volumes/edit/volumeController.js +++ b/app/kubernetes/views/volumes/edit/volumeController.js @@ -96,7 +96,7 @@ class KubernetesVolumeController { this.Notifications.success('Applications successfully redeployed'); } - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Unable to update volume.'); } diff --git a/app/kubernetes/views/volumes/volumesController.js b/app/kubernetes/views/volumes/volumesController.js index cc8beb096..4d2b75dbe 100644 --- a/app/kubernetes/views/volumes/volumesController.js +++ b/app/kubernetes/views/volumes/volumesController.js @@ -68,7 +68,7 @@ class KubernetesVolumesController { } finally { --actionCount; if (actionCount === 0) { - this.$state.reload(); + this.$state.reload(this.$state.current); } } } diff --git a/app/portainer/components/forms/kubernetes-app-git-form/kubernetes-app-git-form.controller.js b/app/portainer/components/forms/kubernetes-app-git-form/kubernetes-app-git-form.controller.js index 68ab3d1bc..af7a8c691 100644 --- a/app/portainer/components/forms/kubernetes-app-git-form/kubernetes-app-git-form.controller.js +++ b/app/portainer/components/forms/kubernetes-app-git-form/kubernetes-app-git-form.controller.js @@ -55,7 +55,7 @@ class KubernetesAppGitFormController { this.state.redeployInProgress = true; await this.StackService.updateKubeGit(this.stack.Id, this.stack.EndpointId, this.namespace, this.formValues); this.Notifications.success('Pulled and redeployed stack successfully'); - await this.$state.reload(); + await this.$state.reload(this.$state.current); } catch (err) { this.Notifications.error('Failure', err, 'Failed redeploying application'); } finally { diff --git a/app/portainer/views/endpoints/access/endpointAccessController.js b/app/portainer/views/endpoints/access/endpointAccessController.js index 6d7e2329e..77f414a31 100644 --- a/app/portainer/views/endpoints/access/endpointAccessController.js +++ b/app/portainer/views/endpoints/access/endpointAccessController.js @@ -33,7 +33,7 @@ class EndpointAccessController { this.state.actionInProgress = true; await this.EndpointService.updateEndpoint(this.$transition$.params().id, this.endpoint); this.Notifications.success('Access successfully updated'); - this.$state.reload(); + this.$state.reload(this.$state.current); } catch (err) { this.state.actionInProgress = false; this.Notifications.error('Failure', err, 'Unable to update accesses');