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:
Andrey Goncharov
2023-09-19 08:19:25 -07:00
committed by Facebook GitHub Bot
parent 3b75b6994b
commit 3022b8ddb1
2 changed files with 12 additions and 10 deletions

View File

@@ -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(),