From e76f042bc079ed578b3bd7144defcb8953c02e59 Mon Sep 17 00:00:00 2001 From: Jim Ehrismann <40840436+jim-docker@users.noreply.github.com> Date: Wed, 8 Sep 2021 07:09:07 -0400 Subject: [PATCH] don't allow delete of the active cluster before setting to new active cluster (#3749) * don't allow user to delete the active cluster before setting to new active cluster Signed-off-by: Jim Ehrismann * fix lint issues Signed-off-by: Jim Ehrismann * Show delete button if no more contexts available Signed-off-by: Alex Andreev Co-authored-by: Alex Andreev Signed-off-by: Alex Andreev --- .../delete-cluster-dialog.tsx | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.tsx b/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.tsx index 6ab4e4e88a..01cf35eec8 100644 --- a/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.tsx +++ b/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.tsx @@ -20,7 +20,7 @@ */ import styles from "./delete-cluster-dialog.module.css"; -import { makeObservable, observable } from "mobx"; +import { computed, makeObservable, observable } from "mobx"; import { observer } from "mobx-react"; import React from "react"; @@ -122,6 +122,18 @@ export class DeleteClusterDialog extends React.Component { this.onClose(); } + @computed get disableDelete() { + const { cluster, config } = dialogState; + const noContextsAvailable = config.contexts.filter(context => context.name !== cluster.contextName).length == 0; + const newContextNotSelected = this.newCurrentContext === ""; + + if (noContextsAvailable) { + return false; + } + + return this.showContextSwitch && newContextNotSelected; + } + isCurrentContext() { return dialogState.config.currentContext == dialogState.cluster.contextName; } @@ -142,6 +154,7 @@ export class DeleteClusterDialog extends React.Component {