Simplify data table power search config for each column
Summary: Doc: https://docs.google.com/document/d/1miofxds9DJgWScj0zFyBbdpRH5Rj0T9FqiCapof5-vU/edit#heading=h.pg8svtdjlx7 Reviewed By: antonk52 Differential Revision: D49410973 fbshipit-source-id: d8854eefaf1901c4984300df955a15c77c03505e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3b75b6994b
commit
3022b8ddb1
@@ -61,7 +61,7 @@ export {DataTable, DataTableColumn} from './ui/data-table/DataTable';
|
||||
export {DataTableManager} from './ui/data-table/DataTableManager';
|
||||
export {
|
||||
DataTable as _DataTableWithPowerSearch,
|
||||
DataTableColumn as _DataColumnWithPowerSearch,
|
||||
DataTableColumn as _DataTableColumnWithPowerSearch,
|
||||
} from './ui/data-table/DataTableWithPowerSearch';
|
||||
export {DataTableManager as _DataTableWithPowerSearchManager} from './ui/data-table/DataTableWithPowerSearchManager';
|
||||
export {DataList} from './ui/DataList';
|
||||
|
||||
@@ -61,7 +61,12 @@ import {
|
||||
_DataSourceView,
|
||||
} from 'flipper-plugin-core';
|
||||
import {useLatestRef} from '../../utils/useLatestRef';
|
||||
import {PowerSearch, PowerSearchConfig, FieldConfig} from '../PowerSearch';
|
||||
import {
|
||||
PowerSearch,
|
||||
PowerSearchConfig,
|
||||
FieldConfig,
|
||||
OperatorConfig,
|
||||
} from '../PowerSearch';
|
||||
import {
|
||||
dataTablePowerSearchOperatorProcessorConfig,
|
||||
dataTablePowerSearchOperators,
|
||||
@@ -124,13 +129,7 @@ export type DataTableColumn<T = any> = {
|
||||
visible?: boolean;
|
||||
inversed?: boolean;
|
||||
sortable?: boolean;
|
||||
powerSearchConfig?:
|
||||
| {
|
||||
[K in keyof typeof dataTablePowerSearchOperators]: ReturnType<
|
||||
(typeof dataTablePowerSearchOperators)[K]
|
||||
>;
|
||||
}
|
||||
| false;
|
||||
powerSearchConfig?: OperatorConfig[] | false;
|
||||
};
|
||||
|
||||
export interface TableRowRenderContext<T = any> {
|
||||
@@ -249,7 +248,10 @@ export function DataTable<T extends object>(
|
||||
label: column.title ?? column.key,
|
||||
key: column.key,
|
||||
// If no power search config provided we treat every input as a string
|
||||
operators: column.powerSearchConfig ?? {
|
||||
operators: column.powerSearchConfig?.reduce((res, operatorConfig) => {
|
||||
res[operatorConfig.key] = operatorConfig;
|
||||
return res;
|
||||
}, {} as Record<string, OperatorConfig>) ?? {
|
||||
string_contains: dataTablePowerSearchOperators.string_contains(),
|
||||
string_not_contains:
|
||||
dataTablePowerSearchOperators.string_not_contains(),
|
||||
|
||||
Reference in New Issue
Block a user