From 6e4fa31a49d485384eaacf7dcb2abc7ee9ee2273 Mon Sep 17 00:00:00 2001 From: steve richards Date: Fri, 16 Oct 2020 08:46:30 +0100 Subject: [PATCH 1/8] Sort Pod environment values in alphabetical order (#1075) * Sort Pod environment values in alphabetical order Fixes: #739 Signed-off-by: Steve Richards * Consolidated to a single lodash import. Corrected Lint failure - Removed the additional import of flatten and updated as needed; - Changed the variabled `orderedEnv` to be a const; Signed-off-by: Steve Richards Co-authored-by: Steve Richards --- .../components/+workloads-pods/pod-container-env.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/+workloads-pods/pod-container-env.tsx b/src/renderer/components/+workloads-pods/pod-container-env.tsx index fb779a9eaa..2071c959d1 100644 --- a/src/renderer/components/+workloads-pods/pod-container-env.tsx +++ b/src/renderer/components/+workloads-pods/pod-container-env.tsx @@ -1,7 +1,6 @@ import "./pod-container-env.scss"; import React, { useEffect, useState } from "react"; -import flatten from "lodash/flatten"; import { observer } from "mobx-react"; import { Trans } from "@lingui/macro"; import { IPodContainer, Secret } from "../../api/endpoints"; @@ -11,6 +10,7 @@ import { secretsStore } from "../+config-secrets/secrets.store"; import { configMapsStore } from "../+config-maps/config-maps.store"; import { Icon } from "../icon"; import { base64, cssNames } from "../../utils"; +import _ from "lodash"; interface Props { container: IPodContainer; @@ -40,7 +40,9 @@ export const ContainerEnvironment = observer((props: Props) => { ) const renderEnv = () => { - return env.map(variable => { + const orderedEnv = _.sortBy(env, 'name'); + + return orderedEnv.map(variable => { const { name, value, valueFrom } = variable let secretValue = null @@ -89,7 +91,7 @@ export const ContainerEnvironment = observer((props: Props) => { )) }) - return flatten(envVars) + return _.flatten(envVars) } return ( From 073b8a43f2ecfc1b1889d7d692dc52e52614dac0 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Fri, 16 Oct 2020 12:46:16 +0300 Subject: [PATCH 2/8] Preloading previous logs on scroll (#1079) * Preload logs when scrolled to top Signed-off-by: Alex Andreev * Adding JumpToBottom button Signed-off-by: Alex Andreev * Moving jump-to-bottom button to right Signed-off-by: Alex Andreev * Adding old/new logs separator Signed-off-by: Alex Andreev * Increase font-size in jump to bottom button Signed-off-by: Alex Andreev * Moving newLogsSince determination out of component Signed-off-by: Alex Andreev * Move newLogSince from storage data to observable Signed-off-by: Alex Andreev * Remove notiifications on log loading errors Signed-off-by: Alex Andreev * Transform logs into array in store Signed-off-by: Alex Andreev * Clean up Signed-off-by: Alex Andreev * Remove excessive join('\n\)s Signed-off-by: Alex Andreev * 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 * Hide JumpToBottom btn on error Signed-off-by: Alex Andreev * Remove mention about dialog Signed-off-by: Alex Andreev --- .../components/+workloads-pods/pod-menu.tsx | 1 - .../components/dock/pod-log-controls.tsx | 116 +++++++++ src/renderer/components/dock/pod-logs.scss | 19 +- .../components/dock/pod-logs.store.ts | 153 ++++++++---- src/renderer/components/dock/pod-logs.tsx | 231 ++++++++---------- 5 files changed, 346 insertions(+), 174 deletions(-) create mode 100644 src/renderer/components/dock/pod-log-controls.tsx 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 -