Skip to content

Commit

Permalink
Replace per-column table search with more robust search utility.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 503424200
  • Loading branch information
cjqian authored and LIT team committed Jan 20, 2023
1 parent 7d30408 commit 7301b28
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions lit_nlp/client/elements/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import * as papa from 'papaparse';
import {ReactiveElement} from '../lib/elements';
import {styles as sharedStyles} from '../lib/shared_styles.css';
import {formatForDisplay} from '../lib/types';
import {isNumber, median, numberRangeFnFromString, randInt} from '../lib/utils';
import {isNumber, median, randInt} from '../lib/utils';

import {ColumnHeader, SortableTableEntry, SortableTemplateResult, TableData, TableEntry, TableRowInternal} from './table_types';
import {filterDataByQueries, getSortableEntry, parseSearchTextIntoQueries} from './table_utils';
import {filterDataByQueries, getSortableEntry, itemMatchesText, parseSearchTextIntoQueries} from './table_utils';

import {styles} from './table.css';

Expand Down Expand Up @@ -878,16 +878,7 @@ export class DataTable extends ReactiveElement {
const handleSearchChange = (e: KeyboardEvent) => {
const searchQuery = (e.target as HTMLInputElement)?.value || '';
function fn(col: SortableTableEntry) {
if (typeof col === 'string') {
// String columns use a reg ex search.
return col.search(new RegExp(searchQuery)) !== -1;
} else if (typeof col === 'number') {
// Numeric columns use a range-based search.
const matchFn = numberRangeFnFromString(searchQuery);
return matchFn(col);
} else {
return false;
}
return itemMatchesText(col, searchQuery);
}
this.columnFilterInfo.set(header.name, {fn, values: [searchQuery]});
};
Expand Down

0 comments on commit 7301b28

Please sign in to comment.