mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
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 -->
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { useEffect } from 'react'
|
|
import { useLatest } from 'react-use'
|
|
|
|
// [Joshen] Refactor: Remove dependencies, and just make this into a single definition
|
|
function useHotKey(
|
|
callback: (e: KeyboardEvent) => void,
|
|
key: string,
|
|
options?: { enabled?: boolean }
|
|
): void
|
|
/**
|
|
* @deprecated The `dependencies` parameter is deprecated. Use the overload without dependencies instead.
|
|
*/
|
|
function useHotKey(
|
|
callback: (e: KeyboardEvent) => void,
|
|
key: string,
|
|
dependencies: unknown[],
|
|
options?: { enabled?: boolean }
|
|
): void
|
|
function useHotKey(
|
|
callback: (e: KeyboardEvent) => void,
|
|
key: string,
|
|
dependenciesOrOptions?: unknown[] | { enabled?: boolean },
|
|
options?: { enabled?: boolean }
|
|
): void {
|
|
// Determine which overload was called
|
|
const isDepsArray = Array.isArray(dependenciesOrOptions)
|
|
const resolvedOptions = isDepsArray ? options : dependenciesOrOptions
|
|
const enabled = resolvedOptions?.enabled ?? true
|
|
|
|
const enabledRef = useLatest(enabled)
|
|
const callbackRef = useLatest(callback)
|
|
const keyRef = useLatest(key)
|
|
|
|
useEffect(() => {
|
|
function handler(e: KeyboardEvent) {
|
|
if (!enabledRef.current) return
|
|
if ((e.metaKey || e.ctrlKey) && e.key === keyRef.current && !e.altKey && !e.shiftKey) {
|
|
callbackRef.current(e)
|
|
}
|
|
}
|
|
|
|
window.addEventListener('keydown', handler, true)
|
|
return () => {
|
|
window.removeEventListener('keydown', handler, true)
|
|
}
|
|
}, [callbackRef, enabledRef, keyRef])
|
|
}
|
|
|
|
export { useHotKey }
|