Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add shortcuts for copy markdown, json or download CSV (#43929)

Ali Waseemb14ef270b296
diff --git a/apps/studio/components/interfaces/Account/Preferences/HotkeySettings.tsx b/apps/studio/components/interfaces/Account/Preferences/HotkeySettings.tsx
index 669cce3c2ab..9666307ecb1 100644
--- a/apps/studio/components/interfaces/Account/Preferences/HotkeySettings.tsx
+++ b/apps/studio/components/interfaces/Account/Preferences/HotkeySettings.tsx
@@ -1,20 +1,9 @@
import { zodResolver } from '@hookform/resolvers/zod'
-import { useForm } from 'react-hook-form'
-import * as z from 'zod'
-
import { LOCAL_STORAGE_KEYS } from 'common'
import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
-import {
- Card,
- CardContent,
- FormControl_Shadcn_,
- FormField_Shadcn_,
- Form_Shadcn_,
- KeyboardShortcut,
- Switch,
-} from 'ui'
-import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { useForm } from 'react-hook-form'
+import { Card, Form_Shadcn_ } from 'ui'
import {
PageSection,
PageSectionContent,
@@ -23,11 +12,17 @@ import {
PageSectionSummary,
PageSectionTitle,
} from 'ui-patterns/PageSection'
+import * as z from 'zod'
+
+import { HotkeyToggle } from './HotkeyToggle'
const HotkeySchema = z.object({
commandMenuEnabled: z.boolean(),
aiAssistantEnabled: z.boolean(),
inlineEditorEnabled: z.boolean(),
+ copyMarkdownEnabled: z.boolean(),
+ copyJsonEnabled: z.boolean(),
+ downloadCsvEnabled: z.boolean(),
})
export const HotkeySettings = () => {
@@ -43,6 +38,18 @@ export const HotkeySettings = () => {
LOCAL_STORAGE_KEYS.HOTKEY_SIDEBAR(SIDEBAR_KEYS.AI_ASSISTANT),
true
)
+ const [copyMarkdownEnabled, setCopyMarkdownEnabled] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.HOTKEY_COPY_MARKDOWN,
+ true
+ )
+ const [copyJsonEnabled, setCopyJsonEnabled] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.HOTKEY_COPY_JSON,
+ true
+ )
+ const [downloadCsvEnabled, setDownloadCsvEnabled] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.HOTKEY_DOWNLOAD_CSV,
+ true
+ )
const form = useForm<z.infer<typeof HotkeySchema>>({
resolver: zodResolver(HotkeySchema),
@@ -50,6 +57,9 @@ export const HotkeySettings = () => {
commandMenuEnabled: commandMenuEnabled ?? true,
aiAssistantEnabled: aiAssistantEnabled ?? true,
inlineEditorEnabled: inlineEditorEnabled ?? true,
+ copyMarkdownEnabled: copyMarkdownEnabled ?? true,
+ copyJsonEnabled: copyJsonEnabled ?? true,
+ downloadCsvEnabled: downloadCsvEnabled ?? true,
},
})
@@ -66,87 +76,49 @@ export const HotkeySettings = () => {
<PageSectionContent>
<Form_Shadcn_ {...form}>
<Card>
- <CardContent className="border-b">
- <FormField_Shadcn_
- control={form.control}
- name="commandMenuEnabled"
- render={({ field }) => (
- <FormItemLayout
- layout="flex-row-reverse"
- label={
- <div className="flex items-center gap-x-3">
- <KeyboardShortcut keys={['Meta', 'k']} />
- <span>Command menu</span>
- </div>
- }
- >
- <FormControl_Shadcn_>
- <Switch
- checked={field.value}
- onCheckedChange={(value) => {
- field.onChange(value)
- setCommandMenuEnabled(value)
- }}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- </CardContent>
- <CardContent className="border-b">
- <FormField_Shadcn_
- control={form.control}
- name="aiAssistantEnabled"
- render={({ field }) => (
- <FormItemLayout
- layout="flex-row-reverse"
- label={
- <div className="flex items-center gap-x-3">
- <KeyboardShortcut keys={['Meta', 'i']} />
- <span>AI Assistant Panel</span>
- </div>
- }
- >
- <FormControl_Shadcn_>
- <Switch
- checked={field.value}
- onCheckedChange={(value) => {
- field.onChange(value)
- setAiAssistantEnabled(value)
- }}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- </CardContent>
- <CardContent>
- <FormField_Shadcn_
- control={form.control}
- name="inlineEditorEnabled"
- render={({ field }) => (
- <FormItemLayout
- layout="flex-row-reverse"
- label={
- <div className="flex items-center gap-x-3">
- <KeyboardShortcut keys={['Meta', 'e']} />
- <span>Inline SQL Editor Panel</span>
- </div>
- }
- >
- <FormControl_Shadcn_>
- <Switch
- checked={field.value}
- onCheckedChange={(value) => {
- field.onChange(value)
- setInlineEditorEnabled(value)
- }}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- </CardContent>
+ <HotkeyToggle
+ form={form}
+ name="commandMenuEnabled"
+ keys={['Meta', 'k']}
+ label="Command menu"
+ onToggle={setCommandMenuEnabled}
+ />
+ <HotkeyToggle
+ form={form}
+ name="aiAssistantEnabled"
+ keys={['Meta', 'i']}
+ label="AI Assistant Panel"
+ onToggle={setAiAssistantEnabled}
+ />
+ <HotkeyToggle
+ form={form}
+ name="inlineEditorEnabled"
+ keys={['Meta', 'e']}
+ label="Inline SQL Editor Panel"
+ onToggle={setInlineEditorEnabled}
+ />
+ <HotkeyToggle
+ form={form}
+ name="copyMarkdownEnabled"
+ keys={['Shift', 'Meta', 'm']}
+ label="Copy results as Markdown"
+ onToggle={setCopyMarkdownEnabled}
+ />
+ <HotkeyToggle
+ form={form}
+ name="copyJsonEnabled"
+ keys={['Shift', 'Meta', 'j']}
+ label="Copy results as JSON"
+ onToggle={setCopyJsonEnabled}
+ />
+ <HotkeyToggle
+ form={form}
+ name="downloadCsvEnabled"
+ keys={['Shift', 'Meta', 'd']}
+ label="Download results as CSV"
+ onToggle={setDownloadCsvEnabled}
+ isLast
+ />
</Card>
</Form_Shadcn_>
</PageSectionContent>
diff --git a/apps/studio/components/interfaces/Account/Preferences/HotkeyToggle.tsx b/apps/studio/components/interfaces/Account/Preferences/HotkeyToggle.tsx
new file mode 100644
index 00000000000..5577ed76731
--- /dev/null
+++ b/apps/studio/components/interfaces/Account/Preferences/HotkeyToggle.tsx
@@ -0,0 +1,51 @@
+import type { FieldValues, Path, UseFormReturn } from 'react-hook-form'
+import { CardContent, FormControl_Shadcn_, FormField_Shadcn_, KeyboardShortcut, Switch } from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+
+interface HotkeyToggleProps<T extends FieldValues> {
+ form: UseFormReturn<T>
+ name: Path<T>
+ keys: string[]
+ label: string
+ onToggle: (value: boolean) => void
+ isLast?: boolean
+}
+
+export function HotkeyToggle<T extends FieldValues>({
+ form,
+ name,
+ keys,
+ label,
+ onToggle,
+ isLast,
+}: HotkeyToggleProps<T>) {
+ return (
+ <CardContent className={isLast ? undefined : 'border-b'}>
+ <FormField_Shadcn_
+ control={form.control}
+ name={name}
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label={
+ <div className="flex items-center gap-x-3">
+ <KeyboardShortcut keys={keys} />
+ <span>{label}</span>
+ </div>
+ }
+ >
+ <FormControl_Shadcn_>
+ <Switch
+ checked={field.value}
+ onCheckedChange={(value) => {
+ field.onChange(value)
+ onToggle(value)
+ }}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
+ )
+}
diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.utils.test.ts b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.utils.test.ts
new file mode 100644
index 00000000000..f1fb5d068fa
--- /dev/null
+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.utils.test.ts
@@ -0,0 +1,154 @@
+import { describe, expect, it } from 'vitest'
+
+import {
+ convertResultsToCSV,
+ convertResultsToJSON,
+ convertResultsToMarkdown,
+ formatResults,
+ getResultsHeaders,
+} from './Results.utils'
+
+describe('Results.utils', () => {
+ describe('formatResults', () => {
+ it('should stringify object values', () => {
+ const results = [{ id: 1, data: { nested: true } }]
+ const formatted = formatResults(results)
+ expect(formatted).toEqual([{ id: 1, data: '{"nested":true}' }])
+ })
+
+ it('should stringify array values', () => {
+ const results = [{ id: 1, tags: ['a', 'b'] }]
+ const formatted = formatResults(results)
+ expect(formatted).toEqual([{ id: 1, tags: '["a","b"]' }])
+ })
+
+ it('should stringify null values', () => {
+ const results = [{ id: 1, value: null }]
+ const formatted = formatResults(results)
+ expect(formatted).toEqual([{ id: 1, value: 'null' }])
+ })
+
+ it('should leave primitive values unchanged', () => {
+ const results = [{ name: 'test', count: 42, active: true }]
+ const formatted = formatResults(results)
+ expect(formatted).toEqual([{ name: 'test', count: 42, active: true }])
+ })
+
+ it('should return empty array for empty input', () => {
+ expect(formatResults([])).toEqual([])
+ })
+ })
+
+ describe('convertResultsToMarkdown', () => {
+ it('should return undefined for empty results', () => {
+ expect(convertResultsToMarkdown([])).toBeUndefined()
+ })
+
+ it('should convert results to a markdown table', () => {
+ const results = [
+ { id: 1, name: 'Alice' },
+ { id: 2, name: 'Bob' },
+ ]
+ const md = convertResultsToMarkdown(results)
+ expect(md).toContain('| id | name |')
+ expect(md).toContain('| 1 | Alice |')
+ expect(md).toContain('| 2 | Bob |')
+ })
+
+ it('should stringify nested objects in markdown output', () => {
+ const results = [{ id: 1, meta: { role: 'admin' } }]
+ const md = convertResultsToMarkdown(results)
+ expect(md).toContain('{"role":"admin"}')
+ })
+ })
+
+ describe('convertResultsToJSON', () => {
+ it('should return undefined for empty results', () => {
+ expect(convertResultsToJSON([])).toBeUndefined()
+ })
+
+ it('should return formatted JSON string', () => {
+ const results = [{ id: 1, name: 'Alice' }]
+ const json = convertResultsToJSON(results)
+ expect(json).toBe(JSON.stringify(results, null, 2))
+ })
+
+ it('should preserve nested object structure', () => {
+ const results = [{ id: 1, meta: { role: 'admin' } }]
+ const json = convertResultsToJSON(results)
+ const parsed = JSON.parse(json!)
+ expect(parsed[0].meta.role).toBe('admin')
+ })
+ })
+
+ describe('getResultsHeaders', () => {
+ it('should return undefined for empty results', () => {
+ expect(getResultsHeaders([])).toBeUndefined()
+ })
+
+ it('should return keys from the first row', () => {
+ const results = [{ id: 1, name: 'Alice' }]
+ expect(getResultsHeaders(results)).toEqual(['id', 'name'])
+ })
+
+ it('should preserve key order from the first row', () => {
+ const results = [{ z: 1, a: 2, m: 3 }]
+ expect(getResultsHeaders(results)).toEqual(['z', 'a', 'm'])
+ })
+
+ it('should use only the first row for headers', () => {
+ const results = [{ id: 1 }, { id: 2, extra: 'bonus' }]
+ expect(getResultsHeaders(results)).toEqual(['id'])
+ })
+ })
+
+ describe('convertResultsToCSV', () => {
+ it('should return undefined for empty results', () => {
+ expect(convertResultsToCSV([])).toBeUndefined()
+ })
+
+ it('should include header row from first result keys', () => {
+ const results = [{ id: 1, name: 'Alice' }]
+ const csv = convertResultsToCSV(results)
+ expect(csv).toContain('id,name')
+ })
+
+ it('should include data rows', () => {
+ const results = [
+ { id: 1, name: 'Alice' },
+ { id: 2, name: 'Bob' },
+ ]
+ const csv = convertResultsToCSV(results)
+ expect(csv).toContain('Alice')
+ expect(csv).toContain('Bob')
+ })
+
+ it('should stringify object values', () => {
+ const results = [{ id: 1, meta: { role: 'admin' } }]
+ const csv = convertResultsToCSV(results)
+ // CSV wraps values containing special chars in quotes and escapes inner quotes
+ expect(csv).toContain('"{""role"":""admin""}"')
+ })
+
+ it('should stringify array values', () => {
+ const results = [{ id: 1, tags: ['a', 'b'] }]
+ const csv = convertResultsToCSV(results)
+ // CSV wraps values containing special chars in quotes and escapes inner quotes
+ expect(csv).toContain('"[""a"",""b""]"')
+ })
+
+ it('should stringify null values', () => {
+ const results = [{ id: 1, value: null }]
+ const csv = convertResultsToCSV(results)
+ expect(csv).toContain('null')
+ })
+
+ it('should preserve column order from first row', () => {
+ const results = [{ z: 1, a: 2, m: 3 }]
+ const csv = convertResultsToCSV(results)
+ // split on CRLF line endings produced by papaparse
+ const headerRow = csv!.split('\r\n')[0]
+ expect(headerRow).toBe('z,a,m')
+ })
+ })
+})
diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.utils.ts b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.utils.ts
new file mode 100644
index 00000000000..3791f6c9c61
--- /dev/null
+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.utils.ts
@@ -0,0 +1,48 @@
+import { markdownTable } from 'markdown-table'
+import Papa from 'papaparse'
+
+type ResultRow = Record<string, unknown>
+
+export function formatResults(
+ results: ResultRow[]
+): Record<string, string | number | boolean | null | undefined>[] {
+ return results.map((row) => {
+ const formatted: Record<string, string | number | boolean> = {}
+ for (const key of Object.keys(row)) {
+ const value = row[key]
+ formatted[key] =
+ typeof value === 'object' ? JSON.stringify(value) : (value as string | number | boolean)
+ }
+ return formatted
+ })
+}
+
+export function convertResultsToMarkdown(results: ResultRow[]): string | undefined {
+ const formatted = formatResults(results)
+ if (formatted.length === 0) return undefined
+
+ const columns = Object.keys(formatted[0])
+ const rows = formatted.map((row) => columns.map((col) => String(row[col] ?? '')))
+ const table = [columns, ...rows]
+ return markdownTable(table)
+}
+
+export function convertResultsToJSON(results: ResultRow[]): string | undefined {
+ if (results.length === 0) return undefined
+ return JSON.stringify(results, null, 2)
+}
+
+export function getResultsHeaders(results: ResultRow[]): string[] | undefined {
+ const firstRow = Array.from(results)[0]
+ if (firstRow) return Object.keys(firstRow)
+ return undefined
+}
+
+export function convertResultsToCSV(results: ResultRow[]): string | undefined {
+ if (results.length === 0) return undefined
+
+ const headers = getResultsHeaders(results)
+ const formatted = formatResults(results)
+
+ return Papa.unparse(formatted, { columns: headers })
+}
diff --git a/apps/studio/components/ui/DownloadResultsButton.tsx b/apps/studio/components/ui/DownloadResultsButton.tsx
index 921e40b907e..ba1e9145e04 100644
--- a/apps/studio/components/ui/DownloadResultsButton.tsx
+++ b/apps/studio/components/ui/DownloadResultsButton.tsx
@@ -1,14 +1,17 @@
+import { IS_PLATFORM, LOCAL_STORAGE_KEYS, useParams } from 'common'
+import {
+ convertResultsToCSV,
+ convertResultsToJSON,
+ convertResultsToMarkdown,
+} from 'components/interfaces/SQLEditor/UtilityPanel/Results.utils'
import saveAs from 'file-saver'
+import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
+import { useHotKey } from 'hooks/ui/useHotKey'
import { ChevronDown, Copy, Download, Settings } from 'lucide-react'
-import { markdownTable } from 'markdown-table'
-import Papa from 'papaparse'
-import { useMemo } from 'react'
-import { toast } from 'sonner'
import Link from 'next/link'
-import { useParams } from 'common'
import { usePathname } from 'next/navigation'
-import { IS_PLATFORM } from 'common'
-
+import { useMemo } from 'react'
+import { toast } from 'sonner'
import {
Button,
copyToClipboard,
@@ -16,6 +19,7 @@ import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
+ KeyboardShortcut,
} from 'ui'
interface DownloadResultsButtonProps {
@@ -44,25 +48,19 @@ export const DownloadResultsButton = ({
const { ref } = useParams()
const pathname = usePathname()
const isLogs = pathname?.includes?.('/logs') ?? false
- // [Joshen] Ensure JSON values are stringified for CSV and Markdown
- const formattedResults = results.map((row) => {
- const r = { ...row }
- Object.keys(row).forEach((x) => {
- if (typeof row[x] === 'object') r[x] = JSON.stringify(row[x])
- })
- return r
- })
+ const [copyMarkdownEnabled] = useLocalStorageQuery(LOCAL_STORAGE_KEYS.HOTKEY_COPY_MARKDOWN, true)
+ const [copyJsonEnabled] = useLocalStorageQuery(LOCAL_STORAGE_KEYS.HOTKEY_COPY_JSON, true)
+ const [downloadCsvEnabled] = useLocalStorageQuery(LOCAL_STORAGE_KEYS.HOTKEY_DOWNLOAD_CSV, true)
- const headers = useMemo(() => {
- if (results) {
- const firstRow = Array.from(results)[0]
- if (firstRow) return Object.keys(firstRow)
- }
- return undefined
- }, [results])
+ const isEmpty = useMemo(() => results.length === 0, [results])
const downloadAsCSV = () => {
- const csv = Papa.unparse(formattedResults, { columns: headers })
+ const csv = convertResultsToCSV(results)
+ if (!csv) {
+ toast('Results are empty')
+ return
+ }
+
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' })
saveAs(blob, `${fileName}.csv`)
toast.success('Downloading results as CSV')
@@ -70,35 +68,56 @@ export const DownloadResultsButton = ({
}
const copyAsMarkdown = () => {
- if (navigator) {
- if (formattedResults.length == 0) toast('Results are empty')
-
- const columns = Object.keys(formattedResults[0])
- const rows = formattedResults.map((x) => {
- let temp: any[] = []
- columns.forEach((col) => temp.push(x[col]))
- return temp
- })
- const table = [columns].concat(rows)
- const markdownData = markdownTable(table)
-
- copyToClipboard(markdownData, () => {
- toast.success('Copied results to clipboard')
- onCopyAsMarkdown?.()
- })
+ const markdownData = convertResultsToMarkdown(results)
+ if (!markdownData) {
+ toast('Results are empty')
+ return
}
+ copyToClipboard(markdownData, () => {
+ toast.success('Copied markdown to clipboard')
+ onCopyAsMarkdown?.()
+ })
}
const copyAsJSON = () => {
- if (navigator) {
- if (results.length === 0) return toast('Results are empty')
- copyToClipboard(JSON.stringify(results, null, 2), () => {
- toast.success('Copied results to clipboard')
- onCopyAsJSON?.()
- })
+ const jsonData = convertResultsToJSON(results)
+ if (!jsonData) {
+ toast('Results are empty')
+ return
}
+ copyToClipboard(jsonData, () => {
+ toast.success('Copied JSON to clipboard')
+ onCopyAsJSON?.()
+ })
}
+ useHotKey(
+ (e) => {
+ e.preventDefault()
+ copyAsMarkdown()
+ },
+ 'm',
+ { enabled: copyMarkdownEnabled ?? isEmpty, shift: true }
+ )
+
+ useHotKey(
+ (e) => {
+ e.preventDefault()
+ copyAsJSON()
+ },
+ 'j',
+ { enabled: copyJsonEnabled ?? isEmpty, shift: true }
+ )
+
+ useHotKey(
+ (e) => {
+ e.preventDefault()
+ downloadAsCSV()
+ },
+ 'd',
+ { enabled: downloadCsvEnabled ?? isEmpty, shift: true }
+ )
+
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
@@ -112,7 +131,7 @@ export const DownloadResultsButton = ({
{!iconOnly && text}
</Button>
</DropdownMenuTrigger>
- <DropdownMenuContent align={align} className="w-44">
+ <DropdownMenuContent align={align} className="w-60">
{isLogs && IS_PLATFORM && (
<DropdownMenuItem asChild className="gap-x-2">
<Link href={`/project/${ref}/settings/log-drains`}>
@@ -124,14 +143,23 @@ export const DownloadResultsButton = ({
<DropdownMenuItem onClick={copyAsMarkdown} className="gap-x-2">
<Copy size={14} />
<p>Copy as markdown</p>
+ <span className="ml-auto">
+ <KeyboardShortcut keys={['Shift', 'Meta', 'm']} />
+ </span>
</DropdownMenuItem>
<DropdownMenuItem onClick={copyAsJSON} className="gap-x-2">
<Copy size={14} />
<p>Copy as JSON</p>
+ <span className="ml-auto">
+ <KeyboardShortcut keys={['Shift', 'Meta', 'j']} />
+ </span>
</DropdownMenuItem>
<DropdownMenuItem className="gap-x-2" onClick={() => downloadAsCSV()}>
<Download size={14} />
<p>Download CSV</p>
+ <span className="ml-auto">
+ <KeyboardShortcut keys={['Shift', 'Meta', 'd']} />
+ </span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
diff --git a/apps/studio/hooks/ui/useHotKey.ts b/apps/studio/hooks/ui/useHotKey.ts
index 41e470ca11c..60dbe097c6a 100644
--- a/apps/studio/hooks/ui/useHotKey.ts
+++ b/apps/studio/hooks/ui/useHotKey.ts
@@ -5,7 +5,7 @@ import { useLatest } from 'react-use'
function useHotKey(
callback: (e: KeyboardEvent) => void,
key: string,
- options?: { enabled?: boolean }
+ options?: { enabled?: boolean; shift?: boolean }
): void
/**
* @deprecated The `dependencies` parameter is deprecated. Use the overload without dependencies instead.
@@ -14,27 +14,34 @@ function useHotKey(
callback: (e: KeyboardEvent) => void,
key: string,
dependencies: unknown[],
- options?: { enabled?: boolean }
+ options?: { enabled?: boolean; shift?: boolean }
): void
function useHotKey(
callback: (e: KeyboardEvent) => void,
key: string,
- dependenciesOrOptions?: unknown[] | { enabled?: boolean },
- options?: { enabled?: boolean }
+ dependenciesOrOptions?: unknown[] | { enabled?: boolean; shift?: boolean },
+ options?: { enabled?: boolean; shift?: boolean }
): void {
// Determine which overload was called
const isDepsArray = Array.isArray(dependenciesOrOptions)
const resolvedOptions = isDepsArray ? options : dependenciesOrOptions
const enabled = resolvedOptions?.enabled ?? true
+ const shift = resolvedOptions?.shift ?? false
const enabledRef = useLatest(enabled)
const callbackRef = useLatest(callback)
const keyRef = useLatest(key)
+ const shiftRef = useLatest(shift)
useEffect(() => {
function handler(e: KeyboardEvent) {
if (!enabledRef.current) return
- if ((e.metaKey || e.ctrlKey) && e.key === keyRef.current && !e.altKey && !e.shiftKey) {
+ if (
+ (e.metaKey || e.ctrlKey) &&
+ e.key.toLowerCase() === keyRef.current.toLowerCase() &&
+ !e.altKey &&
+ (shiftRef.current ? e.shiftKey : !e.shiftKey)
+ ) {
callbackRef.current(e)
}
}
@@ -43,7 +50,7 @@ function useHotKey(
return () => {
window.removeEventListener('keydown', handler, true)
}
- }, [callbackRef, enabledRef, keyRef])
+ }, [callbackRef, enabledRef, keyRef, shiftRef])
}
export { useHotKey }
diff --git a/packages/common/constants/local-storage.ts b/packages/common/constants/local-storage.ts
index 633b9d524ae..c912b18d118 100644
--- a/packages/common/constants/local-storage.ts
+++ b/packages/common/constants/local-storage.ts
@@ -97,6 +97,10 @@ export const LOCAL_STORAGE_KEYS = {
// Project sidebar hotkeys
HOTKEY_SIDEBAR: (sidebarId: string) => `supabase-dashboard-hotkey-sidebar-${sidebarId}`,
+ HOTKEY_COPY_MARKDOWN: 'supabase-dashboard-hotkey-copy-markdown',
+ HOTKEY_COPY_JSON: 'supabase-dashboard-hotkey-copy-json',
+ HOTKEY_DOWNLOAD_CSV: 'supabase-dashboard-hotkey-download-csv',
+
// Index Advisor notice dismissed
INDEX_ADVISOR_NOTICE_DISMISSED: (ref: string) => `index-advisor-notice-dismissed-${ref}`,