1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/extensions/pod-menu/src/logs-menu.tsx
Alex Andreev a157eb03e6
Generic logs view with Pod selector (#1984)
* Adding LogTabStore

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding Pod selector in logs tab

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Refresh containers on pod change

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding <LogResourceSelector /> tests

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding LogTabStore tests

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Clearn getPodsByOwnerId method

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Extracting dummy pods into mock file

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Eliminating containers and initContainers from store

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Refreshing tab pods if pod amount is changed in store

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* A bit of cleaning up, fixing tests

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Fix lint newline errors

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Return getPodsByOwner() method

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Rename log tab when pod changes

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
2021-01-27 17:20:02 +03:00

58 lines
1.9 KiB
TypeScript

import React from "react";
import { Component, K8sApi, Util, Navigation } from "@k8slens/extensions";
export interface PodLogsMenuProps extends Component.KubeObjectMenuProps<K8sApi.Pod> {
}
export class PodLogsMenu extends React.Component<PodLogsMenuProps> {
showLogs(container: K8sApi.IPodContainer) {
Navigation.hideDetails();
const pod = this.props.object;
Component.logTabStore.createPodTab({
selectedPod: pod,
selectedContainer: container,
});
}
render() {
const { object: pod, toolbar } = this.props;
const containers = pod.getAllContainers();
const statuses = pod.getContainerStatuses();
if (!containers.length) return null;
return (
<Component.MenuItem onClick={Util.prevDefault(() => this.showLogs(containers[0]))}>
<Component.Icon material="subject" title="Logs" interactive={toolbar}/>
<span className="title">Logs</span>
{containers.length > 1 && (
<>
<Component.Icon className="arrow" material="keyboard_arrow_right"/>
<Component.SubMenu>
{
containers.map(container => {
const { name } = container;
const status = statuses.find(status => status.name === name);
const brick = status ? (
<Component.StatusBrick
className={Util.cssNames(Object.keys(status.state)[0], { ready: status.ready })}
/>
) : null;
return (
<Component.MenuItem key={name} onClick={Util.prevDefault(() => this.showLogs(container))} className="flex align-center">
{brick}
<span>{name}</span>
</Component.MenuItem>
);
})
}
</Component.SubMenu>
</>
)}
</Component.MenuItem>
);
}
}