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

Catch errors and remove tabs if failed to build log tab

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-10-05 17:02:26 -04:00
parent f3e32eaf70
commit ab60f62f01
2 changed files with 33 additions and 34 deletions

View File

@ -287,7 +287,7 @@ export class DockStore implements DockStorageState {
}
@action
async closeTab(tabId: TabId) {
closeTab(tabId: TabId) {
const tab = this.getTabById(tabId);
if (!tab || tab.pinned) {
@ -305,12 +305,6 @@ export class DockStore implements DockStorageState {
if (this.tabs.length) {
const newTab = this.tabs.slice(-1)[0]; // last
if (newTab?.kind === TabKind.TERMINAL) {
// close the dock when selected sibling inactive terminal tab
const { TerminalStore } = await import("./terminal.store");
if (!TerminalStore.getInstance(false)?.isConnected(newTab.id)) this.close();
}
this.selectTab(newTab.id);
} else {
this.selectedTabId = null;

View File

@ -20,11 +20,12 @@
*/
import uniqueId from "lodash/uniqueId";
import { reaction } from "mobx";
import { action, reaction } from "mobx";
import { podsStore } from "../+workloads-pods/pods.store";
import { IPodContainer, Pod } from "../../../common/k8s-api/endpoints";
import type { WorkloadKubeObject } from "../../../common/k8s-api/workload-kube-object";
import logger from "../../../common/logger";
import { DockTabStore } from "./dock-tab.store";
import { dockStore, DockTabCreateSpecific, TabKind } from "./dock.store";
@ -51,9 +52,7 @@ export class LogTabStore extends DockTabStore<LogTabData> {
storageKey: "pod_logs"
});
reaction(() => podsStore.items.length, () => {
this.updateTabsData();
});
reaction(() => podsStore.items.length, () => this.updateTabsData());
}
createPodTab({ selectedPod, selectedContainer }: PodLogsTabData): void {
@ -108,36 +107,42 @@ export class LogTabStore extends DockTabStore<LogTabData> {
});
}
private async updateTabsData() {
const promises: Promise<void>[] = [];
@action
private updateTabsData() {
for (const [tabId, tabData] of this.data) {
const pod = new Pod(tabData.selectedPod);
const pods = podsStore.getPodsByOwnerId(pod.getOwnerRefs()[0]?.uid);
const isSelectedPodInList = pods.find(item => item.getId() == pod.getId());
const selectedPod = isSelectedPodInList ? pod : pods[0];
const selectedContainer = isSelectedPodInList ? tabData.selectedContainer : pod.getAllContainers()[0];
try {
if (!tabData.selectedPod) {
tabData.selectedPod = tabData.pods[0];
}
if (pods.length) {
this.setData(tabId, {
...tabData,
selectedPod,
selectedContainer,
pods
});
this.renameTab(tabId);
} else {
promises.push(this.closeTab(tabId));
const pod = new Pod(tabData.selectedPod);
const pods = podsStore.getPodsByOwnerId(pod.getOwnerRefs()[0]?.uid);
const isSelectedPodInList = pods.find(item => item.getId() == pod.getId());
const selectedPod = isSelectedPodInList ? pod : pods[0];
const selectedContainer = isSelectedPodInList ? tabData.selectedContainer : pod.getAllContainers()[0];
if (pods.length > 0) {
this.setData(tabId, {
...tabData,
selectedPod,
selectedContainer,
pods
});
this.renameTab(tabId);
} else {
this.closeTab(tabId);
}
} catch (error) {
logger.error(`[LOG-TAB-STORE]: failed to set data for tabId=${tabId} deleting`, error, tabData);
this.data.delete(tabId);
}
}
await Promise.all(promises);
}
private async closeTab(tabId: string) {
private closeTab(tabId: string) {
this.clearData(tabId);
await dockStore.closeTab(tabId);
dockStore.closeTab(tabId);
}
}