Skip to content

Commit 78ab93f

Browse files
jonasnobileclaude
andcommitted
feat(grid): add "Add New Row" command with toolbar button and menu item
Register add-new-row in the command registry (Ctrl+Enter), add a toolbar button, a native macOS menu item, and delegate Cmd+Enter from the query command when in data-grid context. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 06d4ae6 commit 78ab93f

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

src/backend-desktop/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ if (isMac) {
120120
{ role: 'copy', accelerator: 'Cmd+C' },
121121
{ role: 'paste', accelerator: 'Cmd+V' },
122122
{ role: 'selectAll', accelerator: 'Cmd+A' },
123+
{ type: 'divider' },
124+
{ label: 'Add New Row', action: 'add-new-row' },
123125
],
124126
},
125127
{

src/frontend-shared/components/grid/DataGrid.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,18 @@ export default function DataGrid(props: DataGridProps) {
448448
onCleanup(() => window.removeEventListener('dotaz:save-view', onSaveView))
449449
})
450450

451+
// Listen for add-new-row events dispatched by the command registry
452+
onMount(() => {
453+
const onAddNewRow = (e: Event) => {
454+
const detail = (e as CustomEvent).detail
455+
if (detail?.tabId === props.tabId) {
456+
cellEdit.handleAddNewRow()
457+
}
458+
}
459+
window.addEventListener('dotaz:add-new-row', onAddNewRow)
460+
onCleanup(() => window.removeEventListener('dotaz:add-new-row', onAddNewRow))
461+
})
462+
451463
return (
452464
<div
453465
ref={gridRef}
@@ -468,6 +480,7 @@ export default function DataGrid(props: DataGridProps) {
468480
onSaveViewOpen={(forceNew) => modals.openSaveView(forceNew)}
469481
onExportOpen={() => modals.openExport()}
470482
onImportOpen={() => modals.openImport()}
483+
onAddNewRow={() => cellEdit.handleAddNewRow()}
471484
rowColoringOpen={rowColoringOpen()}
472485
onToggleRowColoring={() => setRowColoringOpen(!rowColoringOpen())}
473486
sidePanelToggle={

src/frontend-shared/components/grid/DataGridToolbar.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ColumnFilter } from '@dotaz/shared/types/grid'
22
import type { SavedViewConfig } from '@dotaz/shared/types/rpc'
33
import ArrowLeftRight from 'lucide-solid/icons/arrow-left-right'
44
import EllipsisVertical from 'lucide-solid/icons/ellipsis-vertical'
5+
import Plus from 'lucide-solid/icons/plus'
56
import RotateCcw from 'lucide-solid/icons/rotate-ccw'
67
import Save from 'lucide-solid/icons/save'
78
import { createSignal, type JSX, onCleanup, Show } from 'solid-js'
@@ -28,6 +29,7 @@ export interface DataGridToolbarProps {
2829
onSaveViewOpen: (forceNew: boolean) => void
2930
onExportOpen: () => void
3031
onImportOpen: () => void
32+
onAddNewRow: () => void
3133
sidePanelToggle: JSX.Element
3234
rowColoringOpen: boolean
3335
onToggleRowColoring: () => void
@@ -222,6 +224,15 @@ export default function DataGridToolbar(props: DataGridToolbarProps) {
222224
<Icon name="link" size={12} /> {tabState().autoJoins.length} Join{tabState().autoJoins.length > 1 ? 's' : ''}
223225
</button>
224226
</Show>
227+
<Show when={!props.isReadOnly()}>
228+
<button
229+
class="data-grid__toolbar-btn"
230+
onClick={props.onAddNewRow}
231+
title="Add new row (Ctrl+Enter)"
232+
>
233+
<Plus size={12} /> Add Row
234+
</button>
235+
</Show>
225236
<button
226237
class="data-grid__toolbar-btn"
227238
onClick={handleRefresh}

src/frontend-shared/lib/app-shortcuts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export function registerAppShortcuts(): void {
4040
keyboardManager.register('Ctrl+G', 'ai-generate-sql', 'sql-console')
4141

4242
// Data grid context
43+
keyboardManager.register('Ctrl+Enter', 'add-new-row', 'data-grid')
4344
keyboardManager.register('F5', 'refresh-data', 'data-grid')
4445
keyboardManager.register('F2', 'inline-edit', 'data-grid')
4546
keyboardManager.register('Delete', 'delete-rows', 'data-grid')

src/frontend-shared/lib/commands/grid-commands.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { connectionsStore } from '../../stores/connections'
12
import { gridStore } from '../../stores/grid'
23
import { tabsStore } from '../../stores/tabs'
34
import type { AppCommandActions } from '../app-commands'
@@ -125,6 +126,21 @@ export function registerGridCommands(actions: AppCommandActions): void {
125126
},
126127
})
127128

129+
commandRegistry.register({
130+
id: 'add-new-row',
131+
label: 'Add New Row',
132+
shortcut: 'Ctrl+Enter',
133+
category: 'Grid',
134+
handler: () => {
135+
const tab = tabsStore.activeTab
136+
if (tab?.type !== 'data-grid') return
137+
if (connectionsStore.isReadOnly(tab.connectionId)) return
138+
window.dispatchEvent(
139+
new CustomEvent('dotaz:add-new-row', { detail: { tabId: tab.id } }),
140+
)
141+
},
142+
})
143+
128144
commandRegistry.register({
129145
id: 'compare-data',
130146
label: 'Compare Data',

src/frontend-shared/lib/commands/query-commands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export function registerQueryCommands(actions: AppCommandActions): void {
4949
const tab = tabsStore.activeTab
5050
if (tab?.type === 'sql-console') {
5151
editorStore.executeQuery(tab.id)
52+
} else if (tab?.type === 'data-grid') {
53+
// On desktop, the native menu accelerator Cmd+Enter fires run-query
54+
// regardless of context. Delegate to add-new-row when in data grid.
55+
commandRegistry.execute('add-new-row')
5256
}
5357
},
5458
})

0 commit comments

Comments
 (0)