-
Notifications
You must be signed in to change notification settings - Fork 0
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
Task/WP-72: Highlight matching search terms #873
Merged
chandra-tacc
merged 12 commits into
main
from
task/WP-72--highlight-matching-search-terms
Oct 24, 2023
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ebd4061
task/WP-72 highlighted search queries/term in job history infinitescr…
asimregmi 317f005
fixed formatting
asimregmi 500a0dd
removed highlight and added bold
asimregmi 8a35df5
remove css properties and replaced <mark> with <b>
asimregmi ad8f992
used local css modules instead of global
asimregmi f086b7c
Changed implementation of HighlightSearchTerm component to be used by…
asimregmi cff28c7
added useMemo hook and improved HighlightSearchTerm perf
asimregmi 3dffd09
removed useMemo hook
asimregmi 003e96f
added unit tests for HighlightSearchTerm component
asimregmi 6b24fb0
updated comment and fixed linting
asimregmi fe264b9
Merge branch 'main' into task/WP-72--highlight-matching-search-terms
shayanaijaz 373aa9d
Merge branch 'main' into task/WP-72--highlight-matching-search-terms
chandra-tacc 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 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
55 changes: 55 additions & 0 deletions
55
client/src/components/_common/HighlightSearchTerm/HighlightSearchTerm.jsx
This file contains 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,55 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Link, useLocation } from 'react-router-dom'; | ||
import * as ROUTES from '../../../constants/routes'; | ||
import { getOutputPath } from 'utils/jobsUtil'; | ||
import './HighlightSearchTerm.scss'; | ||
|
||
const HighlightSearchTerm = ({ searchTerm, cell, id }) => { | ||
const highlightParts = (content) => { | ||
const parts = content.split(new RegExp(`(${searchTerm})`, 'gi')); | ||
return parts.map((part, i) => | ||
part.toLowerCase() === searchTerm.toLowerCase() ? ( | ||
<b className="highlight" key={i}> | ||
{part} | ||
</b> | ||
) : ( | ||
part | ||
) | ||
); | ||
}; | ||
|
||
if (id == 'Output Location') { | ||
const outputLocation = getOutputPath(cell.row.original); | ||
|
||
return outputLocation ? ( | ||
<Link | ||
to={`${ROUTES.WORKBENCH}${ROUTES.DATA}/tapis/private/${outputLocation}`} | ||
className="wb-link job__path" | ||
> | ||
{highlightParts(outputLocation)} | ||
</Link> | ||
) : null; | ||
} else if (id == 'uuid') { | ||
return <b className="highlight">{cell.render('Cell')}</b>; | ||
} else if (id == 'name') { | ||
const jobName = cell.row.values[id]; | ||
|
||
return <span>{highlightParts(jobName)}</span>; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
HighlightSearchTerm.propTypes = { | ||
searchTerm: PropTypes.string, | ||
cell: PropTypes.object, | ||
id: PropTypes.string, | ||
}; | ||
|
||
HighlightSearchTerm.defaultProps = { | ||
searchTerm: '', | ||
outputLocation: '', | ||
}; | ||
|
||
export default HighlightSearchTerm; |
3 changes: 3 additions & 0 deletions
3
client/src/components/_common/HighlightSearchTerm/HighlightSearchTerm.scss
This file contains 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,3 @@ | ||
.highlight { | ||
font-weight: bold; | ||
} | ||
asimregmi marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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,3 @@ | ||
import HighlightSearchTerm from './HighlightSearchTerm'; | ||
|
||
export default HighlightSearchTerm; |
This file contains 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
This file contains 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
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.
This look great.
Minor suggestions to help improve perf.
I tried to see if just string replace with regex would work instead of split and replace, I did not get one working. But, may be you can try to see if that feasible?
suggestion code:
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.
I changed logic to use
match
instead oftoLowerCase
. Tried the other suggestion to use.replace()
function instead but couldn't get it to work properly. I am getting [object] [object' inside the string that needs to be highlighted. Is it because .replace() isn't good for returning the<b>...</b>
and only good for string? Let me know.