diff --git a/src/main/cluster.ts b/src/main/cluster.ts index 319f2d23df..2f9debd5a7 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -32,9 +32,9 @@ import logger from "./logger"; import { VersionDetector } from "./cluster-detectors/version-detector"; import { DetectorRegistry } from "./cluster-detectors/detector-registry"; import plimit from "p-limit"; -import { toJS } from "../common/utils"; import type { ClusterState, ClusterRefreshOptions, ClusterMetricsResourceType, ClusterId, ClusterMetadata, ClusterModel, ClusterPreferences, ClusterPrometheusPreferences, UpdateClusterModel } from "../common/cluster-types"; import { ClusterMetadataKey, initialNodeShellImage, ClusterStatus } from "../common/cluster-types"; +import { storedKubeConfigFolder, toJS } from "../common/utils"; /** * Cluster @@ -712,4 +712,8 @@ export class Cluster implements ClusterModel, ClusterState { get imagePullSecret(): string { return this.preferences.imagePullSecret || ""; } + + isInLocalKubeconfig() { + return this.kubeConfigPath.includes(storedKubeConfigFolder()); + } } diff --git a/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.module.css b/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.module.css index 3e18677f0f..0c95c3d2a6 100644 --- a/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.module.css +++ b/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.module.css @@ -32,4 +32,10 @@ > * { margin-left: var(--margin) } +} + +.hr { + @apply mt-7; + height: 1px; + background: #dfdfdf80; } \ No newline at end of file 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 e9d4bff397..a6f89f0f2e 100644 --- a/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.tsx +++ b/src/renderer/components/delete-cluster-dialog/delete-cluster-dialog.tsx @@ -25,7 +25,7 @@ import { observer } from "mobx-react"; import React from "react"; import { Button } from "../button"; -import type { Context, KubeConfig } from "@kubernetes/client-node"; +import type { KubeConfig } from "@kubernetes/client-node"; import type { Cluster } from "../../../main/cluster"; import { saveKubeconfig } from "./save-config"; import { requestMain } from "../../../common/ipc"; @@ -36,6 +36,7 @@ import { boundMethod } from "autobind-decorator"; import { Dialog } from "../dialog"; import { Icon } from "../icon"; import { Select } from "../select"; +import { Checkbox } from "../checkbox"; type DialogState = { isOpen: boolean, @@ -70,16 +71,23 @@ export class DeleteClusterDialog extends React.Component { static close() { dialogState.isOpen = false; + dialogState.cluster = null; + dialogState.config = null; } @boundMethod onOpen() { - this.showContextSwitch = false; this.newCurrentContext = ""; + + if (this.isCurrentContext()) { + this.showContextSwitch = true; + } } + @boundMethod onClose() { DeleteClusterDialog.close(); + this.showContextSwitch = false; } removeContext() { @@ -114,8 +122,14 @@ export class DeleteClusterDialog extends React.Component { this.onClose(); } - renderCurrentContextSwitch(contexts: Context[]) { + isCurrentContext() { + return dialogState.config.currentContext == dialogState.cluster.contextName; + } + + renderCurrentContextSwitch() { if (!this.showContextSwitch) return null; + const { cluster, config } = dialogState; + const contexts = config.contexts.filter(context => context.name !== cluster.contextName); const options = [ ...contexts.map(context => ({ @@ -126,57 +140,74 @@ export class DeleteClusterDialog extends React.Component { return (
-

Choose new current-context