1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Resolve PR comments

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-07-08 13:04:07 -04:00
parent 9e72f90393
commit dade4eba52
10 changed files with 43 additions and 46 deletions

View File

@ -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);

View File

@ -40,7 +40,7 @@ export abstract class BaseStore<T> extends Singleton {
readonly displayName: string = this.constructor.name;
protected constructor(protected readonly depenendices: BaseStoreDependencies, protected params: BaseStoreParams<T>) {
protected constructor(protected readonly dependencies: BaseStoreDependencies, protected params: BaseStoreParams<T>) {
super();
makeObservable(this);
}
@ -49,22 +49,22 @@ export abstract class BaseStore<T> 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<T>'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<T>'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<T> 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<T> 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);
}));
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<ClusterStoreModel> | undefined;
readonly appEventBus: EventEmitter<[AppEvent]>;
}
export class ClusterStore extends BaseStore<ClusterStoreModel> {
@ -52,7 +53,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
}
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<ClusterStoreModel> {
}
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<ClusterStoreModel> {
}
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<ClusterStoreModel> {
}
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}`);
}
}

View File

@ -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),

View File

@ -23,7 +23,7 @@ export interface HotbarStoreModel {
}
interface HotbarStoreDependencies extends BaseStoreDependencies {
readonly catalogCatalogEntity: GeneralEntity;
readonly catalogGeneralEntity: GeneralEntity;
readonly logger: Logger;
readonly migrations: Migrations<HotbarStoreModel> | undefined;
}
@ -88,7 +88,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
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;

View File

@ -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 }};

View File

@ -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<string, PartialHotbar>(); // 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);