mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
A bit of cleaning up, fixing tests
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
0cd865a0d4
commit
51fb963b93
@ -8,7 +8,7 @@ import { Badge } from "../badge";
|
||||
import { Select, SelectOption } from "../select";
|
||||
import { LogTabData } from "./log-tab.store";
|
||||
import { podsStore } from "../+workloads-pods/pods.store";
|
||||
import { dockStore, TabId } from "./dock.store";
|
||||
import { TabId } from "./dock.store";
|
||||
|
||||
interface Props {
|
||||
tabId: TabId
|
||||
@ -18,7 +18,7 @@ interface Props {
|
||||
}
|
||||
|
||||
export const LogResourceSelector = observer((props: Props) => {
|
||||
const { tabData, save, reload, tabId } = props;
|
||||
const { tabData, save, reload } = props;
|
||||
const { selectedPod, selectedContainer, pods } = tabData;
|
||||
const pod = new Pod(selectedPod);
|
||||
const containers = pod.getContainers();
|
||||
@ -33,14 +33,6 @@ export const LogResourceSelector = observer((props: Props) => {
|
||||
reload();
|
||||
};
|
||||
|
||||
const selectFirstContainer = () => {
|
||||
save({ selectedContainer: pod.getAllContainers()[0] });
|
||||
};
|
||||
|
||||
const renameTab = () => {
|
||||
dockStore.renameTab(tabId, `Pod ${pod.getName()}`);
|
||||
};
|
||||
|
||||
const onPodChange = (option: SelectOption) => {
|
||||
const selectedPod = podsStore.getByName(option.value, pod.getNs());
|
||||
|
||||
@ -75,8 +67,6 @@ export const LogResourceSelector = observer((props: Props) => {
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
selectFirstContainer();
|
||||
renameTab();
|
||||
reload();
|
||||
}, [selectedPod]);
|
||||
|
||||
|
||||
@ -86,33 +86,32 @@ export class LogTabStore extends DockTabStore<LogTabData> {
|
||||
}
|
||||
|
||||
private updateTabsData() {
|
||||
this.data.forEach((value, tabId) => {
|
||||
this.updatePodsData(tabId);
|
||||
this.data.forEach((tabData, 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) {
|
||||
this.setData(tabId, {
|
||||
...tabData,
|
||||
selectedPod,
|
||||
selectedContainer,
|
||||
pods
|
||||
});
|
||||
|
||||
this.renameTab(tabId);
|
||||
} else {
|
||||
this.closeTab(tabId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private updatePodsData(tabId: string) {
|
||||
const tabData = this.getData(tabId);
|
||||
const selectedPod = new Pod(tabData.selectedPod);
|
||||
const owner = selectedPod.getOwnerRefs()[0];
|
||||
const pods = podsStore.getPodsByOwnerId(owner?.uid);
|
||||
let newSelectedPod = selectedPod;
|
||||
private renameTab(tabId: string) {
|
||||
const { selectedPod } = this.getData(tabId);
|
||||
|
||||
if (!pods.length) {
|
||||
this.closeTab(tabId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pods.includes(selectedPod)) {
|
||||
newSelectedPod = pods[0];
|
||||
}
|
||||
|
||||
this.setData(tabId, {
|
||||
...tabData,
|
||||
selectedPod: newSelectedPod,
|
||||
pods
|
||||
});
|
||||
dockStore.renameTab(tabId, `Pod ${selectedPod.metadata.name}`);
|
||||
}
|
||||
|
||||
private closeTab(tabId: string) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user