1
0
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:
Alex Andreev 2021-01-25 16:07:58 +03:00
parent 0cd865a0d4
commit 51fb963b93
2 changed files with 24 additions and 35 deletions

View File

@ -8,7 +8,7 @@ import { Badge } from "../badge";
import { Select, SelectOption } from "../select"; import { Select, SelectOption } from "../select";
import { LogTabData } from "./log-tab.store"; import { LogTabData } from "./log-tab.store";
import { podsStore } from "../+workloads-pods/pods.store"; import { podsStore } from "../+workloads-pods/pods.store";
import { dockStore, TabId } from "./dock.store"; import { TabId } from "./dock.store";
interface Props { interface Props {
tabId: TabId tabId: TabId
@ -18,7 +18,7 @@ interface Props {
} }
export const LogResourceSelector = observer((props: Props) => { export const LogResourceSelector = observer((props: Props) => {
const { tabData, save, reload, tabId } = props; const { tabData, save, reload } = props;
const { selectedPod, selectedContainer, pods } = tabData; const { selectedPod, selectedContainer, pods } = tabData;
const pod = new Pod(selectedPod); const pod = new Pod(selectedPod);
const containers = pod.getContainers(); const containers = pod.getContainers();
@ -33,14 +33,6 @@ export const LogResourceSelector = observer((props: Props) => {
reload(); reload();
}; };
const selectFirstContainer = () => {
save({ selectedContainer: pod.getAllContainers()[0] });
};
const renameTab = () => {
dockStore.renameTab(tabId, `Pod ${pod.getName()}`);
};
const onPodChange = (option: SelectOption) => { const onPodChange = (option: SelectOption) => {
const selectedPod = podsStore.getByName(option.value, pod.getNs()); const selectedPod = podsStore.getByName(option.value, pod.getNs());
@ -75,8 +67,6 @@ export const LogResourceSelector = observer((props: Props) => {
]; ];
useEffect(() => { useEffect(() => {
selectFirstContainer();
renameTab();
reload(); reload();
}, [selectedPod]); }, [selectedPod]);

View File

@ -86,33 +86,32 @@ export class LogTabStore extends DockTabStore<LogTabData> {
} }
private updateTabsData() { private updateTabsData() {
this.data.forEach((value, tabId) => { this.data.forEach((tabData, tabId) => {
this.updatePodsData(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) { private renameTab(tabId: string) {
const tabData = this.getData(tabId); const { selectedPod } = this.getData(tabId);
const selectedPod = new Pod(tabData.selectedPod);
const owner = selectedPod.getOwnerRefs()[0];
const pods = podsStore.getPodsByOwnerId(owner?.uid);
let newSelectedPod = selectedPod;
if (!pods.length) { dockStore.renameTab(tabId, `Pod ${selectedPod.metadata.name}`);
this.closeTab(tabId);
return;
}
if (!pods.includes(selectedPod)) {
newSelectedPod = pods[0];
}
this.setData(tabId, {
...tabData,
selectedPod: newSelectedPod,
pods
});
} }
private closeTab(tabId: string) { private closeTab(tabId: string) {