useLogsPreviewShortcuts.ts 1.5 KB

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