* feat: create view from selected filters and sorts Closes #1292 * refactor: use selector to obtain table filters where query option * refactor: activate exhaustive deps eslint rule for useRecoilCallback * feat: switch to newly created view on view creation Closes #1297 * refactor: code review - use `useCallback` instead of `useRecoilCallback` - rename `useTableViews` to `useViews` - move filter-n-sort selectors to /states/selector subfolder
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { useRecoilCallback } from 'recoil';
|
|
|
|
import { currentHotkeyScopeState } from '@/ui/utilities/hotkey/states/internal/currentHotkeyScopeState';
|
|
|
|
import { isSoftFocusActiveState } from '../states/isSoftFocusActiveState';
|
|
import { TableHotkeyScope } from '../types/TableHotkeyScope';
|
|
|
|
import { useCloseCurrentCellInEditMode } from './useClearCellInEditMode';
|
|
import { useDisableSoftFocus } from './useDisableSoftFocus';
|
|
|
|
export function useLeaveTableFocus() {
|
|
const disableSoftFocus = useDisableSoftFocus();
|
|
const closeCurrentCellInEditMode = useCloseCurrentCellInEditMode();
|
|
|
|
return useRecoilCallback(
|
|
({ snapshot }) =>
|
|
() => {
|
|
const isSoftFocusActive = snapshot
|
|
.getLoadable(isSoftFocusActiveState)
|
|
.valueOrThrow();
|
|
|
|
const currentHotkeyScope = snapshot
|
|
.getLoadable(currentHotkeyScopeState)
|
|
.valueOrThrow();
|
|
|
|
if (!isSoftFocusActive) {
|
|
return;
|
|
}
|
|
|
|
if (currentHotkeyScope?.scope === TableHotkeyScope.Table) {
|
|
return;
|
|
}
|
|
|
|
closeCurrentCellInEditMode();
|
|
disableSoftFocus();
|
|
},
|
|
[closeCurrentCellInEditMode, disableSoftFocus],
|
|
);
|
|
}
|