From 92e227f6fae867d6af997927f66942db01b6dc53 Mon Sep 17 00:00:00 2001 From: Yi Cai Date: Mon, 18 Sep 2023 12:54:46 -0400 Subject: [PATCH] feat(ui): Add button for wrapping lines in pod logs viewer (#15506) * Add back wrap log line button Signed-off-by: Yi Cai * Fixed lint issue Signed-off-by: Yi Cai * Updated icon and location of Wrap Lines btn Signed-off-by: Yi Cai * Fixed lint issue Signed-off-by: Yi Cai * Put back pre tag and Ansi component Signed-off-by: Yi Cai --------- Signed-off-by: Yi Cai --- .../pod-logs-viewer/pod-logs-viewer.tsx | 46 ++++++------------- .../pod-logs-viewer/wrap-lines-button.tsx | 17 +++++++ ui/src/app/shared/components/button.tsx | 6 ++- .../app/shared/components/toggle-button.tsx | 5 +- 4 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 ui/src/app/applications/components/pod-logs-viewer/wrap-lines-button.tsx diff --git a/ui/src/app/applications/components/pod-logs-viewer/pod-logs-viewer.tsx b/ui/src/app/applications/components/pod-logs-viewer/pod-logs-viewer.tsx index 2eaf8103fcb638..30b101eecc4f86 100644 --- a/ui/src/app/applications/components/pod-logs-viewer/pod-logs-viewer.tsx +++ b/ui/src/app/applications/components/pod-logs-viewer/pod-logs-viewer.tsx @@ -8,7 +8,6 @@ import {LogEntry} from '../../../shared/models'; import {services, ViewPreferences} from '../../../shared/services'; import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer'; -import Grid from 'react-virtualized/dist/commonjs/Grid'; import './pod-logs-viewer.scss'; import {CopyLogsButton} from './copy-logs-button'; @@ -24,9 +23,9 @@ import {LogMessageFilter} from './log-message-filter'; import {SinceSecondsSelector} from './since-seconds-selector'; import {TailSelector} from './tail-selector'; import {PodNamesToggleButton} from './pod-names-toggle-button'; -import Ansi from 'ansi-to-react'; import {AutoScrollButton} from './auto-scroll-button'; -import {GridCellProps} from 'react-virtualized/dist/es/Grid'; +import {WrapLinesButton} from './wrap-lines-button'; +import Ansi from 'ansi-to-react'; export interface PodLogsProps { namespace: string; @@ -133,22 +132,15 @@ export const PodsLogsViewer = (props: PodLogsProps) => { (viewTimestamps ? (lineNum === 0 || (logs[lineNum - 1].timeStamp !== log.timeStamp ? log.timeStampStr : '').padEnd(30)) + ' ' : '') + // show the log content, highlight the filter text log.content?.replace(highlight, (substring: string) => whiteOnYellow + substring + reset); - - const cellRenderer = ({rowIndex, key, style}: GridCellProps) => { - return ( -
-                {renderLog(logs[rowIndex], rowIndex)}
-            
- ); - }; - - // calculate the width of the grid based on the longest log line - const maxWidth = - 14 * - logs - .map(renderLog) - .map(v => v.length) - .reduce((a, b) => Math.max(a, b), 0); + const logsContent = (width: number, height: number, isWrapped: boolean) => ( +
+ {logs.map((log, lineNum) => ( +
+                    {renderLog(log, lineNum)}
+                
+ ))} +
+ ); return ( services.viewPreferences.getPreferences()}> @@ -173,6 +165,7 @@ export const PodsLogsViewer = (props: PodLogsProps) => { + @@ -189,20 +182,7 @@ export const PodsLogsViewer = (props: PodLogsProps) => { onWheel={e => { if (e.deltaY < 0) setScrollToBottom(false); }}> - - {({width, height}: {width: number; height: number}) => ( - - )} - + {({width, height}: {width: number; height: number}) => logsContent(width, height, prefs.appDetails.wrapLines)} ); diff --git a/ui/src/app/applications/components/pod-logs-viewer/wrap-lines-button.tsx b/ui/src/app/applications/components/pod-logs-viewer/wrap-lines-button.tsx new file mode 100644 index 00000000000000..9caee043fdd39b --- /dev/null +++ b/ui/src/app/applications/components/pod-logs-viewer/wrap-lines-button.tsx @@ -0,0 +1,17 @@ +import {services, ViewPreferences} from '../../../shared/services'; +import * as React from 'react'; +import {ToggleButton} from '../../../shared/components/toggle-button'; + +// WrapLinesButton is a component that wraps log lines. +export const WrapLinesButton = ({prefs}: {prefs: ViewPreferences}) => ( + { + const wrap = prefs.appDetails.wrapLines; + services.viewPreferences.updatePreferences({...prefs, appDetails: {...prefs.appDetails, wrapLines: !wrap}}); + }} + toggled={prefs.appDetails.wrapLines} + icon='share' + rotate={true} + /> +); diff --git a/ui/src/app/shared/components/button.tsx b/ui/src/app/shared/components/button.tsx index 33b9b30da48da4..8530f3492a738a 100644 --- a/ui/src/app/shared/components/button.tsx +++ b/ui/src/app/shared/components/button.tsx @@ -12,7 +12,8 @@ export const Button = ({ className, style, disabled, - beat + beat, + rotate }: { onClick?: MouseEventHandler; children?: ReactNode; @@ -23,13 +24,14 @@ export const Button = ({ style?: CSSProperties; disabled?: boolean; beat?: boolean; + rotate?: boolean; }) => ( ); diff --git a/ui/src/app/shared/components/toggle-button.tsx b/ui/src/app/shared/components/toggle-button.tsx index af2b7a4c54275f..eb0957b87bb052 100644 --- a/ui/src/app/shared/components/toggle-button.tsx +++ b/ui/src/app/shared/components/toggle-button.tsx @@ -11,7 +11,8 @@ export const ToggleButton = ({ toggled, beat, disabled, - icon + icon, + rotate }: { toggled: boolean; beat?: boolean; @@ -20,11 +21,13 @@ export const ToggleButton = ({ title: string; disabled?: boolean; icon: Icon; + rotate?: boolean; }) => (