From dade4eba52fab4781bed86b2f4a49132733eafa0 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 8 Jul 2022 13:04:07 -0400 Subject: [PATCH] Resolve PR comments Signed-off-by: Sebastian Malton --- src/common/__tests__/hotbar-store.test.ts | 6 ++--- src/common/base-store.ts | 20 ++++++++-------- ...ctable.ts => catalog-entity.injectable.ts} | 4 ++-- ...le.ts => preferences-entity.injectable.ts} | 4 ++-- ...ctable.ts => welcome-entity.injectable.ts} | 4 ++-- src/common/cluster-store/cluster-store.ts | 13 +++++----- src/common/hotbars/store.injectable.ts | 4 ++-- src/common/hotbars/store.ts | 4 ++-- .../hotbar-store/5.0.0-alpha.0.injectable.ts | 6 ++--- .../hotbar-store/5.0.0-beta.10.injectable.ts | 24 ++++++++----------- 10 files changed, 43 insertions(+), 46 deletions(-) rename src/common/catalog-entities/general-catalog-entities/implementations/{catalog-catalog-entity.injectable.ts => catalog-entity.injectable.ts} (91%) rename src/common/catalog-entities/general-catalog-entities/implementations/{preferences-catalog-entity.injectable.ts => preferences-entity.injectable.ts} (91%) rename src/common/catalog-entities/general-catalog-entities/implementations/{welcome-catalog-entity.injectable.ts => welcome-entity.injectable.ts} (91%) diff --git a/src/common/__tests__/hotbar-store.test.ts b/src/common/__tests__/hotbar-store.test.ts index cc8a4dc8fa..1761b4e983 100644 --- a/src/common/__tests__/hotbar-store.test.ts +++ b/src/common/__tests__/hotbar-store.test.ts @@ -15,7 +15,7 @@ import type { HotbarStore } from "../hotbars/store"; import catalogEntityRegistryInjectable from "../../main/catalog/entity-registry.injectable"; import { computed } from "mobx"; import hasCategoryForEntityInjectable from "../catalog/has-category-for-entity.injectable"; -import catalogCatalogEntityInjectable from "../catalog-entities/general-catalog-entities/implementations/catalog-catalog-entity.injectable"; +import catalogGeneralEntityInjectable from "../catalog-entities/general-catalog-entities/implementations/catalog-entity.injectable"; import loggerInjectable from "../logger.injectable"; import type { Logger } from "../logger"; import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable"; @@ -103,13 +103,13 @@ describe("HotbarStore", () => { di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data"); const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable); - const catalogCatalogEntity = di.inject(catalogCatalogEntityInjectable); + const catalogGeneralEntity = di.inject(catalogGeneralEntityInjectable); catalogEntityRegistry.addComputedSource("some-id", computed(() => [ testCluster, minikubeCluster, awsCluster, - catalogCatalogEntity, + catalogGeneralEntity, ])); di.permitSideEffects(getConfigurationFileModelInjectable); diff --git a/src/common/base-store.ts b/src/common/base-store.ts index 39c4d99b8e..ab973dba32 100644 --- a/src/common/base-store.ts +++ b/src/common/base-store.ts @@ -40,7 +40,7 @@ export abstract class BaseStore extends Singleton { readonly displayName: string = this.constructor.name; - protected constructor(protected readonly depenendices: BaseStoreDependencies, protected params: BaseStoreParams) { + protected constructor(protected readonly dependencies: BaseStoreDependencies, protected params: BaseStoreParams) { super(); makeObservable(this); } @@ -49,22 +49,22 @@ export abstract class BaseStore extends Singleton { * This must be called after the last child's constructor is finished (or just before it finishes) */ load() { - this.depenendices.logger.debug(`[${kebabCase(this.displayName).toUpperCase()}]: LOADING from ${this.path} ...`); - this.storeConfig = this.depenendices.getConfigurationFileModel({ + this.dependencies.logger.debug(`[${kebabCase(this.displayName).toUpperCase()}]: LOADING from ${this.path} ...`); + this.storeConfig = this.dependencies.getConfigurationFileModel({ ...this.params, projectName: "lens", - projectVersion: this.depenendices.appVersion, + projectVersion: this.dependencies.appVersion, cwd: this.cwd(), }); const res: any = this.fromStore(this.storeConfig.store); if (res instanceof Promise || (typeof res === "object" && res && typeof res.then === "function")) { - this.depenendices.logger.error(`${this.displayName} extends BaseStore's fromStore method returns a Promise or promise-like object. This is an error and must be fixed.`); + this.dependencies.logger.error(`${this.displayName} extends BaseStore's fromStore method returns a Promise or promise-like object. This is an error and must be fixed.`); } this.enableSync(); - this.depenendices.logger.debug(`[${kebabCase(this.displayName).toUpperCase()}]: LOADED from ${this.path}`); + this.dependencies.logger.debug(`[${kebabCase(this.displayName).toUpperCase()}]: LOADED from ${this.path}`); } get name() { @@ -84,11 +84,11 @@ export abstract class BaseStore extends Singleton { } protected cwd() { - return this.depenendices.directoryForUserData; + return this.dependencies.directoryForUserData; } protected saveToFile(model: T) { - this.depenendices.logger.info(`[STORE]: SAVING ${this.path}`); + this.dependencies.logger.info(`[STORE]: SAVING ${this.path}`); // todo: update when fixed https://github.com/sindresorhus/conf/issues/114 if (this.storeConfig) { @@ -109,14 +109,14 @@ export abstract class BaseStore extends Singleton { if (ipcMain) { this.syncDisposers.push(ipcMainOn(this.syncMainChannel, (event, model: T) => { - this.depenendices.logger.silly(`[STORE]: SYNC ${this.name} from renderer`, { model }); + this.dependencies.logger.silly(`[STORE]: SYNC ${this.name} from renderer`, { model }); this.onSync(model); })); } if (ipcRenderer) { this.syncDisposers.push(ipcRendererOn(this.syncRendererChannel, (event, model: T) => { - this.depenendices.logger.silly(`[STORE]: SYNC ${this.name} from main`, { model }); + this.dependencies.logger.silly(`[STORE]: SYNC ${this.name} from main`, { model }); this.onSyncFromMain(model); })); } diff --git a/src/common/catalog-entities/general-catalog-entities/implementations/catalog-catalog-entity.injectable.ts b/src/common/catalog-entities/general-catalog-entities/implementations/catalog-entity.injectable.ts similarity index 91% rename from src/common/catalog-entities/general-catalog-entities/implementations/catalog-catalog-entity.injectable.ts rename to src/common/catalog-entities/general-catalog-entities/implementations/catalog-entity.injectable.ts index 15195a4b74..f5a0b0f314 100644 --- a/src/common/catalog-entities/general-catalog-entities/implementations/catalog-catalog-entity.injectable.ts +++ b/src/common/catalog-entities/general-catalog-entities/implementations/catalog-entity.injectable.ts @@ -8,7 +8,7 @@ import { GeneralEntity } from "../../index"; import { buildURL } from "../../../utils/buildUrl"; import catalogRouteInjectable from "../../../front-end-routing/routes/catalog/catalog-route.injectable"; -const catalogCatalogEntityInjectable = getInjectable({ +const catalogGeneralEntityInjectable = getInjectable({ id: "general-catalog-entity-for-catalog", instantiate: (di) => { @@ -38,4 +38,4 @@ const catalogCatalogEntityInjectable = getInjectable({ injectionToken: generalCatalogEntityInjectionToken, }); -export default catalogCatalogEntityInjectable; +export default catalogGeneralEntityInjectable; diff --git a/src/common/catalog-entities/general-catalog-entities/implementations/preferences-catalog-entity.injectable.ts b/src/common/catalog-entities/general-catalog-entities/implementations/preferences-entity.injectable.ts similarity index 91% rename from src/common/catalog-entities/general-catalog-entities/implementations/preferences-catalog-entity.injectable.ts rename to src/common/catalog-entities/general-catalog-entities/implementations/preferences-entity.injectable.ts index 80d4458b6d..90786da617 100644 --- a/src/common/catalog-entities/general-catalog-entities/implementations/preferences-catalog-entity.injectable.ts +++ b/src/common/catalog-entities/general-catalog-entities/implementations/preferences-entity.injectable.ts @@ -8,7 +8,7 @@ import { GeneralEntity } from "../../index"; import { buildURL } from "../../../utils/buildUrl"; import appPreferencesRouteInjectable from "../../../front-end-routing/routes/preferences/app/app-preferences-route.injectable"; -const preferencesCatalogEntityInjectable = getInjectable({ +const preferencesGeneralEntityInjectable = getInjectable({ id: "general-catalog-entity-for-preferences", instantiate: (di) => { @@ -38,4 +38,4 @@ const preferencesCatalogEntityInjectable = getInjectable({ injectionToken: generalCatalogEntityInjectionToken, }); -export default preferencesCatalogEntityInjectable; +export default preferencesGeneralEntityInjectable; diff --git a/src/common/catalog-entities/general-catalog-entities/implementations/welcome-catalog-entity.injectable.ts b/src/common/catalog-entities/general-catalog-entities/implementations/welcome-entity.injectable.ts similarity index 91% rename from src/common/catalog-entities/general-catalog-entities/implementations/welcome-catalog-entity.injectable.ts rename to src/common/catalog-entities/general-catalog-entities/implementations/welcome-entity.injectable.ts index 363dd73c5f..ea36093e1b 100644 --- a/src/common/catalog-entities/general-catalog-entities/implementations/welcome-catalog-entity.injectable.ts +++ b/src/common/catalog-entities/general-catalog-entities/implementations/welcome-entity.injectable.ts @@ -8,7 +8,7 @@ import { GeneralEntity } from "../../index"; import { buildURL } from "../../../utils/buildUrl"; import welcomeRouteInjectable from "../../../front-end-routing/routes/welcome/welcome-route.injectable"; -const welcomeCatalogEntityInjectable = getInjectable({ +const welcomeGeneralEntityInjectable = getInjectable({ id: "general-catalog-entity-for-welcome", instantiate: (di) => { @@ -38,4 +38,4 @@ const welcomeCatalogEntityInjectable = getInjectable({ injectionToken: generalCatalogEntityInjectionToken, }); -export default welcomeCatalogEntityInjectable; +export default welcomeGeneralEntityInjectable; diff --git a/src/common/cluster-store/cluster-store.ts b/src/common/cluster-store/cluster-store.ts index 36ee383613..4163ad6f76 100644 --- a/src/common/cluster-store/cluster-store.ts +++ b/src/common/cluster-store/cluster-store.ts @@ -9,8 +9,7 @@ import { action, comparer, computed, makeObservable, observable, reaction } from import type { BaseStoreDependencies } from "../base-store"; import { BaseStore } from "../base-store"; import { Cluster } from "../cluster/cluster"; -import logger from "../../main/logger"; -import { appEventBus } from "../app-event-bus/event-bus"; +import type { AppEvent } from "../app-event-bus/event-bus"; import { ipcMainHandle } from "../ipc"; import { disposer, toJS } from "../utils"; import type { ClusterModel, ClusterId, ClusterState } from "../cluster-types"; @@ -19,6 +18,7 @@ import { clusterStates } from "../ipc/cluster"; import type { CreateCluster } from "../cluster/create-cluster-injection-token"; import type { ReadClusterConfigSync } from "./read-cluster-config.injectable"; import type { Migrations } from "conf/dist/source/types"; +import type { EventEmitter } from "../event-emitter"; export interface ClusterStoreModel { clusters?: ClusterModel[]; @@ -28,6 +28,7 @@ interface ClusterStoreDependencies extends BaseStoreDependencies { createCluster: CreateCluster; readClusterConfigSync: ReadClusterConfigSync; readonly migrations: Migrations | undefined; + readonly appEventBus: EventEmitter<[AppEvent]>; } export class ClusterStore extends BaseStore { @@ -52,7 +53,7 @@ export class ClusterStore extends BaseStore { } async loadInitialOnRenderer() { - logger.info("[CLUSTER-STORE] requesting initial state sync"); + this.dependencies.logger.info("[CLUSTER-STORE] requesting initial state sync"); for (const { id, state } of await requestInitialClusterStates()) { this.getById(id)?.setState(state); @@ -77,7 +78,7 @@ export class ClusterStore extends BaseStore { } registerIpcListener() { - logger.info(`[CLUSTER-STORE] start to listen (${webFrame.routingId})`); + this.dependencies.logger.info(`[CLUSTER-STORE] start to listen (${webFrame.routingId})`); const ipc = ipcMain ?? ipcRenderer; ipc?.on("cluster:state", (event, clusterId: ClusterId, state: ClusterState) => { @@ -117,7 +118,7 @@ export class ClusterStore extends BaseStore { } addCluster(clusterOrModel: ClusterModel | Cluster): Cluster { - appEventBus.emit({ name: "cluster", action: "add" }); + this.dependencies.appEventBus.emit({ name: "cluster", action: "add" }); const cluster = clusterOrModel instanceof Cluster ? clusterOrModel @@ -151,7 +152,7 @@ export class ClusterStore extends BaseStore { } newClusters.set(clusterModel.id, cluster); } catch (error) { - logger.warn(`[CLUSTER-STORE]: Failed to update/create a cluster: ${error}`); + this.dependencies.logger.warn(`[CLUSTER-STORE]: Failed to update/create a cluster: ${error}`); } } diff --git a/src/common/hotbars/store.injectable.ts b/src/common/hotbars/store.injectable.ts index 154cc876d7..c57d3a05fd 100644 --- a/src/common/hotbars/store.injectable.ts +++ b/src/common/hotbars/store.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import catalogCatalogEntityInjectable from "../catalog-entities/general-catalog-entities/implementations/catalog-catalog-entity.injectable"; +import catalogGeneralEntityInjectable from "../catalog-entities/general-catalog-entities/implementations/catalog-entity.injectable"; import { HotbarStore } from "./store"; import loggerInjectable from "../logger.injectable"; import appVersionInjectable from "../get-configuration-file-model/app-version/app-version.injectable"; @@ -18,7 +18,7 @@ const hotbarStoreInjectable = getInjectable({ HotbarStore.resetInstance(); return HotbarStore.createInstance({ - catalogCatalogEntity: di.inject(catalogCatalogEntityInjectable), + catalogGeneralEntity: di.inject(catalogGeneralEntityInjectable), migrations: di.inject(hotbarStoreMigrationsInjectionToken), logger: di.inject(loggerInjectable), appVersion: di.inject(appVersionInjectable), diff --git a/src/common/hotbars/store.ts b/src/common/hotbars/store.ts index be3f057468..29944faa6b 100644 --- a/src/common/hotbars/store.ts +++ b/src/common/hotbars/store.ts @@ -23,7 +23,7 @@ export interface HotbarStoreModel { } interface HotbarStoreDependencies extends BaseStoreDependencies { - readonly catalogCatalogEntity: GeneralEntity; + readonly catalogGeneralEntity: GeneralEntity; readonly logger: Logger; readonly migrations: Migrations | undefined; } @@ -88,7 +88,7 @@ export class HotbarStore extends BaseStore { const hotbar = getEmptyHotbar("Default"); const { metadata: { uid, name, source }, - } = this.dependencies.catalogCatalogEntity; + } = this.dependencies.catalogGeneralEntity; const initialItem = { entity: { uid, name, source }}; hotbar.items[0] = initialItem; diff --git a/src/main/migrations/hotbar-store/5.0.0-alpha.0.injectable.ts b/src/main/migrations/hotbar-store/5.0.0-alpha.0.injectable.ts index 88704f8528..62d24a097d 100644 --- a/src/main/migrations/hotbar-store/5.0.0-alpha.0.injectable.ts +++ b/src/main/migrations/hotbar-store/5.0.0-alpha.0.injectable.ts @@ -4,20 +4,20 @@ */ import { getEmptyHotbar } from "../../../common/hotbars/types"; -import catalogCatalogEntityInjectable from "../../../common/catalog-entities/general-catalog-entities/implementations/catalog-catalog-entity.injectable"; +import catalogGeneralEntityInjectable from "../../../common/catalog-entities/general-catalog-entities/implementations/catalog-entity.injectable"; import { getInjectable } from "@ogre-tools/injectable"; import { hotbarStoreMigrationDeclarationInjectionToken } from "./migration"; const hotbarStoreV500Alpha0MigrationInjectable = getInjectable({ id: "hotbar-store-v5.0.0-alpha.0-migration", instantiate: (di) => { - const catalogCatalogEntity = di.inject(catalogCatalogEntityInjectable); + const catalogGeneralEntity = di.inject(catalogGeneralEntityInjectable); return { version: "5.0.0-alpha.0", run(store) { const hotbar = getEmptyHotbar("default"); - const { metadata: { uid, name, source }} = catalogCatalogEntity; + const { metadata: { uid, name, source }} = catalogGeneralEntity; hotbar.items[0] = { entity: { uid, name, source }}; diff --git a/src/main/migrations/hotbar-store/5.0.0-beta.10.injectable.ts b/src/main/migrations/hotbar-store/5.0.0-beta.10.injectable.ts index ebe9240015..53bbab80e4 100644 --- a/src/main/migrations/hotbar-store/5.0.0-beta.10.injectable.ts +++ b/src/main/migrations/hotbar-store/5.0.0-beta.10.injectable.ts @@ -3,17 +3,14 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import fse from "fs-extra"; import { isNull } from "lodash"; -import path from "path"; import * as uuid from "uuid"; import type { ClusterStoreModel } from "../../../common/cluster-store/cluster-store"; import type { Hotbar, HotbarItem } from "../../../common/hotbars/types"; import { defaultHotbarCells, getEmptyHotbar } from "../../../common/hotbars/types"; import { generateNewIdFor } from "../utils"; -import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; -import catalogCatalogEntityInjectable from "../../../common/catalog-entities/general-catalog-entities/implementations/catalog-catalog-entity.injectable"; +import catalogGeneralEntityInjectable from "../../../common/catalog-entities/general-catalog-entities/implementations/catalog-entity.injectable"; import { isDefined, isErrnoException } from "../../../common/utils"; interface Pre500WorkspaceStoreModel { @@ -32,12 +29,17 @@ interface PartialHotbar { import { getInjectable } from "@ogre-tools/injectable"; import migrationLogInjectable from "../log.injectable"; import { hotbarStoreMigrationDeclarationInjectionToken } from "./migration"; +import fsInjectable from "../../../common/fs/fs.injectable"; +import joinPathsInjectable from "../../../common/path/join-paths.injectable"; const hotbarStoreV500Beta10MigrationInjectable = getInjectable({ id: "hotbar-store-v5.0.0-beta.10-migration", instantiate: (di) => { const migrationLog = di.inject(migrationLogInjectable); const userDataPath = di.inject(directoryForUserDataInjectable); + const catalogGeneralEntity = di.inject(catalogGeneralEntityInjectable); + const { readJsonSync } = di.inject(fsInjectable); + const joinPaths = di.inject(joinPathsInjectable); return { version: "5.0.0-beta.10", @@ -49,10 +51,7 @@ const hotbarStoreV500Beta10MigrationInjectable = getInjectable({ if (hotbars.length === 0) { const hotbar = getEmptyHotbar("default"); - const di = getLegacyGlobalDiForExtensionApi(); - const catalogCatalogEntity = di.inject(catalogCatalogEntityInjectable); - - const { metadata: { uid, name, source }} = catalogCatalogEntity; + const { metadata: { uid, name, source }} = catalogGeneralEntity; hotbar.items[0] = { entity: { uid, name, source }}; @@ -60,8 +59,8 @@ const hotbarStoreV500Beta10MigrationInjectable = getInjectable({ } try { - const workspaceStoreData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json")); - const { clusters = [] }: ClusterStoreModel = fse.readJSONSync(path.join(userDataPath, "lens-cluster-store.json")); + const workspaceStoreData: Pre500WorkspaceStoreModel = readJsonSync(joinPaths(userDataPath, "lens-workspace-store.json")); + const { clusters = [] }: ClusterStoreModel = readJsonSync(joinPaths(userDataPath, "lens-cluster-store.json")); const workspaceHotbars = new Map(); // mapping from WorkspaceId to HotBar for (const { id, name } of workspaceStoreData.workspaces) { @@ -130,11 +129,8 @@ const hotbarStoreV500Beta10MigrationInjectable = getInjectable({ */ if (hotbars.every(hotbar => hotbar.items.every(item => item?.entity?.uid !== "catalog-entity"))) { // note, we will add a new whole hotbar here called "default" if that was previously removed - const di = getLegacyGlobalDiForExtensionApi(); - const catalogCatalogEntity = di.inject(catalogCatalogEntityInjectable); - const defaultHotbar = hotbars.find(hotbar => hotbar.name === "default"); - const { metadata: { uid, name, source }} = catalogCatalogEntity; + const { metadata: { uid, name, source }} = catalogGeneralEntity; if (defaultHotbar) { const freeIndex = defaultHotbar.items.findIndex(isNull);