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
async closeTab(tabId: TabId) {
closeTab(tabId: TabId) {
const tab = this.getTabById(tabId);
if (!tab || tab.pinned) {
@ -326,12 +326,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

@ -25,6 +25,7 @@ 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";
@ -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 pods = podsStore.getPodsByOwnerId(podOwner?.uid);
const title = `Pod ${selectedPod.getName()}`;
this.createLogsTab(title, {
return this.createLogsTab(title, {
pods: pods.length ? pods : [selectedPod],
selectedPod,
selectedContainer
@ -108,7 +109,7 @@ export class LogTabStore extends DockTabStore<LogTabData> {
}, false);
}
private createLogsTab(title: string, data: LogTabData) {
private createLogsTab(title: string, data: LogTabData): string {
const id = uniqueId("log-tab-");
this.createDockTab({ id, title });
@ -117,28 +118,46 @@ export class LogTabStore extends DockTabStore<LogTabData> {
showTimestamps: false,
previous: false
});
return id;
}
private updateTabsData() {
for (const [tabId, tabData] of Object.entries(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
});
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];
this.renameTab(tabId);
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,);
this.clearData(tabId);
}
}
}
private closeTab(tabId: string) {
this.clearData(tabId);
dockStore.closeTab(tabId);
}
}
export const logTabStore = new LogTabStore();