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

Eliminating containers and initContainers from store

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-01-20 11:32:40 +03:00
parent e1c4588156
commit 355fbc9134
4 changed files with 10 additions and 36 deletions

View File

@ -30,8 +30,6 @@ const getOnePodTabData = (): LogTabData => {
pods: [] as Pod[], pods: [] as Pod[],
selectedPod, selectedPod,
selectedContainer: selectedPod.getContainers()[0], selectedContainer: selectedPod.getContainers()[0],
containers: selectedPod.getContainers(),
initContainers: selectedPod.getInitContainers(),
}; };
}; };
@ -43,8 +41,6 @@ const getFewPodsTabData = (): LogTabData => {
pods: [anotherPod], pods: [anotherPod],
selectedPod, selectedPod,
selectedContainer: selectedPod.getContainers()[0], selectedContainer: selectedPod.getContainers()[0],
containers: selectedPod.getContainers(),
initContainers: selectedPod.getInitContainers(),
}; };
}; };

View File

@ -32,8 +32,6 @@ describe("log tab store", () => {
pods: [selectedPod], pods: [selectedPod],
selectedPod, selectedPod,
selectedContainer, selectedContainer,
containers: selectedPod.getContainers(),
initContainers: [],
showTimestamps: false, showTimestamps: false,
previous: false previous: false
}); });
@ -53,8 +51,6 @@ describe("log tab store", () => {
pods: [selectedPod, siblingPod], pods: [selectedPod, siblingPod],
selectedPod, selectedPod,
selectedContainer, selectedContainer,
containers: selectedPod.getContainers(),
initContainers: selectedPod.getInitContainers(),
showTimestamps: false, showTimestamps: false,
previous: false previous: false
}); });

View File

@ -19,8 +19,10 @@ interface Props {
export const LogResourceSelector = observer((props: Props) => { export const LogResourceSelector = observer((props: Props) => {
const { tabData, save, reload, tabId } = props; const { tabData, save, reload, tabId } = props;
const { selectedPod, selectedContainer, containers, initContainers, pods } = tabData; const { selectedPod, selectedContainer, pods } = tabData;
const pod = new Pod(selectedPod); const pod = new Pod(selectedPod);
const containers = pod.getContainers();
const initContainers = pod.getInitContainers();
const onContainerChange = (option: SelectOption) => { const onContainerChange = (option: SelectOption) => {
save({ save({
@ -38,13 +40,9 @@ export const LogResourceSelector = observer((props: Props) => {
return; return;
} }
const { getContainers, getInitContainers, getAllContainers } = selectedPod;
save({ save({
selectedPod, selectedPod,
containers: getContainers(), selectedContainer: selectedPod.getAllContainers()[0]
initContainers: getInitContainers(),
selectedContainer: getAllContainers()[0]
}); });
dockStore.renameTab(tabId, `Pod ${option.value}`); dockStore.renameTab(tabId, `Pod ${option.value}`);

View File

@ -4,14 +4,12 @@ import { podsStore } from "../+workloads-pods/pods.store";
import { IPodContainer, Pod } from "../../api/endpoints"; import { IPodContainer, Pod } from "../../api/endpoints";
import { WorkloadKubeObject } from "../../api/workload-kube-object"; import { WorkloadKubeObject } from "../../api/workload-kube-object";
import { DockTabStore } from "./dock-tab.store"; import { DockTabStore } from "./dock-tab.store";
import { dockStore, IDockTab, TabId, TabKind } from "./dock.store"; import { dockStore, IDockTab, TabKind } from "./dock.store";
export interface LogTabData { export interface LogTabData {
pods: Pod[]; pods: Pod[];
selectedPod: Pod; selectedPod: Pod;
selectedContainer: IPodContainer selectedContainer: IPodContainer
containers?: IPodContainer[]
initContainers?: IPodContainer[]
showTimestamps?: boolean showTimestamps?: boolean
previous?: boolean previous?: boolean
} }
@ -67,29 +65,15 @@ export class LogTabStore extends DockTabStore<LogTabData> {
}, false); }, false);
} }
private saveControlsData(id: TabId, data: LogTabData) {
this.setData(id, data);
}
private addBasicControlsData(data: LogTabData): LogTabData {
const containers = data.selectedPod.getContainers();
const initContainers = data.selectedPod.getInitContainers();
return {
...data,
containers,
initContainers,
showTimestamps: false,
previous: false
};
}
private createLogsTab(title: string, data: LogTabData) { private createLogsTab(title: string, data: LogTabData) {
const id = uniqueId("log-tab-"); const id = uniqueId("log-tab-");
const fullData = this.addBasicControlsData(data);
this.createDockTab({ id, title }); this.createDockTab({ id, title });
this.saveControlsData(id, fullData); this.setData(id, {
...data,
showTimestamps: false,
previous: false
});
} }
} }