From 661d6f080b15519b5e71c47a845d7e08bfe88d47 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Mon, 6 Sep 2021 09:53:43 +0300 Subject: [PATCH] Refactor warning messages Signed-off-by: Alex Andreev --- src/main/cluster.ts | 2 +- .../delete-cluster-dialog.tsx | 43 +++++++++++++------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/main/cluster.ts b/src/main/cluster.ts index b7f33adc76..fd8142aa57 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -741,6 +741,6 @@ export class Cluster implements ClusterModel, ClusterState { } isInLocalKubeconfig() { - return this.kubeConfigPath.includes(storedKubeConfigFolder()); + return this.kubeConfigPath.startsWith(storedKubeConfigFolder()); } } 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 68591ee457..60635d25b5 100644 --- a/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.tsx +++ b/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.tsx @@ -151,27 +151,44 @@ export class DeleteClusterDialog extends React.Component { ); } - renderWarning() { - const { cluster } = dialogState; - const isInternalKubeconfig = cluster.isInLocalKubeconfig(); - let warning: JSX.Element = null; + getWarningMessage() { + const { cluster, config } = dialogState; + const contexts = config.contexts.filter(context => context.name !== cluster.contextName); - if (this.isCurrentContext()) { - warning =

- This will remove active context in kubeconfig. Use drop down below to select a different one. -

; - } else if (!isInternalKubeconfig) { - warning =

The contents of kubeconfig file will be changed!

; + if (!contexts.length) { + return ( +

+ This will remove the last context in kubeconfig. There will be no active context. +

+ ); } - if (!warning) { - return null; + if (this.isCurrentContext()) { + return ( +

+ This will remove active context in kubeconfig. Use drop down below to select a different one. +

+ ); + } + + if (cluster.isInLocalKubeconfig()) { + return ( +

+ Are you sure you want to delete it? It can be re-added through the copy/paste mechanism. +

+ ); } + return ( +

The contents of kubeconfig file will be changed!

+ ); + } + + renderWarning() { return (
- {warning} + {this.getWarningMessage()}
); }