1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/dock/logs/create-workload-logs-tab.injectable.ts
Sebastian Malton 595fb90a2a Full dependency inversion of <Dock> and all current tab kinds
- 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>
2022-01-31 09:09:56 -05:00

45 lines
1.5 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 { podsStore } from "../../+workloads-pods/pods.store";
import type { WorkloadKubeObject } from "../../../../common/k8s-api/workload-kube-object";
import { bind } from "../../../utils";
import type { TabId } from "../dock/store";
import createLogsTabInjectable, { CreateLogsTabData } from "./create-logs-tab.injectable";
export interface WorkloadLogsTabData {
workload: WorkloadKubeObject
}
interface Dependencies {
createLogsTab: (title: string, data: CreateLogsTabData) => TabId;
}
function createWorkloadLogsTab({ createLogsTab }: Dependencies, { workload }: WorkloadLogsTabData): TabId | undefined {
const pods = podsStore.getPodsByOwnerId(workload.getId());
if (pods.length === 0) {
return undefined;
}
const selectedPod = pods[0];
return createLogsTab(`${workload.kind} ${selectedPod.getName()}`, {
selectedContainer: selectedPod.getAllContainers()[0].name,
selectedPodId: selectedPod.getId(),
namespace: selectedPod.getNs(),
ownerId: workload.getId(),
});
}
const createWorkloadLogsTabInjectable = getInjectable({
instantiate: (di) => bind(createWorkloadLogsTab, null, {
createLogsTab: di.inject(createLogsTabInjectable),
}),
lifecycle: lifecycleEnum.singleton,
});
export default createWorkloadLogsTabInjectable;