Files
supabase/apps/studio/state/shortcuts/registry/logs-preview.ts
Ali Waseem 83992c55f7 feat(log-explorer): arrow key and deeper shortcuts for log explorer (#45989)
Closes
[FE-3378](https://linear.app/supabase/issue/FE-3378/featlogs-keyboard-shortcuts-for-function-logs-invocations-and-logs).

## Summary
Adds a shared shortcut registry for every `LogsPreviewer` surface —
Function Logs, Function Invocations, and the Logs Explorer — and brings
the grid keyboard model in line with the Auth Users / Table Editor
patterns.

## Shortcuts

| Key | Action |
| --- | --- |
| `↑` / `↓` | Move single-row selection; opens side panel |
| `Shift+Space` | Toggle current row in multi-select |
| `Mod+A` | Toggle all visible rows in multi-select |
| `Esc` | Staged: clear multi-select → close side panel |
| `Shift+R` | Refresh logs |
| `Shift+H` | Toggle histogram |
| `Shift+L` | Load older logs |
| `Shift+P` | Open time range picker |
| `Mod+Shift+J / M / C` | Copy selected rows as JSON / Markdown / CSV
(existing global handler) |

## Other changes
- `ShortcutTooltip` on search, refresh, histogram, load older, and
time-picker controls.
- `onSearchInputEscape` wired on the logs search bar (clear → blur).
- Visual row highlight (`rdg-row--focused`) when a row is
keyboard-focused or multi-selected.
- Multi-select copy dropdown gains a **Copy as CSV** entry and shows the
keybind on each item via `ShortcutBadge`.
- Manual arrow-nav (`navigate()`) updates `selectedRow` directly without
going through `onRowClick`, so multi-select checkmarks survive keyboard
navigation.

## Test plan
- [x] Function Logs and Function Invocations: all shortcuts above fire
while the page is mounted, no firing in other tabs.
- [x] Logs Explorer: same shortcuts work; copy keybinds still copy *all*
rows when nothing is multi-selected.
- [x] Arrow keys on first load select the first row even when the focus
sink is the active element.
- [x] Selecting rows via checkbox or `Shift+Space`, then pressing arrow
keys, preserves the checkmarks.
- [x] Escape on a populated search input clears it; Escape on an empty
input blurs it.
- [x] Esc with multi-select active clears the selection before closing
the side panel.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* CSV export for log selections (adds CSV alongside JSON and Markdown).
* New logs-preview keyboard shortcuts: search focus, refresh, chart
toggle, date picker, load older, navigation, and selection.

* **Improvements**
  * Shortcut badges and tooltip integration across the logs UI.
* Search input focus/ref support and controlled date-picker visibility.
  * Better no-results/error rendering and expanded copy dropdown sizing.

* **Tests**
  * Added CSV formatting tests covering RFC 4180 edge cases.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45989)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-19 15:25:47 +00:00

100 lines
4.0 KiB
TypeScript

import { RegistryDefinations } from '../types'
/**
* Shortcuts scoped to the LogsPreviewer component — used by Function Logs,
* Function Invocations, and the Logs Explorer page. They are page-scoped:
* each shortcut is only active while LogsPreviewer is mounted.
*
* Grid-related bindings (start-nav, toggle-all, toggle-row, escape) mirror the
* Auth Users / Table Editor patterns so the keyboard model stays consistent
* across our react-data-grid surfaces.
*/
export const LOGS_PREVIEW_SHORTCUT_IDS = {
LOGS_PREVIEW_REFRESH: 'logs-preview.refresh',
LOGS_PREVIEW_TOGGLE_CHART: 'logs-preview.toggle-chart',
LOGS_PREVIEW_LOAD_OLDER: 'logs-preview.load-older',
LOGS_PREVIEW_TOGGLE_DATE_PICKER: 'logs-preview.toggle-date-picker',
LOGS_PREVIEW_TOGGLE_ALL_SELECTION: 'logs-preview.toggle-all-selection',
LOGS_PREVIEW_TOGGLE_ROW_SELECTION: 'logs-preview.toggle-row-selection',
LOGS_PREVIEW_EXIT_SELECTION: 'logs-preview.exit-selection',
LOGS_PREVIEW_CLOSE_PANEL: 'logs-preview.close-panel',
LOGS_PREVIEW_START_NAV_DOWN: 'logs-preview.start-nav-down',
LOGS_PREVIEW_START_NAV_UP: 'logs-preview.start-nav-up',
}
export type LogsPreviewShortcutId =
(typeof LOGS_PREVIEW_SHORTCUT_IDS)[keyof typeof LOGS_PREVIEW_SHORTCUT_IDS]
export const logsPreviewRegistry: RegistryDefinations<LogsPreviewShortcutId> = {
[LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_REFRESH]: {
id: LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_REFRESH,
label: 'Refresh logs',
sequence: ['Shift+R'],
showInSettings: false,
options: { ignoreInputs: true, registerInCommandMenu: true },
},
[LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_TOGGLE_CHART]: {
id: LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_TOGGLE_CHART,
label: 'Toggle histogram',
sequence: ['Shift+H'],
showInSettings: false,
options: { ignoreInputs: true, registerInCommandMenu: true },
},
[LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_LOAD_OLDER]: {
id: LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_LOAD_OLDER,
label: 'Load older logs',
sequence: ['Shift+L'],
showInSettings: false,
options: { ignoreInputs: true, registerInCommandMenu: true },
},
[LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_TOGGLE_DATE_PICKER]: {
id: LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_TOGGLE_DATE_PICKER,
label: 'Open time range picker',
sequence: ['Shift+P'],
showInSettings: false,
options: { ignoreInputs: true, registerInCommandMenu: true },
},
[LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_TOGGLE_ALL_SELECTION]: {
id: LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_TOGGLE_ALL_SELECTION,
label: 'Toggle selection on all displayed logs',
sequence: ['Mod+A'],
showInSettings: false,
options: { ignoreInputs: true },
},
[LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_TOGGLE_ROW_SELECTION]: {
id: LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_TOGGLE_ROW_SELECTION,
label: 'Toggle selection on current row',
sequence: ['Shift+Space'],
showInSettings: false,
options: { ignoreInputs: true },
},
[LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_EXIT_SELECTION]: {
id: LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_EXIT_SELECTION,
label: 'Clear log selection',
sequence: ['Escape'],
showInSettings: false,
options: { ignoreInputs: true, conflictBehavior: 'allow' },
},
[LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_CLOSE_PANEL]: {
id: LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_CLOSE_PANEL,
label: 'Close log details panel',
sequence: ['Escape'],
showInSettings: false,
options: { ignoreInputs: true, conflictBehavior: 'allow' },
},
[LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_START_NAV_DOWN]: {
id: LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_START_NAV_DOWN,
label: 'Move focus into logs grid',
sequence: ['ArrowDown'],
showInSettings: false,
options: { ignoreInputs: true },
},
[LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_START_NAV_UP]: {
id: LOGS_PREVIEW_SHORTCUT_IDS.LOGS_PREVIEW_START_NAV_UP,
label: 'Move focus into logs grid',
sequence: ['ArrowUp'],
showInSettings: false,
options: { ignoreInputs: true },
},
}