Skip to content

Commit

Permalink
Integrate filter exceptions with DataTable
Browse files Browse the repository at this point in the history
Summary: See previous diff for context

Reviewed By: LukeDefeo

Differential Revision: D47472005

fbshipit-source-id: 6e7d8873d275f826c38fab16c72e1621fd2784e1
  • Loading branch information
aigoncharov authored and facebook-github-bot committed Jul 18, 2023
1 parent 8397b2b commit b55d730
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions desktop/flipper-plugin-core/src/data-source/DataSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ export class DataSourceView<T, KeyType> {
* 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
*/
public setFilterExpections(ids: KeyType[]) {
this.filterExceptions = new Set(ids);
public setFilterExpections(ids: KeyType[] | undefined) {
this.filterExceptions = ids ? new Set(ids) : undefined;
this.rebuild();
}

Expand Down
5 changes: 5 additions & 0 deletions desktop/flipper-plugin/src/ui/data-table/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ export function DataTable<T extends object>(
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,
// 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
Expand Down Expand Up @@ -438,6 +442,7 @@ export function DataTable<T extends object>(
...tableState.columns.map((c) => c.filters),
// eslint-disable-next-line react-hooks/exhaustive-deps
...tableState.columns.map((c) => c.inversed),
tableState.filterExceptions,
],
);

Expand Down
20 changes: 20 additions & 0 deletions desktop/flipper-plugin/src/ui/data-table/DataTableManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ type DataManagerActions<T> =
>
| Action<'setColumnFilterInverse', {column: keyof T; inversed: boolean}>
| Action<'setColumnFilterFromSelection', {column: keyof T}>
| Action<'setFilterExceptions', {exceptions: string[] | undefined}>
| Action<'appliedInitialScroll'>
| Action<'toggleUseRegex'>
| Action<'toggleAutoScroll'>
Expand Down Expand Up @@ -164,6 +165,7 @@ export type DataManagerState<T> = {
showNumberedHistory: boolean;
autoScroll: boolean;
searchValue: string;
filterExceptions: string[] | undefined;
/** Used to remember the record entry to lookup when user presses ctrl */
previousSearchValue: string;
searchHistory: string[];
Expand All @@ -188,13 +190,15 @@ export const dataTableManagerReducer = produce<
draft.sorting = undefined;
draft.searchValue = '';
draft.selection = castDraft(emptySelection);
draft.filterExceptions = undefined;
break;
}
case 'resetFilters': {
draft.columns.forEach((c) =>
c.filters?.forEach((f) => (f.enabled = false)),
);
draft.searchValue = '';
draft.filterExceptions = undefined;
break;
}
case 'resizeColumn': {
Expand All @@ -221,6 +225,7 @@ export const dataTableManagerReducer = produce<
case 'setSearchValue': {
draft.searchValue = action.value;
draft.previousSearchValue = '';
draft.filterExceptions = undefined;
if (
action.addToHistory &&
action.value &&
Expand All @@ -235,6 +240,7 @@ export const dataTableManagerReducer = produce<
break;
}
case 'toggleSearchValue': {
draft.filterExceptions = undefined;
if (draft.searchValue) {
draft.previousSearchValue = draft.searchValue;
draft.searchValue = '';
Expand Down Expand Up @@ -291,6 +297,7 @@ export const dataTableManagerReducer = produce<
break;
}
case 'addColumnFilter': {
draft.filterExceptions = undefined;
addColumnFilter(
draft.columns,
action.column,
Expand All @@ -300,6 +307,7 @@ export const dataTableManagerReducer = produce<
break;
}
case 'removeColumnFilter': {
draft.filterExceptions = undefined;
const column = draft.columns.find((c) => c.key === action.column)!;
const index =
action.index ??
Expand All @@ -313,6 +321,7 @@ export const dataTableManagerReducer = produce<
break;
}
case 'toggleColumnFilter': {
draft.filterExceptions = undefined;
const column = draft.columns.find((c) => c.key === action.column)!;
const index =
action.index ??
Expand All @@ -326,11 +335,13 @@ export const dataTableManagerReducer = produce<
break;
}
case 'setColumnFilterInverse': {
draft.filterExceptions = undefined;
draft.columns.find((c) => c.key === action.column)!.inversed =
action.inversed;
break;
}
case 'setColumnFilterFromSelection': {
draft.filterExceptions = undefined;
const items = getSelectedItems(
config.dataView as _DataSourceView<any, any>,
draft.selection,
Expand Down Expand Up @@ -382,6 +393,10 @@ export const dataTableManagerReducer = produce<
draft.showNumberedHistory = action.showNumberedHistory;
break;
}
case 'setFilterExceptions': {
draft.filterExceptions = action.exceptions;
break;
}
default: {
throw new Error('Unknown action ' + (action as any).type);
}
Expand Down Expand Up @@ -425,6 +440,7 @@ export type DataTableManager<T> = {
options?: AddColumnFilterOptions,
): void;
removeColumnFilter(column: keyof T, label: string): void;
setFilterExceptions(exceptions: string[] | undefined): void;
};

export function createDataTableManager<T>(
Expand Down Expand Up @@ -495,6 +511,9 @@ export function createDataTableManager<T>(
removeColumnFilter(column, label) {
dispatch({type: 'removeColumnFilter', column, label});
},
setFilterExceptions(exceptions: string[] | undefined) {
dispatch({type: 'setFilterExceptions', exceptions});
},
dataView,
stateRef,
};
Expand Down Expand Up @@ -541,6 +560,7 @@ export function createInitialState<T>(
searchHistory: prefs?.searchHistory ?? [],
useRegex: prefs?.useRegex ?? false,
filterSearchHistory: prefs?.filterSearchHistory ?? true,
filterExceptions: undefined,
autoScroll: prefs?.autoScroll ?? config.autoScroll ?? false,
highlightSearchSetting: prefs?.highlightSearchSetting ?? {
highlightEnabled: false,
Expand Down

0 comments on commit b55d730

Please sign in to comment.