Files
Ali Waseem e8df67d5d5 chore: migrate shortcuts to new hooks API (#44955)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Cleanup shortcuts with new hooks

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

* **Refactor**
* Centralized keyboard shortcut system for consistent shortcut behavior
across the app and moved preference toggles to a unified registry.

* **New Features**
* Added explicit shortcuts for Command Menu, AI Assistant, Inline
Editor, and result copy/download actions.
* Hotkey preferences UI now renders dynamically from the centralized
shortcut list.

* **Tests**
* Test helpers updated to include the command menu provider for accurate
shortcut behavior in tests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-17 10:02:56 -06:00

41 lines
1.5 KiB
TypeScript

import { Fragment } from 'react'
import { CardContent, KeyboardShortcut, Switch } from 'ui'
import { hotkeyToKeys } from '@/state/shortcuts/formatShortcut'
import type { ShortcutId } from '@/state/shortcuts/registry'
import { useShortcutPreferences } from '@/state/shortcuts/state'
import type { ShortcutDefinition } from '@/state/shortcuts/types'
import { useIsShortcutEnabled } from '@/state/shortcuts/useIsShortcutEnabled'
interface HotkeyToggleProps {
definition: ShortcutDefinition
isLast?: boolean
}
export function HotkeyToggle({ definition, isLast }: HotkeyToggleProps) {
const enabled = useIsShortcutEnabled(definition.id as ShortcutId)
const { setShortcutEnabled } = useShortcutPreferences()
return (
<CardContent className={isLast ? undefined : 'border-b'}>
<div className="flex items-center justify-between gap-x-3">
<label className="text-sm text-foreground">{definition.label}</label>
<div className="flex items-center gap-x-3">
<div className="flex items-center gap-1">
{definition.sequence.map((step, i) => (
<Fragment key={i}>
{i > 0 && <span className="text-foreground-lighter text-[11px]">then</span>}
<KeyboardShortcut keys={hotkeyToKeys(step)} />
</Fragment>
))}
</div>
<Switch
checked={enabled}
onCheckedChange={(checked) => setShortcutEnabled(definition.id as ShortcutId, checked)}
/>
</div>
</div>
</CardContent>
)
}