From 75ad1f4b02ed4382754c2e8f59f04957780921e6 Mon Sep 17 00:00:00 2001 From: Hristo Nedelkov Date: Tue, 28 Nov 2023 13:33:22 +0200 Subject: [PATCH] pass search props --- src/pages/LogsPage/LogsPage.tsx | 15 +++++++++++++ src/pages/LogsPage/LogsTerminal.tsx | 34 ++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/pages/LogsPage/LogsPage.tsx b/src/pages/LogsPage/LogsPage.tsx index 14b29f58..30e96479 100644 --- a/src/pages/LogsPage/LogsPage.tsx +++ b/src/pages/LogsPage/LogsPage.tsx @@ -10,9 +10,16 @@ import { useEffect, useState } from 'react' import HeaderBtns from './HeaderBtns' const LogsPage = () => { + const [highLightSearched, setHighLightSearched] = useState(false) + const [searchInput, setSearchInput] = useState(''); const [timestamps, setTimestamps] = useState(false) const [windowWidth, setWindowWidth] = useState(window.innerWidth) const [dropdownMenuItem, setDropdownMenuItem] = useState('Validator') + + const triggerSearch = (isTriggered: boolean) => { + setHighLightSearched(isTriggered) + } + useEffect(() => { const handleResize = () => { setWindowWidth(+window.innerWidth) @@ -46,6 +53,11 @@ const LogsPage = () => { setDropdownMenuItem={setDropdownMenuItem} setTimestamps={setTimestamps} timestamps={timestamps} + searchInput={searchInput} + setSearchInput={setSearchInput} + triggerSearch={triggerSearch} + + /> @@ -53,6 +65,9 @@ const LogsPage = () => { windowWidth={windowWidth} dropdownMenuItem={dropdownMenuItem} timestamps={timestamps} + searchInput={searchInput} + setSearchInput={setSearchInput} + highLightSearched={highLightSearched} /> void + highLightSearched: boolean } const fetchMoreData = () => { @@ -30,15 +33,19 @@ const fetchMoreData = () => { }) } -const LogsTerminal = ({ windowWidth, timestamps }: LogsTerminalProps) => { +const LogsTerminal = ({ + windowWidth, + timestamps, + searchInput, + setSearchInput, + highLightSearched, +}: LogsTerminalProps) => { const [data, setData] = useState([]) const [loadedIndexes, setLoadedIndexes] = useState<{ [key: number]: boolean }>({}) const listRef = useRef(null) const [shouldAutoScroll, setShouldAutoScroll] = useState(true) - - useEffect(() => { if (shouldAutoScroll) { setTimeout(() => { @@ -123,11 +130,22 @@ const LogsTerminal = ({ windowWidth, timestamps }: LogsTerminalProps) => { border: '1px solid #E7EAEE', }} > - {({ index, style }) => ( - - - - )} + {({ index, style }) => { + const highlight = + searchInput && data[index].description.split(' ').includes(searchInput) + // now we only check for the existing text at the moment + // I have to move this statemant in the terminalRow component + return ( + + + + ) + }} )}