Feat/better hotkeys scope (#526)

* Working version

* fix

* Fixed console log

* Fix lint

* wip

* Fix

* Fix

* consolelog

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Lucas Bordeau
2023-07-08 03:53:05 +02:00
committed by GitHub
parent 611cda1f41
commit 66dcc9b2e1
77 changed files with 1240 additions and 454 deletions
@@ -13,6 +13,8 @@ import {
SortType,
} from '@/filters-and-sorts/interfaces/sorts/interface';
import { RecoilScope } from '@/recoil-scope/components/RecoilScope';
import { useListenClickOutsideArrayOfRef } from '@/ui/hooks/useListenClickOutsideArrayOfRef';
import { useLeaveTableFocus } from '@/ui/tables/hooks/useLeaveTableFocus';
import { RowContext } from '@/ui/tables/states/RowContext';
import { currentRowSelectionState } from '../../tables/states/rowSelectionState';
@@ -103,6 +105,8 @@ export function EntityTable<TData extends { id: string }, SortField>({
availableSorts,
onSortsUpdate,
}: OwnProps<TData, SortField>) {
const tableBodyRef = React.useRef<HTMLDivElement>(null);
const [currentRowSelection, setCurrentRowSelection] = useRecoilState(
currentRowSelectionState,
);
@@ -119,6 +123,12 @@ export function EntityTable<TData extends { id: string }, SortField>({
getRowId: (row) => row.id,
});
const leaveTableFocus = useLeaveTableFocus();
useListenClickOutsideArrayOfRef([tableBodyRef], () => {
leaveTableFocus();
});
return (
<StyledTableWithHeader>
<TableHeader
@@ -127,7 +137,7 @@ export function EntityTable<TData extends { id: string }, SortField>({
availableSorts={availableSorts}
onSortsUpdate={onSortsUpdate}
/>
<StyledTableScrollableContainer>
<StyledTableScrollableContainer ref={tableBodyRef}>
<StyledTable>
<thead>
{table.getHeaderGroups().map((headerGroup) => (