-
Notifications
You must be signed in to change notification settings - Fork 121
feat: Implemented log search functionality with highlighted results #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
harshit078
wants to merge
15
commits into
middlewarehq:main
Choose a base branch
from
harshit078:fix-logs-search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+498
−56
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3a3abb0
feat: Implemented log search functionality with highlighted results
harshit078 940f740
Fixing coderabbitai comments
harshit078 ae17ef3
added improvements and fixed errors
harshit078 901cd26
Added debounce and useMemo to reduce my interaction time spent on tex…
harshit078 e2e5018
Added memo to prevent re-render in the list and optimise FPS drops an…
harshit078 65c860e
Added debounded method to improve performance and optimised code
harshit078 113e483
Added circular navigation allowing users to navigate in a loop
harshit078 0a10568
Resolved comments and pushed a fix
harshit078 1d41efb
Resolved comments
harshit078 75ea1fa
Resolved comments and improved code structure and robustness
harshit078 ebdb7bf
minor fix
harshit078 89d9329
Added a fix for failing lint errors
harshit078 25c1dee
Addressed all comments added and resolved them
harshit078 9c2f64f
Fixed Eslint check and resolved failing tests
harshit078 70d1cd0
Fixed dom travesal and implemented storing of indices
harshit078 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
web-server/src/components/Service/SystemLog/LogSearch.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
import { | ||
Search as SearchIcon, | ||
Clear as ClearIcon, | ||
NavigateNext, | ||
NavigateBefore | ||
} from '@mui/icons-material'; | ||
import { | ||
Button, | ||
InputAdornment, | ||
TextField, | ||
Typography, | ||
Box | ||
} from '@mui/material'; | ||
import { styled } from '@mui/material/styles'; | ||
import { memo, useState, useCallback, useMemo } from 'react'; | ||
|
||
import { MotionBox } from '@/components/MotionComponents'; | ||
import { debounce } from '@/utils/debounce'; | ||
|
||
const SearchContainer = styled('div')(() => ({ | ||
position: 'sticky', | ||
top: 0, | ||
zIndex: 1, | ||
gap: 5, | ||
paddingBottom: 8, | ||
alignItems: 'center', | ||
backdropFilter: 'blur(10px)', | ||
borderRadius: 5 | ||
})); | ||
|
||
const SearchControls = styled(Box)(({ theme }) => ({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: theme.spacing(1), | ||
marginTop: 8 | ||
})); | ||
|
||
const StyledTextField = styled(TextField)(({ theme }) => ({ | ||
'& .MuiOutlinedInput-root': { | ||
backgroundColor: theme.palette.background.paper, | ||
transition: 'all 0.2s ease-in-out', | ||
'&:hover': { | ||
backgroundColor: theme.palette.background.paper, | ||
boxShadow: `0 0 0 1px ${theme.palette.primary.main}` | ||
}, | ||
'&.Mui-focused': { | ||
backgroundColor: theme.palette.background.paper, | ||
boxShadow: `0 0 0 2px ${theme.palette.primary.main}` | ||
} | ||
} | ||
})); | ||
|
||
interface LogSearchProps { | ||
onSearch: (query: string) => void; | ||
onNavigate: (direction: 'prev' | 'next') => void; | ||
jayantbh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
currentMatch: number; | ||
totalMatches: number; | ||
} | ||
|
||
const LogSearch = memo( | ||
({ onSearch, onNavigate, currentMatch, totalMatches }: LogSearchProps) => { | ||
const [searchQuery, setSearchQuery] = useState(''); | ||
|
||
const debouncedSearch = useMemo( | ||
() => | ||
debounce((query: string) => { | ||
onSearch(query); | ||
}, 300), | ||
[onSearch] | ||
); | ||
|
||
const handleSearchChange = useCallback( | ||
(event: React.ChangeEvent<HTMLInputElement>) => { | ||
const query = event.target.value; | ||
setSearchQuery(query); | ||
debouncedSearch(query); | ||
}, | ||
[debouncedSearch] | ||
); | ||
|
||
const handleClear = useCallback(() => { | ||
setSearchQuery(''); | ||
onSearch(''); | ||
}, [onSearch]); | ||
|
||
const handleNavigate = useCallback( | ||
(direction: 'prev' | 'next') => { | ||
if (direction === 'next') { | ||
onNavigate('next'); | ||
} else { | ||
onNavigate('prev'); | ||
} | ||
}, | ||
[onNavigate] | ||
); | ||
|
||
const showSearchControls = searchQuery && totalMatches > 0; | ||
|
||
return ( | ||
<SearchContainer> | ||
<StyledTextField | ||
fullWidth | ||
variant="outlined" | ||
placeholder="Search logs..." | ||
value={searchQuery} | ||
onChange={handleSearchChange} | ||
InputProps={{ | ||
startAdornment: ( | ||
<InputAdornment position="start"> | ||
<SearchIcon color="action" /> | ||
</InputAdornment> | ||
), | ||
endAdornment: !!searchQuery.length && ( | ||
<InputAdornment position="end"> | ||
<ClearIcon | ||
sx={{ cursor: 'pointer' }} | ||
onClick={handleClear} | ||
color="action" | ||
/> | ||
</InputAdornment> | ||
) | ||
}} | ||
/> | ||
{showSearchControls && ( | ||
<MotionBox | ||
initial={{ y: 20, opacity: 0 }} | ||
animate={{ y: 0, opacity: 1 }} | ||
exit={{ y: 20, opacity: 0 }} | ||
transition={{ | ||
type: 'tween', | ||
ease: 'easeOut', | ||
duration: 0.3 | ||
}} | ||
> | ||
<SearchControls> | ||
<Button | ||
size="small" | ||
onClick={() => handleNavigate('prev')} | ||
startIcon={<NavigateBefore />} | ||
sx={{ | ||
minWidth: '20px', | ||
padding: '4px 8px' | ||
}} | ||
/> | ||
<Typography variant="body2" color="text.secondary"> | ||
{currentMatch} of {totalMatches} | ||
</Typography> | ||
<Button | ||
size="small" | ||
onClick={() => handleNavigate('next')} | ||
startIcon={<NavigateNext />} | ||
sx={{ | ||
minWidth: '20px', | ||
padding: '4px 8px' | ||
}} | ||
/> | ||
</SearchControls> | ||
</MotionBox> | ||
)} | ||
</SearchContainer> | ||
); | ||
} | ||
); | ||
|
||
LogSearch.displayName = 'LogSearch'; | ||
|
||
export { LogSearch }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
import { Line } from '@/components/Text'; | ||
|
||
export const PlainLog = ({ log }: { log: string; index: number }) => { | ||
import { SearchHighlightText } from './FormattedLog'; | ||
|
||
interface PlainLogProps { | ||
log: string; | ||
index: number; | ||
searchQuery?: string; | ||
isCurrentMatch?: boolean; | ||
} | ||
|
||
export const PlainLog = ({ | ||
log, | ||
searchQuery, | ||
isCurrentMatch | ||
}: PlainLogProps) => { | ||
return ( | ||
<Line mono marginBottom={1}> | ||
{log} | ||
<SearchHighlightText | ||
text={log} | ||
searchQuery={searchQuery} | ||
isCurrentMatch={isCurrentMatch} | ||
/> | ||
</Line> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A component can directly return text. Text nodes are valid react nodes.