Integrate filter exceptions with DataTable
Summary: See previous diff for context Reviewed By: LukeDefeo Differential Revision: D47472005 fbshipit-source-id: 6e7d8873d275f826c38fab16c72e1621fd2784e1
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8397b2bab8
commit
b55d730dd7
@@ -772,8 +772,8 @@ export class DataSourceView<T, KeyType> {
|
|||||||
* They allow us to add singular items to table views.
|
* They allow us to add singular items to table views.
|
||||||
* Extremely useful for Bloks Debugger where we have to jump between multiple types of rows that could be filtered out
|
* Extremely useful for Bloks Debugger where we have to jump between multiple types of rows that could be filtered out
|
||||||
*/
|
*/
|
||||||
public setFilterExpections(ids: KeyType[]) {
|
public setFilterExpections(ids: KeyType[] | undefined) {
|
||||||
this.filterExceptions = new Set(ids);
|
this.filterExceptions = ids ? new Set(ids) : undefined;
|
||||||
this.rebuild();
|
this.rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -392,6 +392,10 @@ export function DataTable<T extends object>(
|
|||||||
tableState.columns,
|
tableState.columns,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
dataView.setFilterExpections(
|
||||||
|
tableState.filterExceptions as T[keyof T][] | undefined,
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: in the future setFilter effects could be async, at the moment it isn't,
|
// TODO: in the future setFilter effects could be async, at the moment it isn't,
|
||||||
// so we can safely assume the internal state of the dataView is updated with the
|
// so we can safely assume the internal state of the dataView is updated with the
|
||||||
// filter changes and try to find the same entry back again
|
// filter changes and try to find the same entry back again
|
||||||
@@ -438,6 +442,7 @@ export function DataTable<T extends object>(
|
|||||||
...tableState.columns.map((c) => c.filters),
|
...tableState.columns.map((c) => c.filters),
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
...tableState.columns.map((c) => c.inversed),
|
...tableState.columns.map((c) => c.inversed),
|
||||||
|
tableState.filterExceptions,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ type DataManagerActions<T> =
|
|||||||
>
|
>
|
||||||
| Action<'setColumnFilterInverse', {column: keyof T; inversed: boolean}>
|
| Action<'setColumnFilterInverse', {column: keyof T; inversed: boolean}>
|
||||||
| Action<'setColumnFilterFromSelection', {column: keyof T}>
|
| Action<'setColumnFilterFromSelection', {column: keyof T}>
|
||||||
|
| Action<'setFilterExceptions', {exceptions: string[] | undefined}>
|
||||||
| Action<'appliedInitialScroll'>
|
| Action<'appliedInitialScroll'>
|
||||||
| Action<'toggleUseRegex'>
|
| Action<'toggleUseRegex'>
|
||||||
| Action<'toggleAutoScroll'>
|
| Action<'toggleAutoScroll'>
|
||||||
@@ -164,6 +165,7 @@ export type DataManagerState<T> = {
|
|||||||
showNumberedHistory: boolean;
|
showNumberedHistory: boolean;
|
||||||
autoScroll: boolean;
|
autoScroll: boolean;
|
||||||
searchValue: string;
|
searchValue: string;
|
||||||
|
filterExceptions: string[] | undefined;
|
||||||
/** Used to remember the record entry to lookup when user presses ctrl */
|
/** Used to remember the record entry to lookup when user presses ctrl */
|
||||||
previousSearchValue: string;
|
previousSearchValue: string;
|
||||||
searchHistory: string[];
|
searchHistory: string[];
|
||||||
@@ -188,6 +190,7 @@ export const dataTableManagerReducer = produce<
|
|||||||
draft.sorting = undefined;
|
draft.sorting = undefined;
|
||||||
draft.searchValue = '';
|
draft.searchValue = '';
|
||||||
draft.selection = castDraft(emptySelection);
|
draft.selection = castDraft(emptySelection);
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'resetFilters': {
|
case 'resetFilters': {
|
||||||
@@ -195,6 +198,7 @@ export const dataTableManagerReducer = produce<
|
|||||||
c.filters?.forEach((f) => (f.enabled = false)),
|
c.filters?.forEach((f) => (f.enabled = false)),
|
||||||
);
|
);
|
||||||
draft.searchValue = '';
|
draft.searchValue = '';
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'resizeColumn': {
|
case 'resizeColumn': {
|
||||||
@@ -221,6 +225,7 @@ export const dataTableManagerReducer = produce<
|
|||||||
case 'setSearchValue': {
|
case 'setSearchValue': {
|
||||||
draft.searchValue = action.value;
|
draft.searchValue = action.value;
|
||||||
draft.previousSearchValue = '';
|
draft.previousSearchValue = '';
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
if (
|
if (
|
||||||
action.addToHistory &&
|
action.addToHistory &&
|
||||||
action.value &&
|
action.value &&
|
||||||
@@ -235,6 +240,7 @@ export const dataTableManagerReducer = produce<
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'toggleSearchValue': {
|
case 'toggleSearchValue': {
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
if (draft.searchValue) {
|
if (draft.searchValue) {
|
||||||
draft.previousSearchValue = draft.searchValue;
|
draft.previousSearchValue = draft.searchValue;
|
||||||
draft.searchValue = '';
|
draft.searchValue = '';
|
||||||
@@ -291,6 +297,7 @@ export const dataTableManagerReducer = produce<
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'addColumnFilter': {
|
case 'addColumnFilter': {
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
addColumnFilter(
|
addColumnFilter(
|
||||||
draft.columns,
|
draft.columns,
|
||||||
action.column,
|
action.column,
|
||||||
@@ -300,6 +307,7 @@ export const dataTableManagerReducer = produce<
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'removeColumnFilter': {
|
case 'removeColumnFilter': {
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
const column = draft.columns.find((c) => c.key === action.column)!;
|
const column = draft.columns.find((c) => c.key === action.column)!;
|
||||||
const index =
|
const index =
|
||||||
action.index ??
|
action.index ??
|
||||||
@@ -313,6 +321,7 @@ export const dataTableManagerReducer = produce<
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'toggleColumnFilter': {
|
case 'toggleColumnFilter': {
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
const column = draft.columns.find((c) => c.key === action.column)!;
|
const column = draft.columns.find((c) => c.key === action.column)!;
|
||||||
const index =
|
const index =
|
||||||
action.index ??
|
action.index ??
|
||||||
@@ -326,11 +335,13 @@ export const dataTableManagerReducer = produce<
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'setColumnFilterInverse': {
|
case 'setColumnFilterInverse': {
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
draft.columns.find((c) => c.key === action.column)!.inversed =
|
draft.columns.find((c) => c.key === action.column)!.inversed =
|
||||||
action.inversed;
|
action.inversed;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'setColumnFilterFromSelection': {
|
case 'setColumnFilterFromSelection': {
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
const items = getSelectedItems(
|
const items = getSelectedItems(
|
||||||
config.dataView as _DataSourceView<any, any>,
|
config.dataView as _DataSourceView<any, any>,
|
||||||
draft.selection,
|
draft.selection,
|
||||||
@@ -382,6 +393,10 @@ export const dataTableManagerReducer = produce<
|
|||||||
draft.showNumberedHistory = action.showNumberedHistory;
|
draft.showNumberedHistory = action.showNumberedHistory;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'setFilterExceptions': {
|
||||||
|
draft.filterExceptions = action.exceptions;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
throw new Error('Unknown action ' + (action as any).type);
|
throw new Error('Unknown action ' + (action as any).type);
|
||||||
}
|
}
|
||||||
@@ -425,6 +440,7 @@ export type DataTableManager<T> = {
|
|||||||
options?: AddColumnFilterOptions,
|
options?: AddColumnFilterOptions,
|
||||||
): void;
|
): void;
|
||||||
removeColumnFilter(column: keyof T, label: string): void;
|
removeColumnFilter(column: keyof T, label: string): void;
|
||||||
|
setFilterExceptions(exceptions: string[] | undefined): void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function createDataTableManager<T>(
|
export function createDataTableManager<T>(
|
||||||
@@ -495,6 +511,9 @@ export function createDataTableManager<T>(
|
|||||||
removeColumnFilter(column, label) {
|
removeColumnFilter(column, label) {
|
||||||
dispatch({type: 'removeColumnFilter', column, label});
|
dispatch({type: 'removeColumnFilter', column, label});
|
||||||
},
|
},
|
||||||
|
setFilterExceptions(exceptions: string[] | undefined) {
|
||||||
|
dispatch({type: 'setFilterExceptions', exceptions});
|
||||||
|
},
|
||||||
dataView,
|
dataView,
|
||||||
stateRef,
|
stateRef,
|
||||||
};
|
};
|
||||||
@@ -541,6 +560,7 @@ export function createInitialState<T>(
|
|||||||
searchHistory: prefs?.searchHistory ?? [],
|
searchHistory: prefs?.searchHistory ?? [],
|
||||||
useRegex: prefs?.useRegex ?? false,
|
useRegex: prefs?.useRegex ?? false,
|
||||||
filterSearchHistory: prefs?.filterSearchHistory ?? true,
|
filterSearchHistory: prefs?.filterSearchHistory ?? true,
|
||||||
|
filterExceptions: undefined,
|
||||||
autoScroll: prefs?.autoScroll ?? config.autoScroll ?? false,
|
autoScroll: prefs?.autoScroll ?? config.autoScroll ?? false,
|
||||||
highlightSearchSetting: prefs?.highlightSearchSetting ?? {
|
highlightSearchSetting: prefs?.highlightSearchSetting ?? {
|
||||||
highlightEnabled: false,
|
highlightEnabled: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user