From b102ac7d9f293374c5bdd38597cd06de28a9ec95 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 7 May 2021 10:01:31 -0400 Subject: [PATCH] remove removedClusters from ClusterStore Signed-off-by: Sebastian Malton --- src/common/cluster-store.ts | 10 ---------- src/main/cluster-manager.ts | 18 +----------------- src/renderer/utils/createStorage.ts | 13 +++---------- 3 files changed, 4 insertions(+), 37 deletions(-) diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index 5ae5378e6f..da053e6b19 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -111,7 +111,6 @@ export class ClusterStore extends BaseStore { } @observable activeCluster: ClusterId; - @observable removedClusters = observable.map(); @observable clusters = observable.map(); private static stateRequestChannel = "cluster:states"; @@ -290,7 +289,6 @@ export class ClusterStore extends BaseStore { protected fromStore({ activeCluster, clusters = [] }: ClusterStoreModel = {}) { const currentClusters = this.clusters.toJS(); const newClusters = new Map(); - const removedClusters = new Map(); // update new clusters for (const clusterModel of clusters) { @@ -308,16 +306,8 @@ export class ClusterStore extends BaseStore { } } - // update removed clusters - currentClusters.forEach(cluster => { - if (!newClusters.has(cluster.id)) { - removedClusters.set(cluster.id, cluster); - } - }); - this.setActive(activeCluster); this.clusters.replace(newClusters); - this.removedClusters.replace(removedClusters); } toJSON(): ClusterStoreModel { diff --git a/src/main/cluster-manager.ts b/src/main/cluster-manager.ts index 9b1b133749..ed6bf0bac8 100644 --- a/src/main/cluster-manager.ts +++ b/src/main/cluster-manager.ts @@ -1,7 +1,7 @@ import "../common/cluster-ipc"; import type http from "http"; import { ipcMain } from "electron"; -import { action, autorun, reaction, toJS } from "mobx"; +import { action, reaction, toJS } from "mobx"; import { ClusterStore, getClusterIdFromHost } from "../common/cluster-store"; import { Cluster } from "./cluster"; import logger from "./logger"; @@ -22,22 +22,6 @@ export class ClusterManager extends Singleton { this.syncClustersFromCatalog(entities); }); - - // auto-stop removed clusters - autorun(() => { - const removedClusters = Array.from(ClusterStore.getInstance().removedClusters.values()); - - if (removedClusters.length > 0) { - const meta = removedClusters.map(cluster => cluster.getMeta()); - - logger.info(`[CLUSTER-MANAGER]: removing clusters`, meta); - removedClusters.forEach(cluster => cluster.disconnect()); - ClusterStore.getInstance().removedClusters.clear(); - } - }, { - delay: 250 - }); - ipcMain.on("network:offline", () => { this.onNetworkOffline(); }); ipcMain.on("network:online", () => { this.onNetworkOnline(); }); } diff --git a/src/renderer/utils/createStorage.ts b/src/renderer/utils/createStorage.ts index 79f6c13ba6..aeb5621730 100755 --- a/src/renderer/utils/createStorage.ts +++ b/src/renderer/utils/createStorage.ts @@ -7,7 +7,7 @@ import { app, remote } from "electron"; import { observable, reaction, when } from "mobx"; import fse from "fs-extra"; import { StorageHelper } from "./storageHelper"; -import { ClusterStore, getHostedClusterId } from "../../common/cluster-store"; +import { getHostedClusterId } from "../../common/cluster-store"; import logger from "../../main/logger"; let initialized = false; @@ -31,10 +31,8 @@ export function createStorage(key: string, defaultValue: T, observableOptions // bind auto-saving reaction(() => storage.toJSON(), saveFile, { delay: 250 }); - // remove json-file when cluster deleted - if (clusterId !== undefined) { - when(() => ClusterStore.getInstance(false)?.removedClusters.has(clusterId)).then(removeFile); - } + // We don't clean up the cluster because it might come back in the future + // as cluster IDs are now deterministic based on "path" + "contextName" } async function saveFile(json = {}) { @@ -46,11 +44,6 @@ export function createStorage(key: string, defaultValue: T, observableOptions } } - function removeFile() { - logger.debug("[remove]:", jsonFilePath); - fse.unlink(jsonFilePath).catch(Function); - } - return new StorageHelper(key, { autoInit: true, observable: observableOptions,