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

Adding Pod selector in logs tab

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-01-18 13:57:06 +03:00
parent 3ed0173d48
commit 99f70f3401
3 changed files with 46 additions and 24 deletions

View File

@ -5,22 +5,23 @@ import { observer } from "mobx-react";
import { Pod } from "../../api/endpoints"; import { Pod } from "../../api/endpoints";
import { cssNames, saveFileDialog } from "../../utils"; import { cssNames, saveFileDialog } from "../../utils";
import { IPodLogsData, podLogsStore } from "./log.store"; import { logStore } from "./log.store";
import { Checkbox } from "../checkbox"; import { Checkbox } from "../checkbox";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { LogTabData } from "./log-tab.store";
interface Props { interface Props {
tabData: IPodLogsData tabData: LogTabData
logs: string[] logs: string[]
save: (data: Partial<IPodLogsData>) => void save: (data: Partial<LogTabData>) => void
reload: () => void reload: () => void
} }
export const LogControls = observer((props: Props) => { export const LogControls = observer((props: Props) => {
const { tabData, save, reload, logs } = props; const { tabData, save, reload, logs } = props;
const { showTimestamps, previous } = tabData; const { showTimestamps, previous } = tabData;
const since = logs.length ? podLogsStore.getTimestamps(logs[0]) : null; const since = logs.length ? logStore.getTimestamps(logs[0]) : null;
const pod = new Pod(tabData.pod); const pod = new Pod(tabData.selectedPod);
const toggleTimestamps = () => { const toggleTimestamps = () => {
save({ showTimestamps: !showTimestamps }); save({ showTimestamps: !showTimestamps });
@ -33,7 +34,7 @@ export const LogControls = observer((props: Props) => {
const downloadLogs = () => { const downloadLogs = () => {
const fileName = pod.getName(); const fileName = pod.getName();
const logsToDownload = showTimestamps ? logs : podLogsStore.logsWithoutTimestamps; const logsToDownload = showTimestamps ? logs : logStore.logsWithoutTimestamps;
saveFileDialog(`${fileName}.log`, logsToDownload.join("\n"), "text/plain"); saveFileDialog(`${fileName}.log`, logsToDownload.join("\n"), "text/plain");
}; };

View File

@ -14,7 +14,8 @@ import { Button } from "../button";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { Spinner } from "../spinner"; import { Spinner } from "../spinner";
import { VirtualList } from "../virtual-list"; import { VirtualList } from "../virtual-list";
import { podLogsStore } from "./log.store"; import { logStore } from "./log.store";
import { logTabStore } from "./log-tab.store";
interface Props { interface Props {
logs: string[] logs: string[]
@ -77,10 +78,10 @@ export class LogList extends React.Component<Props> {
*/ */
@computed @computed
get logs() { get logs() {
const showTimestamps = podLogsStore.getData(this.props.id).showTimestamps; const showTimestamps = logTabStore.getData(this.props.id).showTimestamps;
if (!showTimestamps) { if (!showTimestamps) {
return podLogsStore.logsWithoutTimestamps; return logStore.logsWithoutTimestamps;
} }
return this.props.logs; return this.props.logs;

View File

@ -3,25 +3,24 @@ import "./log-resource-selector.scss";
import React from "react"; import React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { IPodContainer, Pod } from "../../api/endpoints"; import { Pod } from "../../api/endpoints";
import { Badge } from "../badge"; import { Badge } from "../badge";
import { Select, SelectOption } from "../select"; import { Select, SelectOption } from "../select";
import { IPodLogsData } from "./log.store"; import { LogTabData } from "./log-tab.store";
import { podsStore } from "../+workloads-pods/pods.store";
interface Props { interface Props {
tabData: IPodLogsData tabData: LogTabData
save: (data: Partial<IPodLogsData>) => void save: (data: Partial<LogTabData>) => void
reload: () => void reload: () => void
} }
export const LogResourceSelector = observer((props: Props) => { export const LogResourceSelector = observer((props: Props) => {
const { tabData, save, reload } = props; const { tabData, save, reload } = props;
const { selectedContainer, containers, initContainers } = tabData; const { selectedPod, selectedContainer, containers, initContainers, pods } = tabData;
const pod = new Pod(tabData.pod); const pod = new Pod(tabData.selectedPod);
const onContainerChange = (option: SelectOption) => { const onContainerChange = (option: SelectOption) => {
const { containers, initContainers } = tabData;
save({ save({
selectedContainer: containers selectedContainer: containers
.concat(initContainers) .concat(initContainers)
@ -30,11 +29,19 @@ export const LogResourceSelector = observer((props: Props) => {
reload(); reload();
}; };
const getSelectOptions = (containers: IPodContainer[]) => { const onPodChange = (option: SelectOption) => {
return containers.map(container => { save({ selectedPod: podsStore.getByName(option.value, selectedPod.getNs()) });
// Change tab title
// Refresh container list
reload();
};
const getSelectOptions = (items: string[]) => {
return items.map(item => {
return { return {
value: container.name, value: item,
label: container.name label: item
}; };
}); });
}; };
@ -42,18 +49,31 @@ export const LogResourceSelector = observer((props: Props) => {
const containerSelectOptions = [ const containerSelectOptions = [
{ {
label: `Containers`, label: `Containers`,
options: getSelectOptions(containers) options: getSelectOptions(containers.map(container => container.name))
}, },
{ {
label: `Init Containers`, label: `Init Containers`,
options: getSelectOptions(initContainers), options: getSelectOptions(initContainers.map(container => container.name)),
}
];
const podSelectOptions = [
{
label: pod.getOwnerRefs()[0]?.name,
options: getSelectOptions(pods.map(pod => pod.getName()))
} }
]; ];
return ( return (
<div className="LogResourceSelector flex gaps align-center"> <div className="LogResourceSelector flex gaps align-center">
<span>Namespace</span> <Badge label={pod.getNs()}/> <span>Namespace</span> <Badge label={pod.getNs()}/>
<span>Pod</span> <Badge label={pod.getName()}/> <span>Pod</span>
<Select
options={podSelectOptions}
value={{ label: pod.getName(), value: pod.getName() }}
onChange={onPodChange}
autoConvertOptions={false}
/>
<span>Container</span> <span>Container</span>
<Select <Select
options={containerSelectOptions} options={containerSelectOptions}