useLogsPreviewShortcuts.ts52 lines · main
| 1 | import type { RefObject } from 'react' |
| 2 | |
| 3 | import { SHORTCUT_IDS } from '@/state/shortcuts/registry' |
| 4 | import { useShortcut } from '@/state/shortcuts/useShortcut' |
| 5 | |
| 6 | interface UseLogsPreviewShortcutsParams { |
| 7 | searchInputRef: RefObject<HTMLInputElement | null> |
| 8 | hasSearch: boolean |
| 9 | onResetSearch: () => void |
| 10 | onRefresh: () => void |
| 11 | onToggleChart: () => void |
| 12 | onLoadOlder: () => void |
| 13 | canLoadOlder: boolean |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Toolbar-level shortcuts for the LogsPreviewer (search focus, reset filters, |
| 18 | * refresh, toggle histogram, load older). Grid-level shortcuts (selection, |
| 19 | * arrow navigation, escape) live alongside the grid in LogTable. |
| 20 | * |
| 21 | * Mounted once inside LogsPreviewer so the shortcuts auto-activate on every |
| 22 | * consumer of the component (function logs, function invocations, logs |
| 23 | * explorer). |
| 24 | */ |
| 25 | export function useLogsPreviewShortcuts({ |
| 26 | searchInputRef, |
| 27 | hasSearch, |
| 28 | onResetSearch, |
| 29 | onRefresh, |
| 30 | onToggleChart, |
| 31 | onLoadOlder, |
| 32 | canLoadOlder, |
| 33 | }: UseLogsPreviewShortcutsParams) { |
| 34 | useShortcut( |
| 35 | SHORTCUT_IDS.LIST_PAGE_FOCUS_SEARCH, |
| 36 | () => { |
| 37 | searchInputRef.current?.focus() |
| 38 | searchInputRef.current?.select() |
| 39 | }, |
| 40 | { label: 'Search logs' } |
| 41 | ) |
| 42 | |
| 43 | useShortcut(SHORTCUT_IDS.LIST_PAGE_RESET_FILTERS, onResetSearch, { |
| 44 | enabled: hasSearch, |
| 45 | }) |
| 46 | |
| 47 | useShortcut(SHORTCUT_IDS.LOGS_PREVIEW_REFRESH, onRefresh) |
| 48 | |
| 49 | useShortcut(SHORTCUT_IDS.LOGS_PREVIEW_TOGGLE_CHART, onToggleChart) |
| 50 | |
| 51 | useShortcut(SHORTCUT_IDS.LOGS_PREVIEW_LOAD_OLDER, onLoadOlder, { enabled: canLoadOlder }) |
| 52 | } |