/** * Internal types */ import { Column, PluginHook, TableInstance, Row, ColumnInstance, UseExpandedRowProps, UseGroupByColumnProps, UseFiltersColumnProps, UseSortByColumnProps, TableOptions, Cell, } from 'react-table'; export type Omit = Pick> export type TableStateDefault = { [key: string]: any }; // @todo: better typings export type TableParamFactory = any> = (params: TableOptions) => IInstance; export type TableStateFactory = (state: TableStateDefault) => TableStateDefault; export type AddOnPredicate = (columnOrRow: any) => boolean; export type GlobalActionName = string | null; export type TableActionName = string | null; export type TableAddOnReturn = [GlobalActionName, TableActionName, AddOnPredicate, TableParamFactory, TableStateFactory, PluginHook] export type RelatableAction = [string, AddOnPredicate]; export type ToolbarAction = { name: string, column?: any } export type ToolbarActionDispatch = (name: string, column?: any) => void export enum RELATABLE_ICONS { SORT = 'SORT', SORT_ASC = 'SORT_ASC', SORT_DESC = 'SORT_DESC', FILTER = 'FILTER', GROUP_BY = 'GROUP_BY', } export interface IRelatableStateInstance extends TableInstance { availableGlobalActions: RelatableAction[]; availableTableActions: RelatableAction[]; getCustomCellColSpan: CellCollSpanGetter[]; _originalColumns: Column[]; _rowsToUse: Row[]; state: State; // add-on methods onCustomExpandedChange?: ExpandSetter; onCustomSelectionChange?: SelectSetter; onCustomFiltersChange?: FilterSetter; onCustomGroupingChange?: GroupSetter; onCustomSortChange?: SortSetter; onCustomPageSizeChange?: PageSizeSetter; onCustomPageChange?: PageSetter; } /** * Externally exposed types */ export type CellCollSpanGetter = (cell: Cell) => number | string | undefined; export type StateChangeHandler = (state: Partial, changedKeys: string[]) => void; export type PageSetter = (pageIndex: number) => void; export type PageSizeSetter = (pageSize: number) => void; export type GroupSetter = (column: (ColumnInstance & UseGroupByColumnProps), group: boolean) => void; export type ExpandSetter = (rows: (Row & UseExpandedRowProps)[], expand: boolean) => void; export type SelectSetter = (rows: Row[], select: boolean) => void; /* Sorting */ export enum SORT_ACTIONS { SORT_CLEAR = 'SORT_CLEAR', SORT_DESC = 'SORT_DESC', SORT_ASC = 'SORT_ASC', } export type SortSetter = (column: (ColumnInstance & UseSortByColumnProps), action: SORT_ACTIONS) => void; /* Filters */ export enum FILTER_ACTIONS { FILTER_CLEAR = 'FILTER_CLEAR', FILTER_ADD = 'FILTER_ADD', FILTER_REMOVE = 'FILTER_REMOVE', } export type FilterSetter = (column: (ColumnInstance & UseFiltersColumnProps), action: FILTER_ACTIONS, values: any[]) => void;