mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 09:20:21 -04:00
618c902e1a
## Summary Adds the `O→S` / `Shift+F` / `Shift+N` / `F→C` shortcut set across every Database listing page, on top of the schema-visualizer pattern from #45386. Fixes [FE-3131](https://linear.app/supabase/issue/FE-3131). A shared `list-page.*` registry replaces what would have been a per-page registry file for each route, and `useShortcut`/`Shortcut` gain a `label` override so a single ID renders contextually in Cmd+K and hover tooltips. ## Pages and shortcuts | Page | `O→S` | `Shift+F` | `Shift+N` | `F→C` | | --- | --- | --- | --- | --- | | Tables | Open schema selector | Search tables | Create new table | Clears search + entity-type filter | | Functions | Open schema selector | Search functions | Create new function | Clears search + Return Type + Security | | Triggers — data | Open schema selector | Search triggers | Create new trigger | Clears search + Table filter | | Triggers — event | — | Search event triggers | Create new event trigger | Clears search + Owner filter | | Enumerated Types | Open schema selector | Search enumerated types | Create new enumerated type | Clears search | | Indexes | Open schema selector | Search indexes | Create new index | Clears search | | Roles | — | Search roles | Add new role | Clears search + filter type → 'all' | | Publications | — | Search publications | — | Clears search | | Extensions | — | Search extensions | — | Clears search | `Shift+N` only fires when the page-specific gate allows it (permission + unlocked schema + any other prerequisite like `hasTables` for triggers). ## Test plan - [ ] On each of the 9 pages, all four shortcuts behave as listed in the table above - [ ] Hover the wrapped controls — tooltip shows the page-specific label and the right keybind badge - [ ] Open the schema selector via `O→S` — the hover tooltip is suppressed while the popover is open - [ ] `Shift+N` is a no-op on locked schemas / when permission is missing / when a prereq fails (e.g. no tables on Triggers data) - [ ] `Shift+F` focuses the search input; while focused, Escape clears (with text) → Escape blurs (when empty) - [ ] `Cmd+K` shows the page-specific shortcut name while on each page; the entry goes away on navigation - [ ] `Mod+/` reference sheet shows one "List pages" group with 4 generic entries - [ ] No regression to existing schema-visualizer / table-editor / SQL-editor shortcut behavior <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a dedicated list-page shortcut group in the shortcuts reference. * **Improvements** * Keyboard shortcuts across database list pages: focus & select search, reset filters, and create-new-item shortcuts. * Escape now clears/searches or blurs inputs to avoid accidental popover closes. * Create/new buttons respond to shortcuts when allowed; disabled actions keep permission tooltips for clarity. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
31 lines
924 B
TypeScript
31 lines
924 B
TypeScript
import type { KeyboardEvent } from 'react'
|
|
|
|
type ClearableInputElement = HTMLInputElement | HTMLTextAreaElement
|
|
|
|
/**
|
|
* Staged-Escape handler for search/filter inputs:
|
|
* - Escape while the input has a value → clear the value (keeps focus)
|
|
* - Escape while the input is empty → blur the input
|
|
*
|
|
* Stops propagation on Escape so the keystroke doesn't bubble to dialog/popover
|
|
* close handlers when the consumer is nested inside one.
|
|
*
|
|
* @example
|
|
* <Input
|
|
* value={query}
|
|
* onChange={(e) => setQuery(e.target.value)}
|
|
* onKeyDown={onSearchInputEscape(query, setQuery)}
|
|
* />
|
|
*/
|
|
export const onSearchInputEscape =
|
|
<T extends ClearableInputElement>(value: string, onClear: (next: string) => void) =>
|
|
(event: KeyboardEvent<T>) => {
|
|
if (event.key !== 'Escape') return
|
|
event.stopPropagation()
|
|
if (value.length > 0) {
|
|
onClear('')
|
|
} else {
|
|
event.currentTarget.blur()
|
|
}
|
|
}
|