Add boilerplate for data table power search config and processors

Summary: Doc: https://docs.google.com/document/d/1miofxds9DJgWScj0zFyBbdpRH5Rj0T9FqiCapof5-vU/edit#heading=h.pg8svtdjlx7

Reviewed By: lblasa

Differential Revision: D49230144

fbshipit-source-id: d6e6dfb340fd23c8655e331869600cb474c8e8bc
This commit is contained in:
Andrey Goncharov
2023-09-14 04:48:12 -07:00
committed by Facebook GitHub Bot
parent f897ab9487
commit 589937bc8f
2 changed files with 22 additions and 2 deletions

View File

@@ -17,3 +17,10 @@ export type PowerSearchOperatorProcessor = (
export type PowerSearchOperatorProcessorConfig = { export type PowerSearchOperatorProcessorConfig = {
[key: string]: PowerSearchOperatorProcessor; [key: string]: PowerSearchOperatorProcessor;
}; };
export const dataTablePowerSearchOperators = {} satisfies {
[key: string]: (...args: any[]) => OperatorConfig;
};
export const dataTablePowerSearchOperatorProcessorConfig =
{} satisfies PowerSearchOperatorProcessorConfig;

View File

@@ -58,6 +58,10 @@ import {
import {useLatestRef} from '../../utils/useLatestRef'; import {useLatestRef} from '../../utils/useLatestRef';
import {PowerSearch, OperatorConfig} from '../PowerSearch'; import {PowerSearch, OperatorConfig} from '../PowerSearch';
import {powerSearchExampleConfig} from '../PowerSearch/PowerSearchExampleConfig'; import {powerSearchExampleConfig} from '../PowerSearch/PowerSearchExampleConfig';
import {
dataTablePowerSearchOperatorProcessorConfig,
dataTablePowerSearchOperators,
} from './DataTableDefaultPowerSearchOperators';
type DataTableBaseProps<T = any> = { type DataTableBaseProps<T = any> = {
columns: DataTableColumn<T>[]; columns: DataTableColumn<T>[];
@@ -116,7 +120,11 @@ export type DataTableColumn<T = any> = {
visible?: boolean; visible?: boolean;
inversed?: boolean; inversed?: boolean;
sortable?: boolean; sortable?: boolean;
powerSearchConfig?: {[key: string]: OperatorConfig}; powerSearchConfig?: {
[K in keyof typeof dataTablePowerSearchOperators]: ReturnType<
(typeof dataTablePowerSearchOperators)[K]
>;
};
}; };
export interface TableRowRenderContext<T = any> { export interface TableRowRenderContext<T = any> {
@@ -369,7 +377,12 @@ export function DataTable<T extends object>(
tableState.selection.current >= 0 tableState.selection.current >= 0
? dataView.getEntry(tableState.selection.current) ? dataView.getEntry(tableState.selection.current)
: null; : null;
dataView.setFilter(computeDataTableFilter(tableState.searchExpression, {})); dataView.setFilter(
computeDataTableFilter(
tableState.searchExpression,
dataTablePowerSearchOperatorProcessorConfig,
),
);
dataView.setFilterExpections( dataView.setFilterExpections(
tableState.filterExceptions as T[keyof T][] | undefined, tableState.filterExceptions as T[keyof T][] | undefined,
); );