Add context menu entry for deleting local clusters (#2923)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-06-17 12:19:22 -04:00
1 parent e47d26e1ce
commit eb45f45a7a
30 files changed
+348 -377

No files matched your search

@@ -21,13 +21,13 @@
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
import { CatalogEntity, CatalogEntityActionContext, CatalogEntityAddMenuContext, CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
import { clusterActivateHandler, clusterDisconnectHandler } from "../cluster-ipc";
import { clusterActivateHandler, clusterDeleteHandler, clusterDisconnectHandler } from "../cluster-ipc";
import { ClusterStore } from "../cluster-store";
import { requestMain } from "../ipc";
import { productName } from "../vars";
import { CatalogCategory, CatalogCategorySpec } from "../catalog";
import { addClusterURL } from "../routes";
import { app } from "electron";
import { HotbarStore } from "../hotbar-store";
export type KubernetesClusterPrometheusMetrics = {
address?: {
@@ -50,7 +50,7 @@ export type KubernetesClusterSpec = {
};
export interface KubernetesClusterStatus extends CatalogEntityStatus {
phase: "connected" | "disconnected";
phase: "connected" | "disconnected" | "deleting";
}
export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, KubernetesClusterStatus, KubernetesClusterSpec> {
@@ -103,39 +103,38 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
if (!this.metadata.source || this.metadata.source === "local") {
context.menuItems.push({
title: "Settings",
icon: "edit",
onClick: async () => context.navigate(`/entity/${this.metadata.uid}/settings`)
});
}
if (this.metadata.labels["file"]?.startsWith(ClusterStore.storedKubeConfigFolder)) {
context.menuItems.push({
title: "Delete",
icon: "delete",
onClick: async () => ClusterStore.getInstance().removeById(this.metadata.uid),
confirm: {
message: `Remove Kubernetes Cluster "${this.metadata.name} from ${productName}?`
}
});
context.menuItems.push(
{
title: "Settings",
icon: "edit",
onClick: () => context.navigate(`/entity/${this.metadata.uid}/settings`)
},
{
title: "Delete",
icon: "delete",
onClick: () => {
HotbarStore.getInstance().removeAllHotbarItems(this.getId());
requestMain(clusterDeleteHandler, this.metadata.uid);
},
confirm: {
// TODO: change this to be a <p> tag with better formatting once this code can accept it.
message: `Delete the "${this.metadata.name}" context from "${this.metadata.labels.file}"?`
}
},
);
}
if (this.status.phase == "connected") {
context.menuItems.push({
title: "Disconnect",
icon: "link_off",
onClick: async () => {
requestMain(clusterDisconnectHandler, this.metadata.uid);
}
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid)
});
} else {
context.menuItems.push({
title: "Connect",
icon: "link",
onClick: async () => {
context.navigate(`/cluster/${this.metadata.uid}`);
}
onClick: () => context.navigate(`/cluster/${this.metadata.uid}`)
});
}