-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task/WP-72 highlighted search queries/term in job history infinitescr…
…olltable
- Loading branch information
Showing
6 changed files
with
79 additions
and
1 deletion.
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
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
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() ? ( | ||
<mark className="highlight" key={i}>{part}</mark> | ||
) : ( | ||
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 <mark className="highlight">{cell.render('Cell')}</mark>; | ||
} 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; |
4 changes: 4 additions & 0 deletions
4
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,4 @@ | ||
.highlight { | ||
padding: 2.8px 0; | ||
background-color: yellow; | ||
} |
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