diff --git a/src/components/logs-viewer/index.tsx b/src/components/logs-viewer/index.tsx index b0737107..918d43f5 100644 --- a/src/components/logs-viewer/index.tsx +++ b/src/components/logs-viewer/index.tsx @@ -26,6 +26,7 @@ const LogsViewer: React.FC = (props) => { const uidRef = useRef(0); const [logs, setLogs] = useState([]); const autoScroll = useRef(true); + const stopScroll = useRef(false); const setId = () => { uidRef.current += 1; @@ -62,6 +63,17 @@ const LogsViewer: React.FC = (props) => { }); }; + const debounceResetStopScroll = _.debounce(() => { + stopScroll.current = false; + }, 3000); + const handleOnWheel = useCallback( + (e: any) => { + stopScroll.current = true; + debounceResetStopScroll(); + }, + [debounceResetStopScroll] + ); + useEffect(() => { createChunkConnection(); return () => { @@ -76,14 +88,19 @@ const LogsViewer: React.FC = (props) => { }, [scroller.current, initialize]); useEffect(() => { - if (logs.length) { + if (logs.length && !stopScroll.current) { updateScrollerPosition(0); } - }, [logs, autoScroll.current]); + }, [logs, autoScroll.current, stopScroll.current]); return (
-
+
{_.map(logs, (item: any, index: number) => { return ( diff --git a/src/components/logs-viewer/parse-ansi.ts b/src/components/logs-viewer/parse-ansi.ts index 418c7b0c..e2c1440a 100644 --- a/src/components/logs-viewer/parse-ansi.ts +++ b/src/components/logs-viewer/parse-ansi.ts @@ -6,7 +6,7 @@ const useParseAnsi = () => { const lastIndex = useRef(0); const removeBrackets = useCallback((str: string) => { - return str?.replace?.(/^\(.*?\)/, ''); + return str?.replace?.(/^\(…\)/, ''); }, []); const isClean = useCallback((ansiStr: string) => { @@ -26,6 +26,8 @@ const useParseAnsi = () => { // replace carriage return and newline characters in the text let input = inputStr.replace(/\r\n/g, '\n'); + lastIndex.current = 0; + // handle the \r and \n characters in the text const handleText = (text: string) => { let processed = '';