From 05bb346e7bcb4943d6cc000aba95bd096038d458 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Thu, 15 Oct 2020 16:04:53 +0300 Subject: [PATCH] Adding pod and namespace data to log controls panel (#1083) * Move log controls into separate file Signed-off-by: Alex Andreev * Changing prev container logs icon Signed-off-by: Alex Andreev * Removing 'Logs' from the tab title Signed-off-by: Alex Andreev * Remove unused string template quotes Signed-off-by: Alex Andreev --- .../components/dock/pod-log-controls.tsx | 116 ++++++++++++++++++ .../components/dock/pod-logs.store.ts | 2 +- src/renderer/components/dock/pod-logs.tsx | 115 +++-------------- 3 files changed, 131 insertions(+), 102 deletions(-) create mode 100644 src/renderer/components/dock/pod-log-controls.tsx diff --git a/src/renderer/components/dock/pod-log-controls.tsx b/src/renderer/components/dock/pod-log-controls.tsx new file mode 100644 index 0000000000..d3ba81e7ab --- /dev/null +++ b/src/renderer/components/dock/pod-log-controls.tsx @@ -0,0 +1,116 @@ +import React from "react"; +import { observer } from "mobx-react"; +import { IPodLogsData, podLogsStore } from "./pod-logs.store"; +import { t, Trans } from "@lingui/macro"; +import { Select, SelectOption } from "../select"; +import { Badge } from "../badge"; +import { Icon } from "../icon"; +import { _i18n } from "../../i18n"; +import { cssNames, downloadFile } from "../../utils"; +import { Pod } from "../../api/endpoints"; + +interface Props { + ready: boolean + tabId: string + tabData: IPodLogsData + logs: string[][] + save: (data: Partial) => void + reload: () => void +} + +export const PodLogControls = observer((props: Props) => { + if (!props.ready) return null; + const { tabData, tabId, save, reload, logs } = props; + const { selectedContainer, showTimestamps, previous } = tabData; + const since = podLogsStore.getTimestamps(podLogsStore.logs.get(tabId)[0]); + const pod = new Pod(tabData.pod); + const toggleTimestamps = () => { + save({ showTimestamps: !showTimestamps }); + } + + const togglePrevious = () => { + save({ previous: !previous }); + reload(); + } + + const downloadLogs = () => { + const fileName = selectedContainer ? selectedContainer.name : pod.getName(); + const [oldLogs, newLogs] = logs; + downloadFile(fileName + ".log", [...oldLogs, ...newLogs].join("\n"), "text/plain"); + } + + const onContainerChange = (option: SelectOption) => { + const { containers, initContainers } = tabData; + save({ + selectedContainer: containers + .concat(initContainers) + .find(container => container.name === option.value) + }) + reload(); + } + + const containerSelectOptions = () => { + const { containers, initContainers } = tabData; + return [ + { + label: _i18n._(t`Containers`), + options: containers.map(container => { + return { value: container.name } + }), + }, + { + label: _i18n._(t`Init Containers`), + options: initContainers.map(container => { + return { value: container.name } + }), + } + ]; + } + + const formatOptionLabel = (option: SelectOption) => { + const { value, label } = option; + return label || <> {value}; + } + + return ( +
+ Pod: + Namespace: + Container + -
- {since && ( - <> - Since{" "} - {new Date(since[0]).toLocaleString()} - - )} -
-
- - - -
-
- ); - } - renderLogs() { const [oldLogs, newLogs] = this.logs; if (!this.ready) { @@ -282,11 +185,21 @@ export class PodLogs extends React.Component { render() { const { className } = this.props; + const controls = ( + + ) return (