Add an predicate to search a whole row
Summary: Allow users to search through the entire row. Based on feedback from https://fb.workplace.com/groups/flippersupport/permalink/1703929480087703/ Reviewed By: lblasa Differential Revision: D49911869 fbshipit-source-id: 7bb9816c91b9168d657314b289e3ecc3c237c8d8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
53eb06a781
commit
0346dc1120
@@ -99,6 +99,11 @@ type DataTableBaseProps<T = any> = {
|
|||||||
| null
|
| null
|
||||||
| ((dataView?: _DataSourceView<T, T[keyof T]>) => React.ReactElement);
|
| ((dataView?: _DataSourceView<T, T[keyof T]>) => React.ReactElement);
|
||||||
powerSearchInitialState?: SearchExpressionTerm[];
|
powerSearchInitialState?: SearchExpressionTerm[];
|
||||||
|
/**
|
||||||
|
* Adds a special power search entry to search through the entire row (mathching a substring in it after stringifying it as a JSON)
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
enablePowerSearchWholeRowSearch?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ItemRenderer<T> = (
|
export type ItemRenderer<T> = (
|
||||||
@@ -249,6 +254,20 @@ export function DataTable<T extends object>(
|
|||||||
const powerSearchConfig: PowerSearchConfig = useMemo(() => {
|
const powerSearchConfig: PowerSearchConfig = useMemo(() => {
|
||||||
const res: PowerSearchConfig = {fields: {}};
|
const res: PowerSearchConfig = {fields: {}};
|
||||||
|
|
||||||
|
if (props.enablePowerSearchWholeRowSearch) {
|
||||||
|
res.fields.entireRow = {
|
||||||
|
label: 'Row',
|
||||||
|
key: 'entireRow',
|
||||||
|
operators: {
|
||||||
|
searializable_object_contains:
|
||||||
|
dataTablePowerSearchOperators.searializable_object_contains(),
|
||||||
|
searializable_object_not_contains:
|
||||||
|
dataTablePowerSearchOperators.searializable_object_not_contains(),
|
||||||
|
},
|
||||||
|
useWholeRow: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
for (const column of columns) {
|
for (const column of columns) {
|
||||||
if (column.powerSearchConfig === false) {
|
if (column.powerSearchConfig === false) {
|
||||||
continue;
|
continue;
|
||||||
@@ -268,7 +287,7 @@ export function DataTable<T extends object>(
|
|||||||
columnPowerSearchOperators = column.powerSearchConfig;
|
columnPowerSearchOperators = column.powerSearchConfig;
|
||||||
} else {
|
} else {
|
||||||
columnPowerSearchOperators = column.powerSearchConfig.operators;
|
columnPowerSearchOperators = column.powerSearchConfig.operators;
|
||||||
useWholeRow = true;
|
useWholeRow = !!column.powerSearchConfig.useWholeRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnFieldConfig: FieldConfig = {
|
const columnFieldConfig: FieldConfig = {
|
||||||
@@ -284,7 +303,7 @@ export function DataTable<T extends object>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}, [columns]);
|
}, [columns, props.enablePowerSearchWholeRowSearch]);
|
||||||
|
|
||||||
const renderingConfig = useMemo<TableRowRenderContext<T>>(() => {
|
const renderingConfig = useMemo<TableRowRenderContext<T>>(() => {
|
||||||
let startIndex = 0;
|
let startIndex = 0;
|
||||||
@@ -787,6 +806,7 @@ DataTable.defaultProps = {
|
|||||||
enableContextMenu: true,
|
enableContextMenu: true,
|
||||||
enablePersistSettings: true,
|
enablePersistSettings: true,
|
||||||
onRenderEmpty: undefined,
|
onRenderEmpty: undefined,
|
||||||
|
enablePowerSearchWholeRowSearch: true,
|
||||||
} as Partial<DataTableProps<any>>;
|
} as Partial<DataTableProps<any>>;
|
||||||
|
|
||||||
/* eslint-disable react-hooks/rules-of-hooks */
|
/* eslint-disable react-hooks/rules-of-hooks */
|
||||||
|
|||||||
Reference in New Issue
Block a user