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

reverted incorrect merge for Catch metadata being undefined at KubeObject creation (#3960)

(cherry picked from commit 913244b204)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-10-07 17:09:21 +03:00
parent c1025fe1ba
commit 98244ec95c
2 changed files with 36 additions and 23 deletions

View File

@ -313,7 +313,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) {
@ -326,12 +326,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;

View File

@ -25,6 +25,7 @@ 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";
@ -67,12 +68,12 @@ export class LogTabStore extends DockTabStore<LogTabData> {
); );
} }
createPodTab({ selectedPod, selectedContainer }: PodLogsTabData): void { createPodTab({ selectedPod, selectedContainer }: PodLogsTabData): string {
const podOwner = selectedPod.getOwnerRefs()[0]; const podOwner = selectedPod.getOwnerRefs()[0];
const pods = podsStore.getPodsByOwnerId(podOwner?.uid); const pods = podsStore.getPodsByOwnerId(podOwner?.uid);
const title = `Pod ${selectedPod.getName()}`; const title = `Pod ${selectedPod.getName()}`;
this.createLogsTab(title, { return this.createLogsTab(title, {
pods: pods.length ? pods : [selectedPod], pods: pods.length ? pods : [selectedPod],
selectedPod, selectedPod,
selectedContainer selectedContainer
@ -108,7 +109,7 @@ export class LogTabStore extends DockTabStore<LogTabData> {
}, false); }, false);
} }
private createLogsTab(title: string, data: LogTabData) { private createLogsTab(title: string, data: LogTabData): string {
const id = uniqueId("log-tab-"); const id = uniqueId("log-tab-");
this.createDockTab({ id, title }); this.createDockTab({ id, title });
@ -117,17 +118,24 @@ export class LogTabStore extends DockTabStore<LogTabData> {
showTimestamps: false, showTimestamps: false,
previous: false previous: false
}); });
return id;
} }
private updateTabsData() { private updateTabsData() {
for (const [tabId, tabData] of Object.entries(this.data)) { for (const [tabId, tabData] of Object.entries(this.data)) {
try {
if (!tabData.selectedPod) {
tabData.selectedPod = tabData.pods[0];
}
const pod = new Pod(tabData.selectedPod); const pod = new Pod(tabData.selectedPod);
const pods = podsStore.getPodsByOwnerId(pod.getOwnerRefs()[0]?.uid); const pods = podsStore.getPodsByOwnerId(pod.getOwnerRefs()[0]?.uid);
const isSelectedPodInList = pods.find(item => item.getId() == pod.getId()); const isSelectedPodInList = pods.find(item => item.getId() == pod.getId());
const selectedPod = isSelectedPodInList ? pod : pods[0]; const selectedPod = isSelectedPodInList ? pod : pods[0];
const selectedContainer = isSelectedPodInList ? tabData.selectedContainer : pod.getAllContainers()[0]; const selectedContainer = isSelectedPodInList ? tabData.selectedContainer : pod.getAllContainers()[0];
if (pods.length) { if (pods.length > 0) {
this.setData(tabId, { this.setData(tabId, {
...tabData, ...tabData,
selectedPod, selectedPod,
@ -136,9 +144,20 @@ export class LogTabStore extends DockTabStore<LogTabData> {
}); });
this.renameTab(tabId); this.renameTab(tabId);
} else {
this.closeTab(tabId);
}
} catch (error) {
logger.error(`[LOG-TAB-STORE]: failed to set data for tabId=${tabId} deleting`, error,);
this.clearData(tabId);
} }
} }
} }
private closeTab(tabId: string) {
this.clearData(tabId);
dockStore.closeTab(tabId);
}
} }
export const logTabStore = new LogTabStore(); export const logTabStore = new LogTabStore();