1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-10-06 08:56:16 -04:00
parent ab60f62f01
commit b9effeb740
3 changed files with 19 additions and 15 deletions

View File

@ -25,9 +25,11 @@ import { Pod } from "../../../../common/k8s-api/endpoints";
import { ThemeStore } from "../../../theme.store";
import { dockStore } from "../dock.store";
import { logTabStore } from "../log-tab.store";
import { TerminalStore } from "../terminal.store";
import { deploymentPod1, deploymentPod2, deploymentPod3, dockerPod } from "./pod.mock";
import fse from "fs-extra";
import { mockWindow } from "../../../../../__mocks__/windowMock";
mockWindow();
jest.mock("react-monaco-editor", () => null);
@ -45,7 +47,6 @@ describe("log tab store", () => {
beforeEach(() => {
UserStore.createInstance();
ThemeStore.createInstance();
TerminalStore.createInstance();
});
afterEach(() => {
@ -53,7 +54,6 @@ describe("log tab store", () => {
dockStore.reset();
UserStore.resetInstance();
ThemeStore.resetInstance();
TerminalStore.resetInstance();
fse.remove("tmp");
});
@ -135,18 +135,19 @@ describe("log tab store", () => {
});
// FIXME: this is failed when it's not .only == depends on something above
it.only("closes tab if no pods left in store", () => {
it.only("closes tab if no pods left in store", async () => {
const selectedPod = new Pod(deploymentPod1);
const selectedContainer = selectedPod.getInitContainers()[0];
logTabStore.createPodTab({
const id = logTabStore.createPodTab({
selectedPod,
selectedContainer
});
podsStore.items.clear();
expect(logTabStore.getData(dockStore.selectedTabId)).toBeUndefined();
expect(dockStore.getTabById(dockStore.selectedTabId)).toBeUndefined();
expect(logTabStore.getData(id)).toBeUndefined();
expect(dockStore.getTabById(id)).toBeUndefined();
});
});

View File

@ -21,7 +21,7 @@
import * as uuid from "uuid";
import { action, computed, IReactionOptions, makeObservable, observable, reaction } from "mobx";
import { autoBind, createStorage } from "../../utils";
import { autoBind, createStorage, toJS } from "../../utils";
import throttle from "lodash/throttle";
import {monacoModelsManager} from "./monaco-model-manager";
@ -311,6 +311,8 @@ export class DockStore implements DockStorageState {
this.close();
}
}
console.log(tabId, toJS(this.tabs));
}
closeTabs(tabs: DockTab[]) {

View File

@ -20,7 +20,7 @@
*/
import uniqueId from "lodash/uniqueId";
import { action, reaction } from "mobx";
import { reaction } from "mobx";
import { podsStore } from "../+workloads-pods/pods.store";
import { IPodContainer, Pod } from "../../../common/k8s-api/endpoints";
@ -55,12 +55,12 @@ export class LogTabStore extends DockTabStore<LogTabData> {
reaction(() => podsStore.items.length, () => this.updateTabsData());
}
createPodTab({ selectedPod, selectedContainer }: PodLogsTabData): void {
createPodTab({ selectedPod, selectedContainer }: PodLogsTabData): string {
const podOwner = selectedPod.getOwnerRefs()[0];
const pods = podsStore.getPodsByOwnerId(podOwner?.uid);
const title = `Pod ${selectedPod.getName()}`;
this.createLogsTab(title, {
return this.createLogsTab(title, {
pods: pods.length ? pods : [selectedPod],
selectedPod,
selectedContainer
@ -94,9 +94,9 @@ export class LogTabStore extends DockTabStore<LogTabData> {
...tabParams,
kind: TabKind.POD_LOGS,
}, false);
}
}
private createLogsTab(title: string, data: LogTabData) {
private createLogsTab(title: string, data: LogTabData): string {
const id = uniqueId("log-tab-");
this.createDockTab({ id, title });
@ -105,9 +105,10 @@ export class LogTabStore extends DockTabStore<LogTabData> {
showTimestamps: false,
previous: false
});
return id;
}
@action
private updateTabsData() {
for (const [tabId, tabData] of this.data) {
try {
@ -134,7 +135,7 @@ export class LogTabStore extends DockTabStore<LogTabData> {
this.closeTab(tabId);
}
} catch (error) {
logger.error(`[LOG-TAB-STORE]: failed to set data for tabId=${tabId} deleting`, error, tabData);
logger.error(`[LOG-TAB-STORE]: failed to set data for tabId=${tabId} deleting`, error,);
this.data.delete(tabId);
}
}