mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Full dependency inversion of <Dock> and all current tab kinds (#4757)
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Co-authored-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
152 files changed
+3423
-2617
No files matched your search
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 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 { DockTabCreate, DockTab, TabKind, TabId } from "../dock/store";
|
||||
import type { LogTabData } from "./tab-store";
|
||||
import * as uuid from "uuid";
|
||||
import { runInAction } from "mobx";
|
||||
import createDockTabInjectable from "../dock/create-dock-tab.injectable";
|
||||
import setLogTabDataInjectable from "./set-log-tab-data.injectable";
|
||||
|
||||
export type CreateLogsTabData = Pick<LogTabData, "owner" | "selectedPodId" | "selectedContainer" | "namespace"> & Omit<Partial<LogTabData>, "owner" | "selectedPodId" | "selectedContainer" | "namespace">;
|
||||
|
||||
interface Dependencies {
|
||||
createDockTab: (rawTabDesc: DockTabCreate, addNumber?: boolean) => DockTab;
|
||||
setLogTabData: (tabId: string, data: LogTabData) => void;
|
||||
}
|
||||
|
||||
const createLogsTab = ({ createDockTab, setLogTabData }: Dependencies) => (title: string, data: CreateLogsTabData): TabId => {
|
||||
const id = `log-tab-${uuid.v4()}`;
|
||||
|
||||
runInAction(() => {
|
||||
createDockTab({
|
||||
id,
|
||||
title,
|
||||
kind: TabKind.POD_LOGS,
|
||||
}, false);
|
||||
setLogTabData(id, {
|
||||
showTimestamps: false,
|
||||
showPrevious: false,
|
||||
...data,
|
||||
});
|
||||
});
|
||||
|
||||
return id;
|
||||
};
|
||||
|
||||
const createLogsTabInjectable = getInjectable({
|
||||
instantiate: (di) => createLogsTab({
|
||||
createDockTab: di.inject(createDockTabInjectable),
|
||||
setLogTabData: di.inject(setLogTabDataInjectable),
|
||||
}),
|
||||
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default createLogsTabInjectable;
|
||||
Reference in new issue
Block a user