mirror of
https://github.com/supabase/supabase.git
synced 2026-07-03 13:04:33 +08:00
* added initial queue operations and feature flag * updated types * added dirty state tracking on columns * updated queue operations * updated operation types and queue * updated spacing * removed on cancel * updated to support saving * updated to include eye details * updated spacing for orders * updated to support shortcuts * added feature preview * updated to unify queue methods * added key generation * used unique keys rather than random uuid * updated based on code review * operation key * updated handle cancel * updated remove operation button * updated views for toast * updated logic to support optimistic updates * updated types * code cleanup: remove LLM slop * updated PR bug * updated preview for logout * updated based on code review * removed use effect as it was causing problems * fixed toast mounting away from sql editor * removed toast for dedicated action bar * cleaned up logic * updated queue operations * renamed method * updated name for types * updated comment * fixed code rabbit solution * added check for changed column * added tests
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import { useCallback, useEffect } from 'react'
|
|
|
|
import { detectOS } from 'lib/helpers'
|
|
|
|
export function getModKey() {
|
|
const os = detectOS()
|
|
return os === 'macos' ? '⌘' : 'Ctrl+'
|
|
}
|
|
|
|
interface UseOperationQueueShortcutsOptions {
|
|
enabled: boolean
|
|
onSave: () => void
|
|
onTogglePanel: () => void
|
|
isSaving?: boolean
|
|
hasOperations?: boolean
|
|
}
|
|
|
|
/**
|
|
* Hook that provides keyboard shortcuts for the operation queue.
|
|
*
|
|
* Shortcuts:
|
|
* - Cmd/Ctrl + S: Save all pending changes
|
|
* - Cmd/Ctrl + .: Toggle the operation queue side panel
|
|
*
|
|
* These shortcuts are registered on the capture phase to ensure they fire
|
|
* before the data grid handles the keyboard event.
|
|
*/
|
|
export function useOperationQueueShortcuts({
|
|
enabled,
|
|
onSave,
|
|
onTogglePanel,
|
|
isSaving = false,
|
|
hasOperations = true,
|
|
}: UseOperationQueueShortcutsOptions) {
|
|
const os = detectOS()
|
|
const modKey = os === 'macos' ? '⌘' : 'Ctrl+'
|
|
|
|
const handleKeyDown = useCallback(
|
|
(event: KeyboardEvent) => {
|
|
const isMod = os === 'macos' ? event.metaKey : event.ctrlKey
|
|
|
|
if (isMod && event.key === 's') {
|
|
event.preventDefault()
|
|
event.stopPropagation()
|
|
if (!isSaving && hasOperations) {
|
|
onSave()
|
|
}
|
|
} else if (isMod && event.key === '.') {
|
|
event.preventDefault()
|
|
event.stopPropagation()
|
|
onTogglePanel()
|
|
}
|
|
},
|
|
[os, isSaving, hasOperations, onSave, onTogglePanel]
|
|
)
|
|
|
|
// Use capture phase to intercept events before the grid handles them
|
|
useEffect(() => {
|
|
if (enabled) {
|
|
window.addEventListener('keydown', handleKeyDown, true)
|
|
return () => {
|
|
window.removeEventListener('keydown', handleKeyDown, true)
|
|
}
|
|
}
|
|
}, [enabled, handleKeyDown])
|
|
|
|
return { modKey }
|
|
}
|