Skip to content

Commit

Permalink
highlighted searched query string in Job History InfiniteScrollTable
Browse files Browse the repository at this point in the history
  • Loading branch information
asimregmi committed Oct 4, 2023
1 parent 9675034 commit 62cf8db
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
4 changes: 2 additions & 2 deletions client/src/components/Jobs/Jobs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AppIcon,
InfiniteScrollTable,
Message,
HighlightSearchTerm,
SectionMessage,
Section,
} from '_common';
Expand Down Expand Up @@ -88,7 +89,6 @@ function JobsView({
},
}) => {
const query = queryStringParser.parse(useLocation().search);

// TODOv3: dropV2Jobs
const jobsPathname = uuid ? `/jobs/${uuid}` : `/jobsv2/${id}`;
return (
Expand Down Expand Up @@ -205,7 +205,6 @@ function JobsView({
];

const filterColumns = columns.filter((f) => f.show !== false);

return (
<>
{includeSearchbar && (
Expand All @@ -231,6 +230,7 @@ function JobsView({
}
getRowProps={rowProps}
columnMemoProps={[version]} /* TODOv3: dropV2Jobs. */
searchTerm={query.query_string}
/>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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';

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 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>{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;
3 changes: 3 additions & 0 deletions client/src/components/_common/HighlightSearchTerm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import HighlightSearchTerm from './HighlightSearchTerm';

export default HighlightSearchTerm;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTable } from 'react-table';
import PropTypes from 'prop-types';
import LoadingSpinner from '../LoadingSpinner';
import './InfiniteScrollTable.scss';
import { HighlightSearchTerm } from '_common';

const rowContentPropType = PropTypes.oneOfType([
PropTypes.string,
Expand Down Expand Up @@ -54,6 +55,7 @@ const InfiniteScrollTable = ({
noDataText,
getRowProps,
columnMemoProps,
searchTerm,
}) => {
const columns = React.useMemo(() => tableColumns, columnMemoProps);
const data = React.useMemo(() => tableData, [tableData]);
Expand Down Expand Up @@ -93,7 +95,18 @@ const InfiniteScrollTable = ({
<td
{...cell.getCellProps({ className: cell.column.className })}
>
{cell.render('Cell')}
{searchTerm !== '' &&
(cell.column.id === 'name' ||
cell.column.id === 'Output Location' ||
cell.column.id === 'uuid') ? (
<HighlightSearchTerm
searchTerm={searchTerm}
cell={cell}
id={cell.column.id}
/>
) : (
cell.render('Cell')
)}
</td>
);
})}
Expand All @@ -119,12 +132,15 @@ InfiniteScrollTable.propTypes = {
noDataText: rowContentPropType,
getRowProps: PropTypes.func,
columnMemoProps: PropTypes.arrayOf(PropTypes.any),
searchTerm: PropTypes.string,
cell: PropTypes.object,
};
InfiniteScrollTable.defaultProps = {
onInfiniteScroll: (offset) => {},
isLoading: false,
className: '',
noDataText: '',
searchTerm: '',
getRowProps: (row) => {},
columnMemoProps: [],
};
Expand Down
1 change: 1 addition & 0 deletions client/src/components/_common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { default as Icon } from './Icon';
export { default as Message } from './Message';
export { default as InlineMessage } from './InlineMessage';
export { default as SectionMessage } from './SectionMessage';
export { default as HighlightSearchTerm } from './HighlightSearchTerm';
export { default as Sidebar } from './Sidebar';
export { default as DescriptionList } from './DescriptionList';
export { default as DropdownSelector } from './DropdownSelector';
Expand Down

0 comments on commit 62cf8db

Please sign in to comment.