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:
parent
f3e32eaf70
commit
ab60f62f01
@ -287,7 +287,7 @@ export class DockStore implements DockStorageState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async closeTab(tabId: TabId) {
|
closeTab(tabId: TabId) {
|
||||||
const tab = this.getTabById(tabId);
|
const tab = this.getTabById(tabId);
|
||||||
|
|
||||||
if (!tab || tab.pinned) {
|
if (!tab || tab.pinned) {
|
||||||
@ -305,12 +305,6 @@ export class DockStore implements DockStorageState {
|
|||||||
if (this.tabs.length) {
|
if (this.tabs.length) {
|
||||||
const newTab = this.tabs.slice(-1)[0]; // last
|
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);
|
this.selectTab(newTab.id);
|
||||||
} else {
|
} else {
|
||||||
this.selectedTabId = null;
|
this.selectedTabId = null;
|
||||||
|
|||||||
@ -20,11 +20,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import uniqueId from "lodash/uniqueId";
|
import uniqueId from "lodash/uniqueId";
|
||||||
import { reaction } from "mobx";
|
import { action, reaction } from "mobx";
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
|
|
||||||
import { IPodContainer, Pod } from "../../../common/k8s-api/endpoints";
|
import { IPodContainer, Pod } from "../../../common/k8s-api/endpoints";
|
||||||
import type { WorkloadKubeObject } from "../../../common/k8s-api/workload-kube-object";
|
import type { WorkloadKubeObject } from "../../../common/k8s-api/workload-kube-object";
|
||||||
|
import logger from "../../../common/logger";
|
||||||
import { DockTabStore } from "./dock-tab.store";
|
import { DockTabStore } from "./dock-tab.store";
|
||||||
import { dockStore, DockTabCreateSpecific, TabKind } from "./dock.store";
|
import { dockStore, DockTabCreateSpecific, TabKind } from "./dock.store";
|
||||||
|
|
||||||
@ -51,9 +52,7 @@ export class LogTabStore extends DockTabStore<LogTabData> {
|
|||||||
storageKey: "pod_logs"
|
storageKey: "pod_logs"
|
||||||
});
|
});
|
||||||
|
|
||||||
reaction(() => podsStore.items.length, () => {
|
reaction(() => podsStore.items.length, () => this.updateTabsData());
|
||||||
this.updateTabsData();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createPodTab({ selectedPod, selectedContainer }: PodLogsTabData): void {
|
createPodTab({ selectedPod, selectedContainer }: PodLogsTabData): void {
|
||||||
@ -108,36 +107,42 @@ export class LogTabStore extends DockTabStore<LogTabData> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateTabsData() {
|
@action
|
||||||
const promises: Promise<void>[] = [];
|
private updateTabsData() {
|
||||||
|
|
||||||
for (const [tabId, tabData] of this.data) {
|
for (const [tabId, tabData] of this.data) {
|
||||||
const pod = new Pod(tabData.selectedPod);
|
try {
|
||||||
const pods = podsStore.getPodsByOwnerId(pod.getOwnerRefs()[0]?.uid);
|
if (!tabData.selectedPod) {
|
||||||
const isSelectedPodInList = pods.find(item => item.getId() == pod.getId());
|
tabData.selectedPod = tabData.pods[0];
|
||||||
const selectedPod = isSelectedPodInList ? pod : pods[0];
|
}
|
||||||
const selectedContainer = isSelectedPodInList ? tabData.selectedContainer : pod.getAllContainers()[0];
|
|
||||||
|
|
||||||
if (pods.length) {
|
const pod = new Pod(tabData.selectedPod);
|
||||||
this.setData(tabId, {
|
const pods = podsStore.getPodsByOwnerId(pod.getOwnerRefs()[0]?.uid);
|
||||||
...tabData,
|
const isSelectedPodInList = pods.find(item => item.getId() == pod.getId());
|
||||||
selectedPod,
|
const selectedPod = isSelectedPodInList ? pod : pods[0];
|
||||||
selectedContainer,
|
const selectedContainer = isSelectedPodInList ? tabData.selectedContainer : pod.getAllContainers()[0];
|
||||||
pods
|
|
||||||
});
|
if (pods.length > 0) {
|
||||||
|
this.setData(tabId, {
|
||||||
this.renameTab(tabId);
|
...tabData,
|
||||||
} else {
|
selectedPod,
|
||||||
promises.push(this.closeTab(tabId));
|
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);
|
this.clearData(tabId);
|
||||||
await dockStore.closeTab(tabId);
|
dockStore.closeTab(tabId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user