update control filter toggling implementation

Summary:
The `Control` button press, that hides the current search filter, had some specific logic to make sure that the current selection remained visible. Since this is now generically supported, this is no longer needed.

Also updated the `Control` button behavior to also toggle back the search filter if needed, which was never finished in the original implementation.

Changelog: DataTable: pressing the control key can be used to temporarily turn the current search filter on and off.

Reviewed By: aigoncharov

Differential Revision: D36736494

fbshipit-source-id: 2c4949efa0d6935735f61ee43f9268b7e27d1fcf
This commit is contained in:
Michel Weststrate
2022-06-07 04:04:01 -07:00
committed by Facebook GitHub Bot
parent 2037cf0595
commit 36b78131b7
2 changed files with 18 additions and 56 deletions

View File

@@ -311,7 +311,7 @@ export function DataTable<T extends object>(
tableManager.clearSelection();
break;
case 'Control':
tableManager.setSelectedSearchRecord();
tableManager.toggleSearchValue();
break;
default:
handled = false;
@@ -505,30 +505,6 @@ export function DataTable<T extends object>(
// eslint-disable-next-line
}, []);
useEffect(
function findMappedIndex() {
// Hardcoded delay to give dataSource.view time to update, otherwise
// the entries we loop over here won't be the list of unfiltered records
// the user sees, so there won't be a match found
const delay = 300;
if (tableState.selectedSearchRecord) {
const timer = setTimeout(() => {
for (let i = 0; i < dataSource.view.size; i++) {
if (dataSource.view.get(i) === tableState.selectedSearchRecord) {
tableManager.clearSelectedSearchRecord();
tableManager.selectItem(i, false, true);
break;
}
}
}, delay);
return () => clearTimeout(timer);
}
},
[dataSource, selection, tableManager, tableState.selectedSearchRecord],
);
const header = (
<Layout.Container>
{props.enableSearchbar && (