Skip to content

feat: highlight global search text in table results (#533)#537

Merged
NoopDog merged 2 commits into
mainfrom
fran/533-dd-highlight
Jun 18, 2025
Merged

feat: highlight global search text in table results (#533)#537
NoopDog merged 2 commits into
mainfrom
fran/533-dd-highlight

Conversation

@frano-m

@frano-m frano-m commented Jun 18, 2025

Copy link
Copy Markdown
Contributor

Closes #533.

This pull request introduces enhancements to the global filtering functionality in the table component, including support for ranking and highlighting matched cells based on search terms. The most significant changes involve updating the filtering logic, adding metadata for ranked columns, and implementing cell rendering with highlighted matches.

Enhancements to global filtering:

Metadata for ranked columns:

Cell rendering with highlighting:

Styling updates for highlighted cells:

image

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the global filtering feature of the Table component by tracking which columns pass the filter and rendering matched cells with highlighted search terms.

  • Extend fuzzy filter to record pass metadata and invoke ranking for other columns
  • Add ColumnFilterMeta and rankRowColumns to track and process highlight eligibility
  • Implement RankedCell component and utils for token-based highlighting
  • Add theme styles for <mark> tags in table cells

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/theme/components/muiTableCell.ts Adds theme override to style <mark> tags in table cells
src/components/Table/components/TableCell/components/RankedCell/utils.ts Introduces renderRankedCell, token parsing, and matching
src/components/Table/components/TableCell/components/RankedCell/rankedCell.tsx Implements RankedCell JSX component for highlighted cells
src/components/Table/columnDef/globalFilter/utils.ts Adds rankRowColumns to process and rank other row columns
src/components/Table/columnDef/globalFilter/types.ts Defines ColumnFilterMeta to include a passed flag
src/components/Table/columnDef/globalFilter/filterFn.ts Updates fuzzy filter to add metadata and rank other columns
Comments suppressed due to low confidence (2)

src/components/Table/components/TableCell/components/RankedCell/utils.ts:14

  • No unit tests cover the new highlighting utility 'renderRankedCell'. Consider adding tests for token matching and resulting HTML output to ensure highlighting works correctly.
export function renderRankedCell<T extends RowData>(

src/components/Table/components/TableCell/components/RankedCell/rankedCell.tsx:6

  • There are no component tests for 'RankedCell'. Adding snapshot or behavior tests would help verify that highlighting and null/undefined handling behave as expected.
export const RankedCell = <

Comment thread src/theme/components/muiTableCell.ts Outdated
// Create regex pattern.
const regex = getTokensRegex(tokens);

return stringValue.replace(regex, "<mark>$1</mark>");

Copilot AI Jun 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Injecting raw HTML tags into strings may lead to XSS if the cell value contains HTML entities. Consider sanitizing the cell value or using React elements for highlighting rather than raw string replacements.

Copilot uses AI. Check for mistakes.
Comment on lines +60 to +63
for (const { column } of row.getAllCells()) {
// Column is not searchable.
if (!column.getCanGlobalFilter()) continue;

Copilot AI Jun 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iterating over all cells for each row on every filter invocation can be expensive for large tables. Consider limiting this to searchable columns only or caching previous results.

Suggested change
for (const { column } of row.getAllCells()) {
// Column is not searchable.
if (!column.getCanGlobalFilter()) continue;
const searchableColumns = row.getAllCells()
.map(cell => cell.column)
.filter(column => column.getCanGlobalFilter());
for (const column of searchableColumns) {

Copilot uses AI. Check for mistakes.
Comment on lines +18 to 22
value: unknown,
addMeta: (meta: FilterMeta) => void
): boolean {
// Split the search term into terms.
const terms = parseSearchTerms(value);

Copilot AI Jun 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The parameter name 'value' is generic; renaming it to 'filterValue' could improve readability by clarifying its role as the search input.

Suggested change
value: unknown,
addMeta: (meta: FilterMeta) => void
): boolean {
// Split the search term into terms.
const terms = parseSearchTerms(value);
filterValue: unknown,
addMeta: (meta: FilterMeta) => void
): boolean {
// Split the search term into terms.
const terms = parseSearchTerms(filterValue);

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving as is - to mirror TanStack's filterFn variables.

@NoopDog NoopDog merged commit f9b8d24 into main Jun 18, 2025
2 checks passed
@NoopDog NoopDog deleted the fran/533-dd-highlight branch July 8, 2025 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Highlight global search text in table results

3 participants