diff --git a/desktop/flipper-plugin/src/ui/data-table/DataTable.tsx b/desktop/flipper-plugin/src/ui/data-table/DataTable.tsx index e6cf3644f..ce8b7e536 100644 --- a/desktop/flipper-plugin/src/ui/data-table/DataTable.tsx +++ b/desktop/flipper-plugin/src/ui/data-table/DataTable.tsx @@ -313,6 +313,9 @@ export function DataTable( case 'Control': tableManager.toggleSearchValue(); break; + case 'H': + tableManager.toggleHighlightSearch(); + break; default: handled = false; } @@ -469,6 +472,7 @@ export function DataTable( dataSource, dispatch, selection, + tableState.highlightSearchSetting, tableState.columns, visibleColumns, onCopyRows, @@ -479,6 +483,7 @@ export function DataTable( dispatch, selection, tableState.columns, + tableState.highlightSearchSetting, visibleColumns, onCopyRows, onContextMenu, diff --git a/desktop/flipper-plugin/src/ui/data-table/DataTableManager.tsx b/desktop/flipper-plugin/src/ui/data-table/DataTableManager.tsx index 5345bb17a..6c3568b60 100644 --- a/desktop/flipper-plugin/src/ui/data-table/DataTableManager.tsx +++ b/desktop/flipper-plugin/src/ui/data-table/DataTableManager.tsx @@ -18,6 +18,10 @@ export type Sorting = { key: keyof T; direction: Exclude; }; +export type SearchHighlightSetting = { + highlightEnabled: boolean; + color: string; +}; export type SortDirection = 'asc' | 'desc' | undefined; @@ -46,6 +50,7 @@ type PersistedState = { scrollOffset: number; autoScroll: boolean; searchHistory: string[]; + highlightSearchSetting: SearchHighlightSetting; }; type Action = {type: Name} & Args; @@ -100,7 +105,8 @@ type DataManagerActions = | Action<'toggleAutoScroll'> | Action<'setAutoScroll', {autoScroll: boolean}> | Action<'toggleSearchValue'> - | Action<'clearSearchHistory'>; + | Action<'clearSearchHistory'> + | Action<'toggleHighlightSearch'>; type DataManagerConfig = { dataSource: DataSource; @@ -126,6 +132,7 @@ export type DataManagerState = { /** Used to remember the record entry to lookup when user presses ctrl */ previousSearchValue: string; searchHistory: string[]; + highlightSearchSetting: SearchHighlightSetting; }; export type DataTableReducer = Reducer< @@ -297,6 +304,11 @@ export const dataTableManagerReducer = produce< draft.autoScroll = action.autoScroll; break; } + case 'toggleHighlightSearch': { + draft.highlightSearchSetting.highlightEnabled = + !draft.highlightSearchSetting.highlightEnabled; + break; + } default: { throw new Error('Unknown action ' + (action as any).type); } @@ -328,6 +340,7 @@ export type DataTableManager = { setSearchValue(value: string, addToHistory?: boolean): void; dataSource: DataSource; toggleSearchValue(): void; + toggleHighlightSearch(): void; }; export function createDataTableManager( @@ -377,6 +390,9 @@ export function createDataTableManager( toggleSearchValue() { dispatch({type: 'toggleSearchValue'}); }, + toggleHighlightSearch() { + dispatch({type: 'toggleHighlightSearch'}); + }, dataSource, }; } @@ -422,6 +438,10 @@ export function createInitialState( searchHistory: prefs?.searchHistory ?? [], useRegex: prefs?.useRegex ?? false, autoScroll: prefs?.autoScroll ?? config.autoScroll ?? false, + highlightSearchSetting: prefs?.highlightSearchSetting ?? { + highlightEnabled: false, + color: '', + }, }; // @ts-ignore res.config[immerable] = false; // optimization: never proxy anything in config @@ -500,6 +520,7 @@ export function savePreferences( scrollOffset, autoScroll: state.autoScroll, searchHistory: state.searchHistory, + highlightSearchSetting: state.highlightSearchSetting, }; localStorage.setItem(state.storageKey, JSON.stringify(prefs)); } diff --git a/desktop/flipper-plugin/src/ui/data-table/TableContextMenu.tsx b/desktop/flipper-plugin/src/ui/data-table/TableContextMenu.tsx index fe8187106..fdc1aa9d0 100644 --- a/desktop/flipper-plugin/src/ui/data-table/TableContextMenu.tsx +++ b/desktop/flipper-plugin/src/ui/data-table/TableContextMenu.tsx @@ -8,12 +8,14 @@ */ import {CopyOutlined, FilterOutlined, TableOutlined} from '@ant-design/icons'; -import {Checkbox, Menu} from 'antd'; +import {Checkbox, Menu, Switch} from 'antd'; +import {Layout} from 'flipper-plugin'; import { DataTableDispatch, getSelectedItem, getSelectedItems, getValueAtPath, + SearchHighlightSetting, Selection, } from './DataTableManager'; import React from 'react'; @@ -30,6 +32,7 @@ export function tableContextMenuFactory( datasource: DataSource, dispatch: DataTableDispatch, selection: Selection, + highlightSearchSetting: SearchHighlightSetting, columns: DataTableColumn[], visibleColumns: DataTableColumn[], onCopyRows: ( @@ -177,13 +180,36 @@ export function tableContextMenuFactory( }}> Reset view - { - dispatch({type: 'clearSearchHistory'}); - }}> - Clear search history - + + + { + dispatch({type: 'clearSearchHistory'}); + }}> + Clear search history + + + { + e.stopPropagation(); + e.preventDefault(); + }}> + { + dispatch({ + type: 'toggleHighlightSearch', + }); + }} + /> + Highlight search terms + + + ); }