diff --git a/src/renderer/components/+workloads-pods/pod-menu.tsx b/src/renderer/components/+workloads-pods/pod-menu.tsx index 4ec3bb69d0..fecd400449 100644 --- a/src/renderer/components/+workloads-pods/pod-menu.tsx +++ b/src/renderer/components/+workloads-pods/pod-menu.tsx @@ -51,7 +51,6 @@ export class PodMenu extends React.Component { selectedContainer: container, showTimestamps: false, previous: false, - tailLines: 1000 }); } 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 + - Lines -