Skip to content

Commit 604508b

Browse files
committed
refactor: remove 'insert-many' mode and related functionality from DocumentEditorDialog and CollectionLeaf and merge it with 'insert'
1 parent c2dc42b commit 604508b

2 files changed

Lines changed: 14 additions & 31 deletions

File tree

src/renderer/src/features/document/DocumentEditorDialog.tsx

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { parseMongoDocuments, parseMongoQuery } from '@/lib/mongoQueryLang'
1717
import { serializeMongoValue } from '@/lib/mongoQuerySerialize'
1818
import type { DocumentEnvelope, UuidEncoding } from '@shared/types'
1919

20-
export type EditorMode = 'view' | 'edit' | 'duplicate' | 'insert' | 'insert-many'
20+
export type EditorMode = 'view' | 'edit' | 'duplicate' | 'insert'
2121

2222
type Props = {
2323
mode: EditorMode | null
@@ -36,22 +36,18 @@ const TITLES: Record<EditorMode, string> = {
3636
view: 'View document',
3737
edit: 'Edit document',
3838
duplicate: 'Duplicate document',
39-
insert: 'Insert document',
40-
'insert-many': 'Insert documents'
39+
insert: 'Insert documents'
4140
}
4241

4342
const DESCRIPTIONS: Record<EditorMode, string> = {
4443
view: 'Read-only — BSON types render as ObjectId / ISODate / UUID / NumberLong / NumberDecimal.',
4544
edit: 'Edit using mongo shell syntax — ObjectId("…"), ISODate("…"), NumberLong("…"), UUID/JUUID, regex literals.',
4645
duplicate: 'A copy with the original _id removed. Save inserts a new document with a fresh _id.',
4746
insert:
48-
'New document — mongo shell syntax. Leave _id out and the server will assign a fresh ObjectId.',
49-
'insert-many':
5047
'Multiple documents, one after another newline, comma-separated or JSON array. Leave _id out for a fresh ObjectId.'
5148
}
5249

5350
const INSERT_TEMPLATE = '{\n \n}'
54-
const INSERT_MANY_TEMPLATE = '{\n \n}\n{\n \n}'
5551

5652
/**
5753
* Read the canonical EJSON document carried by an envelope, then re-render
@@ -99,7 +95,7 @@ export function DocumentEditorDialog({
9995
timezone,
10096
onClose
10197
}: Props) {
102-
const open = mode !== null && (mode === 'insert' || mode === 'insert-many' || envelope !== null)
98+
const open = mode !== null && (mode === 'insert' || envelope !== null)
10399
const [value, setValue] = useState('')
104100
const [serverError, setServerError] = useState<string | null>(null)
105101
const queryClient = useQueryClient()
@@ -111,10 +107,6 @@ export function DocumentEditorDialog({
111107
setValue(INSERT_TEMPLATE)
112108
return
113109
}
114-
if (mode === 'insert-many') {
115-
setValue(INSERT_MANY_TEMPLATE)
116-
return
117-
}
118110
if (!envelope) return
119111
const rendered = shellRenderOf(envelope, uuidEncoding, timezone)
120112
setValue(mode === 'duplicate' ? stripIdShell(rendered, uuidEncoding, timezone) : rendered)
@@ -124,7 +116,7 @@ export function DocumentEditorDialog({
124116
{ ok: true; ejson: string; documents: string[] } | { ok: false; error: string }
125117
>(() => {
126118
if (mode === 'view' || mode === null) return { ok: true, ejson: '', documents: [] }
127-
if (mode === 'insert-many') {
119+
if (mode === 'insert') {
128120
const parsed = parseMongoDocuments(value)
129121
if (!parsed.ok) return { ok: false, error: parsed.error }
130122
if (parsed.documents.length === 0) return { ok: false, error: 'Enter at least one document' }
@@ -155,10 +147,10 @@ export function DocumentEditorDialog({
155147
replacement: compiled.ejson
156148
})
157149
}
158-
if (mode === 'insert-many') {
150+
if (mode === 'insert') {
159151
return api.query.insertMany({ connectionId, db, coll, documents: compiled.documents })
160152
}
161-
if (mode === 'duplicate' || mode === 'insert') {
153+
if (mode === 'duplicate') {
162154
return api.query.insertOne({ connectionId, db, coll, document: compiled.ejson })
163155
}
164156
throw new Error('Cannot save in view mode')
@@ -171,9 +163,7 @@ export function DocumentEditorDialog({
171163
? 'Document updated'
172164
: mode === 'duplicate'
173165
? 'Document duplicated'
174-
: mode === 'insert-many'
175-
? `Inserted ${manyCount} document${manyCount === 1 ? '' : 's'}`
176-
: 'Document inserted'
166+
: `Inserted ${manyCount} document${manyCount === 1 ? '' : 's'}`
177167
toast.success(successMessage)
178168
onClose()
179169
},
@@ -190,7 +180,7 @@ export function DocumentEditorDialog({
190180
if (!mode) return null
191181

192182
// Insert needs neither envelope nor _id; the others can't render without one.
193-
if (mode !== 'insert' && mode !== 'insert-many' && !envelope) return null
183+
if (mode !== 'insert' && !envelope) return null
194184

195185
const parseError = compiled.ok ? null : compiled.error
196186
const isReadOnly = mode === 'view'
@@ -199,11 +189,9 @@ export function DocumentEditorDialog({
199189
? 'Save changes'
200190
: mode === 'duplicate'
201191
? 'Insert duplicate'
202-
: mode === 'insert-many'
203-
? manyCount > 0
204-
? `Insert ${manyCount} document${manyCount === 1 ? '' : 's'}`
205-
: 'Insert documents'
206-
: 'Insert document'
192+
: manyCount > 0
193+
? `Insert ${manyCount} document${manyCount === 1 ? '' : 's'}`
194+
: 'Insert documents'
207195

208196
return (
209197
<Dialog open={open} onOpenChange={handleOpenChange}>
@@ -235,7 +223,7 @@ export function DocumentEditorDialog({
235223
}
236224
>
237225
<Editor
238-
key={mode === 'insert' || mode === 'insert-many' ? mode : `${envelope?.id}::${mode}`}
226+
key={mode === 'insert' ? 'insert' : `${envelope?.id}::${mode}`}
239227
height="100%"
240228
width="100%"
241229
value={value}

src/renderer/src/features/explorer/CollectionLeaf.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
ClipboardCopy,
66
Eye,
77
FilePlus2,
8-
Files,
98
Info,
109
KeyRound,
1110
Loader2,
@@ -41,7 +40,7 @@ import { RenameCollectionDialog } from '@/features/collection/RenameCollectionDi
4140
import { DocumentEditorDialog } from '@/features/document/DocumentEditorDialog'
4241
import { useQuery } from '@tanstack/react-query'
4342

44-
type DialogState = 'info' | 'rename' | 'drop' | 'indexes' | 'insert' | 'insert-many' | null
43+
type DialogState = 'info' | 'rename' | 'drop' | 'indexes' | 'insert' | null
4544

4645
export function CollectionLeaf({
4746
connectionId,
@@ -145,10 +144,6 @@ export function CollectionLeaf({
145144
<ContextMenuSeparator />
146145
<ContextMenuItem onSelect={() => setDialog('insert')} disabled={type === 'view'}>
147146
<FilePlus2 className="h-4 w-4" />
148-
Insert document…
149-
</ContextMenuItem>
150-
<ContextMenuItem onSelect={() => setDialog('insert-many')} disabled={type === 'view'}>
151-
<Files className="h-4 w-4" />
152147
Insert documents…
153148
</ContextMenuItem>
154149
<ContextMenuItem onSelect={() => setDialog('indexes')} disabled={type === 'view'}>
@@ -187,7 +182,7 @@ export function CollectionLeaf({
187182
/>
188183

189184
<DocumentEditorDialog
190-
mode={dialog === 'insert' ? 'insert' : dialog === 'insert-many' ? 'insert-many' : null}
185+
mode={dialog === 'insert' ? 'insert' : null}
191186
envelope={null}
192187
connectionId={connectionId}
193188
db={db}

0 commit comments

Comments
 (0)