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

fix edit-resource/store.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-04-12 14:40:53 -04:00
parent 5382dc0290
commit 0066ea6321
2 changed files with 11 additions and 12 deletions

View File

@ -5,12 +5,14 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { EditResourceTabStore } from "./store"; import { EditResourceTabStore } from "./store";
import createStorageInjectable from "../../../utils/create-storage/create-storage.injectable"; import createStorageInjectable from "../../../utils/create-storage/create-storage.injectable";
import apiManagerInjectable from "../../../../common/k8s-api/api-manager/manager.injectable";
const editResourceTabStoreInjectable = getInjectable({ const editResourceTabStoreInjectable = getInjectable({
id: "edit-resource-tab-store", id: "edit-resource-tab-store",
instantiate: (di) => new EditResourceTabStore({ instantiate: (di) => new EditResourceTabStore({
createStorage: di.inject(createStorageInjectable), createStorage: di.inject(createStorageInjectable),
apiManager: di.inject(apiManagerInjectable),
}), }),
}); });

View File

@ -3,12 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { StorageHelper } from "../../../utils"; import type { DockTabStoreDependencies } from "../dock-tab-store/dock-tab.store";
import type { DockTabStorageState } from "../dock-tab-store/dock-tab.store";
import { DockTabStore } from "../dock-tab-store/dock-tab.store"; import { DockTabStore } from "../dock-tab-store/dock-tab.store";
import type { TabId } from "../dock/store"; import type { TabId } from "../dock/store";
import type { KubeObject } from "../../../../common/k8s-api/kube-object"; import type { KubeObject } from "../../../../common/k8s-api/kube-object";
import { apiManager } from "../../../../common/k8s-api/api-manager"; import type { ApiManager } from "../../../../common/k8s-api/api-manager";
import type { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; import type { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store";
export interface EditingResource { export interface EditingResource {
@ -17,12 +16,12 @@ export interface EditingResource {
firstDraft?: string; firstDraft?: string;
} }
interface Dependencies { export interface EditResourceTabStoreDependencies extends DockTabStoreDependencies {
createStorage:<T> (storageKey: string, options: DockTabStorageState<T>) => StorageHelper<DockTabStorageState<T>>; readonly apiManager: ApiManager;
} }
export class EditResourceTabStore extends DockTabStore<EditingResource> { export class EditResourceTabStore extends DockTabStore<EditingResource> {
constructor(protected dependencies: Dependencies) { constructor(protected readonly dependencies: EditResourceTabStoreDependencies) {
super(dependencies, { super(dependencies, {
storageKey: "edit_resource_store", storageKey: "edit_resource_store",
}); });
@ -40,18 +39,16 @@ export class EditResourceTabStore extends DockTabStore<EditingResource> {
const apiPath = this.getResourcePath(tabId); const apiPath = this.getResourcePath(tabId);
return apiPath return apiPath
? apiManager.getStore(apiPath) ? this.dependencies.apiManager.getStore(apiPath)
: undefined; : undefined;
} }
getResource(tabId: TabId): KubeObject | undefined { getResource(tabId: TabId): KubeObject | undefined {
const apiPath = this.getResourcePath(tabId); const apiPath = this.getResourcePath(tabId);
if (apiPath) { return apiPath
return apiManager.getStore(apiPath)?.getByPath(apiPath); ? this.dependencies.apiManager.getStore(apiPath)?.getByPath(apiPath)
} : undefined;
return undefined;
} }
getResourcePath(tabId: TabId): string | undefined { getResourcePath(tabId: TabId): string | undefined {