Skip to content

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

feat(studio): add insert, filter, sort, refresh shortcuts to the table editor (#45191)

Ali Waseeme7c33bf580ee
diff --git a/apps/studio/components/grid/components/common/Shortcuts.tsx b/apps/studio/components/grid/components/common/Shortcuts.tsx
index 0c5d6a26b8c..99b3a2939a4 100644
--- a/apps/studio/components/grid/components/common/Shortcuts.tsx
+++ b/apps/studio/components/grid/components/common/Shortcuts.tsx
@@ -1,6 +1,8 @@
import { RefObject, useContext } from 'react'
import type { DataGridHandle } from 'react-data-grid'
+import { useTableFilter } from '@/components/grid/hooks/useTableFilter'
+import { useTableSort } from '@/components/grid/hooks/useTableSort'
import { SupaRow } from '@/components/grid/types'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
import { useShortcut } from '@/state/shortcuts/useShortcut'
@@ -19,6 +21,9 @@ export function Shortcuts({ gridRef, rows }: ShortcutsProps) {
const state = useContext(TableEditorTableStateContext)
const canStartNavigation = !snap.selectedCellPosition && rows.length > 0
+ const { filters, clearFilters } = useTableFilter()
+ const { sorts, onApplySorts } = useTableSort()
+
const startGridNavigation = () => {
const frozenColumns = snap.gridColumns.filter((x) => x.frozen)
gridRef.current?.selectCell({
@@ -103,5 +108,34 @@ export function Shortcuts({ gridRef, rows }: ShortcutsProps) {
}
)
+ useShortcut(
+ SHORTCUT_IDS.TABLE_EDITOR_FOCUS_FILTERS,
+ () => {
+ const input = document.querySelector<HTMLInputElement>(
+ '[data-testid="filter-bar-freeform-input"]'
+ )
+ input?.focus()
+ },
+ {
+ registerInCommandMenu: true,
+ }
+ )
+
+ useShortcut(
+ SHORTCUT_IDS.TABLE_EDITOR_CLEAR_FILTERS,
+ () => {
+ clearFilters()
+ },
+ {
+ registerInCommandMenu: true,
+ enabled: filters.length > 0,
+ }
+ )
+
+ useShortcut(SHORTCUT_IDS.TABLE_EDITOR_CLEAR_SORT, () => onApplySorts([]), {
+ registerInCommandMenu: true,
+ enabled: sorts.length > 0,
+ })
+
return null
}
diff --git a/apps/studio/components/grid/components/header/Header.tsx b/apps/studio/components/grid/components/header/Header.tsx
index 648ec60ded5..c5cfec42e8c 100644
--- a/apps/studio/components/grid/components/header/Header.tsx
+++ b/apps/studio/components/grid/components/header/Header.tsx
@@ -31,6 +31,7 @@ import {
} from '@/components/layouts/TableEditorLayout/ExportAllRows'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { Shortcut } from '@/components/ui/Shortcut'
+import { ShortcutBadge } from '@/components/ui/ShortcutBadge'
import { useTableRowsCountQuery } from '@/data/table-rows/table-rows-count-query'
import { useTableRowsQuery } from '@/data/table-rows/table-rows-query'
import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
@@ -43,6 +44,7 @@ import {
useSubscribeToImpersonatedRole,
} from '@/state/role-impersonation-state'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
+import { useShortcut } from '@/state/shortcuts/useShortcut'
import { useTableEditorStateSnapshot } from '@/state/table-editor'
import { useTableEditorTableStateSnapshot } from '@/state/table-editor-table'
@@ -105,6 +107,19 @@ const InsertButton = () => {
const canAddNew = onAddRow !== undefined || onAddColumn !== undefined
+ useShortcut(SHORTCUT_IDS.TABLE_EDITOR_INSERT_ROW, () => onAddRow?.(), {
+ registerInCommandMenu: true,
+ enabled: onAddRow !== undefined && canAddNew && canCreateColumns,
+ })
+ useShortcut(SHORTCUT_IDS.TABLE_EDITOR_INSERT_COLUMN, () => onAddColumn?.(), {
+ registerInCommandMenu: true,
+ enabled: onAddColumn !== undefined && canAddNew && canCreateColumns,
+ })
+ useShortcut(SHORTCUT_IDS.TABLE_EDITOR_IMPORT_CSV, () => onImportData?.(), {
+ registerInCommandMenu: true,
+ enabled: onImportData !== undefined && canAddNew && canCreateColumns,
+ })
+
if (!canAddNew || !canCreateColumns) return null
return (
@@ -123,8 +138,8 @@ const InsertButton = () => {
{[
...(onAddRow !== undefined
? [
- <DropdownMenuItem key="add-row" className="group space-x-2" onClick={onAddRow}>
- <div className="-mt-2 pr-1.5">
+ <DropdownMenuItem key="add-row" className="group gap-x-3" onClick={onAddRow}>
+ <div className="-mt-2 pr-1.5 shrink-0">
<div className="border border-foreground-lighter w-[15px] h-[4px]" />
<div className="border border-foreground-lighter w-[15px] h-[4px] my-[2px]" />
<div
@@ -134,21 +149,21 @@ const InsertButton = () => {
])}
/>
</div>
- <div>
+ <div className="flex-1 min-w-0 pr-4">
<p>Insert row</p>
<p className="text-foreground-light">Insert a new row into {snap.table.name}</p>
</div>
+ <ShortcutBadge
+ shortcutId={SHORTCUT_IDS.TABLE_EDITOR_INSERT_ROW}
+ className="shrink-0"
+ />
</DropdownMenuItem>,
]
: []),
...(onAddColumn !== undefined
? [
- <DropdownMenuItem
- key="add-column"
- className="group space-x-2"
- onClick={onAddColumn}
- >
- <div className="flex -mt-2 pr-1.5">
+ <DropdownMenuItem key="add-column" className="group gap-x-3" onClick={onAddColumn}>
+ <div className="flex -mt-2 pr-1.5 shrink-0">
<div className="border border-foreground-lighter w-[4px] h-[15px]" />
<div className="border border-foreground-lighter w-[4px] h-[15px] mx-[2px]" />
<div
@@ -158,12 +173,16 @@ const InsertButton = () => {
])}
/>
</div>
- <div>
+ <div className="flex-1 min-w-0 pr-4">
<p>Insert column</p>
<p className="text-foreground-light">
Insert a new column into {snap.table.name}
</p>
</div>
+ <ShortcutBadge
+ shortcutId={SHORTCUT_IDS.TABLE_EDITOR_INSERT_COLUMN}
+ className="shrink-0"
+ />
</DropdownMenuItem>,
]
: []),
@@ -171,7 +190,7 @@ const InsertButton = () => {
? [
<DropdownMenuItem
key="import-data"
- className="group space-x-2"
+ className="group gap-x-3"
onClick={() => {
onImportData()
sendEvent({
@@ -184,7 +203,7 @@ const InsertButton = () => {
})
}}
>
- <div className="relative -mt-2">
+ <div className="relative -mt-2 shrink-0">
<FileText size={18} strokeWidth={1.5} className="-translate-x-[2px]" />
<ArrowUp
className={cn(
@@ -195,10 +214,14 @@ const InsertButton = () => {
size={12}
/>
</div>
- <div>
+ <div className="flex-1 min-w-0 pr-4">
<p>Import data from CSV</p>
<p className="text-foreground-light">Insert new rows from a CSV</p>
</div>
+ <ShortcutBadge
+ shortcutId={SHORTCUT_IDS.TABLE_EDITOR_IMPORT_CSV}
+ className="shrink-0"
+ />
</DropdownMenuItem>,
]
: []),
diff --git a/apps/studio/components/grid/components/header/RefreshButton.tsx b/apps/studio/components/grid/components/header/RefreshButton.tsx
index 48860aa1a80..cbfbe5c56b6 100644
--- a/apps/studio/components/grid/components/header/RefreshButton.tsx
+++ b/apps/studio/components/grid/components/header/RefreshButton.tsx
@@ -1,10 +1,12 @@
import { useQueryClient } from '@tanstack/react-query'
import { useParams } from 'common'
import { RefreshCw } from 'lucide-react'
+import { Button } from 'ui'
import { useTableIndexAdvisor } from '@/components/grid/context/TableIndexAdvisorContext'
-import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
+import { Shortcut } from '@/components/ui/Shortcut'
import { tableRowKeys } from '@/data/table-rows/keys'
+import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
export type RefreshButtonProps = {
tableId?: number
@@ -23,18 +25,19 @@ export const RefreshButton = ({ tableId, isRefetching }: RefreshButtonProps) =>
}
return (
- <ButtonTooltip
- type="outline"
- loading={isRefetching}
- icon={<RefreshCw />}
- onClick={() => onClick()}
- className="w-7 h-7 p-0"
- tooltip={{
- content: {
- side: 'bottom',
- text: 'Refresh table data',
- },
- }}
- />
+ <Shortcut
+ id={SHORTCUT_IDS.TABLE_EDITOR_REFRESH}
+ onTrigger={onClick}
+ options={{ registerInCommandMenu: true }}
+ side="bottom"
+ >
+ <Button
+ type="outline"
+ loading={isRefetching}
+ icon={<RefreshCw />}
+ onClick={() => onClick()}
+ className="w-7 h-7 p-0"
+ />
+ </Shortcut>
)
}
diff --git a/apps/studio/components/ui/ShortcutBadge.tsx b/apps/studio/components/ui/ShortcutBadge.tsx
new file mode 100644
index 00000000000..66ad90c3e61
--- /dev/null
+++ b/apps/studio/components/ui/ShortcutBadge.tsx
@@ -0,0 +1,45 @@
+import { Fragment } from 'react'
+import { cn, KeyboardShortcut } from 'ui'
+
+import { hotkeyToKeys } from '@/state/shortcuts/formatShortcut'
+import { SHORTCUT_DEFINITIONS, type ShortcutId } from '@/state/shortcuts/registry'
+
+interface ShortcutBadgeProps {
+ shortcutId: ShortcutId
+ className?: string
+ /** `'inline'` (default) is flat text; `'pill'` is a boxed badge. */
+ variant?: 'inline' | 'pill'
+}
+
+/**
+ * Inline display of the keybind for a registered shortcut. Useful inside
+ * menu items, buttons, or rows where the label already exists elsewhere and
+ * you just want to surface the keybind itself (no tooltip / hover).
+ *
+ * For multi-step sequences (e.g. `['G', 'T']`), each step is separated by the
+ * word "then".
+ *
+ * @example
+ * <DropdownMenuItem>
+ * <p>Copy as CSV</p>
+ * <ShortcutBadge shortcutId={SHORTCUT_IDS.RESULTS_COPY_CSV} className="ml-auto" />
+ * </DropdownMenuItem>
+ */
+export const ShortcutBadge = ({
+ shortcutId,
+ className,
+ variant = 'inline',
+}: ShortcutBadgeProps) => {
+ const def = SHORTCUT_DEFINITIONS[shortcutId]
+
+ return (
+ <span className={cn('flex items-center gap-1', className)}>
+ {def.sequence.map((step, i) => (
+ <Fragment key={i}>
+ {i > 0 && <span className="text-foreground-lighter text-[11px]">then</span>}
+ <KeyboardShortcut keys={hotkeyToKeys(step)} variant={variant} />
+ </Fragment>
+ ))}
+ </span>
+ )
+}
diff --git a/apps/studio/state/shortcuts/registry/table-editor.ts b/apps/studio/state/shortcuts/registry/table-editor.ts
index 5981d3a4d42..374ef466c74 100644
--- a/apps/studio/state/shortcuts/registry/table-editor.ts
+++ b/apps/studio/state/shortcuts/registry/table-editor.ts
@@ -12,6 +12,13 @@ export const TABLE_EDITOR_SHORTCUT_IDS = {
TABLE_EDITOR_START_NAVIGATION_DOWN: 'table-editor.start-navigation-down',
TABLE_EDITOR_START_NAVIGATION_UP: 'table-editor.start-navigation-up',
TABLE_EDITOR_EXIT_SELECTION: 'table-editor.exit-selection',
+ TABLE_EDITOR_INSERT_ROW: 'table-editor.insert-row',
+ TABLE_EDITOR_INSERT_COLUMN: 'table-editor.insert-column',
+ TABLE_EDITOR_IMPORT_CSV: 'table-editor.import-csv',
+ TABLE_EDITOR_FOCUS_FILTERS: 'table-editor.focus-filters',
+ TABLE_EDITOR_CLEAR_FILTERS: 'table-editor.clear-filters',
+ TABLE_EDITOR_CLEAR_SORT: 'table-editor.clear-sort',
+ TABLE_EDITOR_REFRESH: 'table-editor.refresh',
}
export type TableEditorShortcutId =
@@ -95,4 +102,53 @@ export const tableEditorRegistry: RegistryDefinations<TableEditorShortcutId> = {
showInSettings: false,
options: { ignoreInputs: true },
},
+ [TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_INSERT_ROW]: {
+ id: TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_INSERT_ROW,
+ label: 'Insert row',
+ sequence: ['I', 'R'],
+ showInSettings: false,
+ options: { ignoreInputs: true },
+ },
+ [TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_INSERT_COLUMN]: {
+ id: TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_INSERT_COLUMN,
+ label: 'Insert column',
+ sequence: ['I', 'C'],
+ showInSettings: false,
+ options: { ignoreInputs: true },
+ },
+ [TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_IMPORT_CSV]: {
+ id: TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_IMPORT_CSV,
+ label: 'Import data from CSV',
+ sequence: ['I', 'U'],
+ showInSettings: false,
+ options: { ignoreInputs: true },
+ },
+ [TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_FOCUS_FILTERS]: {
+ id: TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_FOCUS_FILTERS,
+ label: 'Focus filters',
+ sequence: ['Shift+F'],
+ showInSettings: false,
+ options: { ignoreInputs: true },
+ },
+ [TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_CLEAR_FILTERS]: {
+ id: TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_CLEAR_FILTERS,
+ label: 'Clear filters',
+ sequence: ['F', 'C'],
+ showInSettings: false,
+ options: { ignoreInputs: true },
+ },
+ [TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_CLEAR_SORT]: {
+ id: TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_CLEAR_SORT,
+ label: 'Clear sort',
+ sequence: ['S', 'C'],
+ showInSettings: false,
+ options: { ignoreInputs: true },
+ },
+ [TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_REFRESH]: {
+ id: TABLE_EDITOR_SHORTCUT_IDS.TABLE_EDITOR_REFRESH,
+ label: 'Refresh table',
+ sequence: ['Shift+R'],
+ showInSettings: false,
+ options: { ignoreInputs: true },
+ },
}