Files
supabase/apps/studio/components/grid/hooks/useOperationQueueShortcuts.ts
T
Joshen Lim f90f3b4d14 Revert "Revert "Fix queue operations stale state + refactor to reuse existing…" (#42291)
TBD

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

* **New Features**
* OS-aware modifier-key label shown in UI (⌘ on macOS, Ctrl+ on others)
  * Tooltips added to operation queue actions for improved usability

* **Bug Fixes**
  * Warns before applying non-primary-key sorts on large tables
  * Clarified access error messages for organizations and projects

* **Refactor**
  * Redesigned hotkey handling and operation-queue shortcuts
* Operation queue view toggle and save flow refined (panel auto-closes
after save)

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-01-30 10:44:42 +08:00

47 lines
1.4 KiB
TypeScript

import { useOperationQueueActions } from './useOperationQueueActions'
import { useIsQueueOperationsEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { useHotKey } from '@/hooks/ui/useHotKey'
import { useTableEditorStateSnapshot } from '@/state/table-editor'
/**
* 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() {
const isQueueOperationsEnabled = useIsQueueOperationsEnabled()
const snap = useTableEditorStateSnapshot()
const { handleSave } = useOperationQueueActions()
const isSaving = snap.operationQueue.status === 'saving'
const hasOperations = snap.hasPendingOperations
const isEnabled = isQueueOperationsEnabled && hasOperations
useHotKey(
(event) => {
event.preventDefault()
event.stopPropagation()
if (!isSaving && hasOperations) {
handleSave()
}
},
's',
{ enabled: isEnabled }
)
useHotKey(
(event) => {
event.preventDefault()
event.stopPropagation()
snap.toggleViewOperationQueue()
},
'.',
{ enabled: isEnabled }
)
}