From b2292f9963aef96ae25bc62dfc2a797ebc7dcd5e Mon Sep 17 00:00:00 2001 From: Jason Clark Date: Thu, 12 Mar 2020 16:57:36 -0600 Subject: [PATCH] [react-table]Added disableGlobalFilter in prep for 7.0.0 stable (#43014) * Added disableGlobalFilter in prep for 7.0.0 stable * Cleaned up prettier violation Co-authored-by: Jason Clark --- types/react-table/Readme.md | 2 ++ types/react-table/index.d.ts | 23 +++++++++++++++++++---- types/react-table/react-table-tests.tsx | 10 +++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/types/react-table/Readme.md b/types/react-table/Readme.md index b413169dbd..6f99dbf5b4 100644 --- a/types/react-table/Readme.md +++ b/types/react-table/Readme.md @@ -56,6 +56,7 @@ import { UseFiltersInstanceProps, UseFiltersOptions, UseFiltersState, + UseGlobalFiltersColumnOptions, UseGlobalFiltersInstanceProps, UseGlobalFiltersOptions, UseGlobalFiltersState, @@ -141,6 +142,7 @@ declare module 'react-table' { export interface Column extends UseFiltersColumnOptions, + UseGlobalFiltersColumnOptions, UseGroupByColumnOptions, UseResizeColumnsColumnOptions, UseSortByColumnOptions {} diff --git a/types/react-table/index.d.ts b/types/react-table/index.d.ts index 28f128ab68..5a6cdfafe5 100644 --- a/types/react-table/index.d.ts +++ b/types/react-table/index.d.ts @@ -6,7 +6,7 @@ // Jason Clark // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.5 -// reflects react-table@7.0.0-rc.16 +// reflects react-table@7.0.0 - (prepping for stable 7.0.0 release https://github.com/tannerlinsley/react-table/issues/1964) // tslint:disable:no-empty-interface // no-empty-interface is disabled to allow easy extension with declaration merging @@ -15,7 +15,17 @@ // no-unnecessary-generics is disabled because many of these definitions are either used in a generic // context or the signatures are required to match for declaration merging -import { ComponentType, DependencyList, EffectCallback, MouseEvent, ReactElement, ReactNode, ReactText, ReactFragment, CSSProperties } from 'react'; +import { + ComponentType, + DependencyList, + EffectCallback, + MouseEvent, + ReactElement, + ReactNode, + ReactText, + ReactFragment, + CSSProperties, +} from 'react'; export {}; @@ -237,7 +247,7 @@ export interface UseTableColumnProps { depth: number; // not documented index: number; // not documented placeholderOf?: ColumnInstance; - } +} export interface UseTableRowProps { cells: Array>; @@ -457,12 +467,17 @@ export type UseGlobalFiltersOptions = Partial<{ manualGlobalFilter: boolean; filterTypes: FilterTypes; autoResetGlobalFilter?: boolean; + disableGlobalFilter?: boolean; }>; export interface UseGlobalFiltersState { globalFilter: any; } +export type UseGlobalFiltersColumnOptions = Partial<{ + disableGlobalFilter?: boolean; +}>; + export interface UseGlobalFiltersInstanceProps { preGlobalFilteredRows: Array>; preGlobalFilteredFlatRows: Array>; @@ -820,7 +835,7 @@ export function loopHooks(hooks: Hooks, ...args: any[]): void; export function ensurePluginOrder( plugins: Array>, befores: string[], - pluginName: string + pluginName: string, ): void; export function functionalUpdate( diff --git a/types/react-table/react-table-tests.tsx b/types/react-table/react-table-tests.tsx index 3e24153400..853adf6025 100644 --- a/types/react-table/react-table-tests.tsx +++ b/types/react-table/react-table-tests.tsx @@ -25,6 +25,8 @@ import { UseFiltersInstanceProps, UseFiltersOptions, UseFiltersState, + UseGlobalFiltersOptions, + UseGlobalFiltersColumnOptions, useGroupBy, UseGroupByCellProps, UseGroupByColumnOptions, @@ -49,6 +51,7 @@ import { UseSortByOptions, UseSortByState, useTable, + useGlobalFilter, } from 'react-table'; declare module 'react-table' { @@ -57,6 +60,7 @@ declare module 'react-table' { interface TableOptions extends UseExpandedOptions, UseFiltersOptions, + UseGlobalFiltersOptions, UseGroupByOptions, UsePaginationOptions, UseRowSelectOptions, @@ -84,6 +88,7 @@ declare module 'react-table' { interface Column extends UseFiltersColumnOptions, + UseGlobalFiltersColumnOptions, UseGroupByColumnOptions, UseSortByColumnOptions {} @@ -360,6 +365,7 @@ function Table({ columns, data, updateMyData, skipPageReset }: Table) { }, useGroupBy, useFilters, + useGlobalFilter, useSortBy, useExpanded, usePagination, @@ -439,7 +445,8 @@ function Table({ columns, data, updateMyData, skipPageReset }: Table) { // If the cell is aggregated, use the Aggregated // renderer for cell cell.render('Aggregated') - ) : cell.isPlaceholder ? null : (// For cells with repeated values, render null + ) : cell.isPlaceholder ? null : ( + // For cells with repeated values, render null // Otherwise, just render the regular cell cell.render('Cell', { editable: true }) )} @@ -625,6 +632,7 @@ const Component = (props: {}) => { // Aggregate the average age of visitors aggregate: 'average', Aggregated: ({ cell: { value } }: CellProps) => `${value} (avg)`, + disableGlobalFilter: true, }, { Header: 'Visits',