From c230ae79201037eea289c61045314f6c854eef65 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 30 Jan 2023 16:04:55 +0100 Subject: [PATCH] feat: added the ability to tail the logs on the LogViewer Signed-off-by: blam --- .../core-components/src/components/LogViewer/LogViewer.tsx | 4 ++++ .../src/components/LogViewer/RealLogViewer.tsx | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/packages/core-components/src/components/LogViewer/LogViewer.tsx b/packages/core-components/src/components/LogViewer/LogViewer.tsx index 20530cffaf..f1396eef36 100644 --- a/packages/core-components/src/components/LogViewer/LogViewer.tsx +++ b/packages/core-components/src/components/LogViewer/LogViewer.tsx @@ -39,6 +39,10 @@ export interface LogViewerProps { classes?: { root?: string; }; + /** + * Whether the LogViewer should automatically scroll to the bottom of the log. + */ + tail?: boolean; } /** diff --git a/packages/core-components/src/components/LogViewer/RealLogViewer.tsx b/packages/core-components/src/components/LogViewer/RealLogViewer.tsx index 59e0bea44b..d211399c69 100644 --- a/packages/core-components/src/components/LogViewer/RealLogViewer.tsx +++ b/packages/core-components/src/components/LogViewer/RealLogViewer.tsx @@ -32,6 +32,7 @@ import { useLogViewerSelection } from './useLogViewerSelection'; export interface RealLogViewerProps { text: string; classes?: { root?: string }; + tail?: boolean; } export function RealLogViewer(props: RealLogViewerProps) { @@ -52,6 +53,12 @@ export function RealLogViewer(props: RealLogViewerProps) { } }, [search.resultLine]); + useEffect(() => { + if (props.tail && listRef.current) { + listRef.current.scrollToItem(lines.length - 1, 'center'); + } + }, [lines.length, props.tail]); + useEffect(() => { if (location.hash) { // #line-6 -> 6