mirror of
https://github.com/supabase/supabase.git
synced 2026-06-20 20:16:04 +08:00
## Summary - Migrates all 11 `useHotKey` call sites across 9 files to `useShortcut`, backed by `SHORTCUT_DEFINITIONS` in `state/shortcuts/registry.ts`. - Adds 10 new registry entries (all `showInSettings: false` to keep behavior identical to today — these were not previously user-configurable). - Deletes `apps/studio/hooks/ui/useHotKey.ts`. - Simplifies `ActionBar.handleSave` — the legacy hook passed a `KeyboardEvent` the callback used for `preventDefault`/`stopPropagation` and a textarea-plain-Enter guard; all of that is redundant under `useShortcut` (TanStack handles default/propagation; `Mod+Enter` never fires on plain Enter). - Removes a stale commented-out `useHotKey` reference in `DataTableFilterCommand.tsx`. Part of FE-3025 (legacy hotkey hook cleanup). `useKeyboardShortcuts` in `grid/components/common/Hooks.tsx` will be migrated in a follow-up. ## Test plan All shortcuts should still fire with **Cmd** (macOS) / **Ctrl** (Win/Linux). **Table Editor — operation queue** (requires pending unsaved edits on a row) - [x] `Cmd+S` saves pending edits - [x] `Cmd+.` toggles the operation queue side panel - [x] `Cmd+Z` undoes the latest edit and re-fetches the affected table rows - [x] With no pending edits, none of the above fire (gated by `isEnabled`) **Table Editor — side panel editor forms** (row, table, column, policy, etc.) - [x] `Cmd+Enter` submits the form when the panel is visible - [x] Does not submit if the form is disabled/loading or the panel is hidden **Unified Logs — data table** - [x] `Cmd+B` toggles the filter controls sidebar (desktop) - [x] `Cmd+B` opens the filter drawer (mobile, `<sm` breakpoint) - [x] `Cmd+Esc` resets active column filters (reset button visible) - [x] `Cmd+U` resets column order + visibility - [x] `Cmd+J` toggles live mode **Unified Logs — reset focus** - [x] `Cmd+.` blurs the currently focused element / resets focus to body **AI Assistant panel** - [x] While editing a message, `Cmd+Esc` cancels the edit **Regression checks** - [x] `pnpm --filter=studio typecheck` passes (verified locally) - [x] None of the new shortcut entries appear in Account → Preferences → Keyboard shortcuts (all `showInSettings: false`) - [x] Existing shortcuts (`Cmd+K`, `Cmd+I`, `Cmd+E`, results copy/download) still work unchanged <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Refactor * Implemented a centralized keyboard shortcut registry system for managing shortcuts consistently across the application * Updated multiple UI components throughout the interface to use the new shortcut management system * All existing keyboard shortcuts continue to function without any changes in behavior or user experience ## Chores * Removed legacy keyboard shortcut hook implementation <!-- end of auto-generated comment: release notes by coderabbit.ai -->
106 lines
3.1 KiB
TypeScript
106 lines
3.1 KiB
TypeScript
import { noop } from 'lodash'
|
|
import { PropsWithChildren, useCallback, useState } from 'react'
|
|
import { Button, KeyboardShortcut } from 'ui'
|
|
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
import { useShortcut } from '@/state/shortcuts/useShortcut'
|
|
|
|
interface ActionBarProps {
|
|
loading?: boolean
|
|
disableApply?: boolean
|
|
hideApply?: boolean
|
|
applyButtonLabel?: string
|
|
backButtonLabel?: string
|
|
applyFunction?: (resolve: any) => void
|
|
closePanel: () => void
|
|
formId?: string
|
|
visible?: boolean
|
|
}
|
|
|
|
export const ActionBar = ({
|
|
loading = false,
|
|
disableApply = false,
|
|
hideApply = false,
|
|
children = undefined,
|
|
applyButtonLabel = 'Apply',
|
|
backButtonLabel = 'Back',
|
|
applyFunction = undefined,
|
|
closePanel = noop,
|
|
formId,
|
|
visible = true,
|
|
}: PropsWithChildren<ActionBarProps>) => {
|
|
const [isRunning, setIsRunning] = useState(false)
|
|
|
|
const onSelectApply = useCallback(async () => {
|
|
const applyCallback = () => new Promise((resolve) => applyFunction?.(resolve))
|
|
setIsRunning(true)
|
|
await applyCallback()
|
|
setIsRunning(false)
|
|
}, [applyFunction])
|
|
|
|
const handleSave = useCallback(() => {
|
|
if (isRunning || loading || disableApply || hideApply) return
|
|
|
|
if (formId) {
|
|
const form = document.getElementById(formId) as HTMLFormElement | null
|
|
if (form) {
|
|
form.requestSubmit()
|
|
}
|
|
} else if (applyFunction) {
|
|
onSelectApply()
|
|
}
|
|
}, [isRunning, loading, disableApply, hideApply, formId, applyFunction, onSelectApply])
|
|
|
|
useShortcut(SHORTCUT_IDS.ACTION_BAR_SAVE, handleSave, { enabled: visible })
|
|
|
|
return (
|
|
<div className="flex w-full items-center gap-3 border-t border-default px-3 py-4">
|
|
{children}
|
|
|
|
<div className="flex items-center gap-3 ml-auto">
|
|
<Button
|
|
type="default"
|
|
htmlType="button"
|
|
onClick={closePanel}
|
|
disabled={isRunning || loading}
|
|
>
|
|
{backButtonLabel}
|
|
</Button>
|
|
|
|
{applyFunction !== undefined ? (
|
|
// Old solution, necessary when loading is handled by this component itself
|
|
<Button
|
|
onClick={onSelectApply}
|
|
disabled={disableApply || isRunning || loading}
|
|
loading={isRunning || loading}
|
|
iconRight={
|
|
isRunning || loading ? undefined : (
|
|
<KeyboardShortcut keys={['Meta', 'Enter']} variant="inline" />
|
|
)
|
|
}
|
|
>
|
|
{applyButtonLabel}
|
|
</Button>
|
|
) : !hideApply ? (
|
|
// New solution, when using the Form component, loading is handled by the Form itself
|
|
// Does not require applyFunction() callback
|
|
<Button
|
|
disabled={loading || disableApply}
|
|
loading={loading}
|
|
data-testid="action-bar-save-row"
|
|
htmlType="submit"
|
|
form={formId}
|
|
iconRight={
|
|
loading ? undefined : <KeyboardShortcut keys={['Meta', 'Enter']} variant="inline" />
|
|
}
|
|
>
|
|
{applyButtonLabel}
|
|
</Button>
|
|
) : (
|
|
<div />
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|