mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
- Fixes pod logs not working on initial load - Removes DockStore as a dependency of all *TabStore - Removes all the reactions about loading new data from the stores - Removes dependencies on selectedTabId from all *TabStore's Signed-off-by: Sebastian Malton <sebastian@malton.name>
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
|
import editResourceTabStoreInjectable from "./store.injectable";
|
|
import dockStoreInjectable from "../dock/store.injectable";
|
|
import type { KubeObject } from "../../../../common/k8s-api/kube-object";
|
|
import { DockStore, DockTabCreateSpecific, TabId, TabKind } from "../dock/store";
|
|
import type { EditResourceTabStore } from "./store";
|
|
import { bind } from "../../../utils";
|
|
import { runInAction } from "mobx";
|
|
|
|
interface Dependencies {
|
|
dockStore: DockStore;
|
|
editResourceStore: EditResourceTabStore;
|
|
}
|
|
|
|
function createEditResourceTab({ dockStore, editResourceStore }: Dependencies, object: KubeObject, tabParams: DockTabCreateSpecific = {}): TabId {
|
|
// use existing tab if already opened
|
|
const tabId = editResourceStore.getTabIdByResource(object);
|
|
|
|
if (tabId) {
|
|
dockStore.open();
|
|
dockStore.selectTab(tabId);
|
|
|
|
return tabId;
|
|
}
|
|
|
|
return runInAction(() => {
|
|
const tab = dockStore.createTab(
|
|
{
|
|
title: `${object.kind}: ${object.getName()}`,
|
|
...tabParams,
|
|
kind: TabKind.EDIT_RESOURCE,
|
|
},
|
|
false,
|
|
);
|
|
|
|
editResourceStore.setData(tab.id, {
|
|
resource: object.selfLink,
|
|
});
|
|
|
|
return tab.id;
|
|
});
|
|
}
|
|
|
|
const createEditResourceTabInjectable = getInjectable({
|
|
instantiate: (di) => bind(createEditResourceTab, null, {
|
|
dockStore: di.inject(dockStoreInjectable),
|
|
editResourceStore: di.inject(editResourceTabStoreInjectable),
|
|
}),
|
|
|
|
lifecycle: lifecycleEnum.singleton,
|
|
});
|
|
|
|
export default createEditResourceTabInjectable;
|