Skip to content

Commit 254af5c

Browse files
committed
fix(files,tables): restore new-file editor autofocus and CSV import error toasts
Both were dropped on the staging line and regressed vs production (main): - Files: the new-file editor autofocus chain (files.tsx -> file-viewer -> text-editor) was stripped by the react-doctor dead-code pass in #4544, which misread the prop-drilled `autoFocus` (consumed by an imperative `editor.focus()` effect) as unused. Restored the prop through all three layers and the one-shot focus effect so creating a new file focuses the editor immediately. - Tables: CSV import failures were silently logged with no user feedback. Restored the per-file and generic `toast.error` surfacing.
1 parent b9cc9bc commit 254af5c

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/file-viewer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ interface FileViewerProps {
4343
workspaceId: string
4444
canEdit: boolean
4545
previewMode?: PreviewMode
46+
autoFocus?: boolean
4647
onDirtyChange?: (isDirty: boolean) => void
4748
onSaveStatusChange?: (status: 'idle' | 'saving' | 'saved' | 'error') => void
4849
saveRef?: React.MutableRefObject<(() => Promise<void>) | null>
@@ -57,6 +58,7 @@ export function FileViewer({
5758
workspaceId,
5859
canEdit,
5960
previewMode,
61+
autoFocus,
6062
onDirtyChange,
6163
onSaveStatusChange,
6264
saveRef,
@@ -74,6 +76,7 @@ export function FileViewer({
7476
workspaceId={workspaceId}
7577
canEdit={canEdit}
7678
previewMode={previewMode ?? 'editor'}
79+
autoFocus={autoFocus}
7780
onDirtyChange={onDirtyChange}
7881
onSaveStatusChange={onSaveStatusChange}
7982
saveRef={saveRef}

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ interface TextEditorProps {
392392
workspaceId: string
393393
canEdit: boolean
394394
previewMode: PreviewMode
395+
autoFocus?: boolean
395396
onDirtyChange?: (isDirty: boolean) => void
396397
onSaveStatusChange?: (status: 'idle' | 'saving' | 'saved' | 'error') => void
397398
saveRef?: React.MutableRefObject<(() => Promise<void>) | null>
@@ -406,6 +407,7 @@ export const TextEditor = memo(function TextEditor({
406407
workspaceId,
407408
canEdit,
408409
previewMode,
410+
autoFocus,
409411
onDirtyChange,
410412
onSaveStatusChange,
411413
saveRef,
@@ -417,6 +419,7 @@ export const TextEditor = memo(function TextEditor({
417419
const containerRef = useRef<HTMLDivElement>(null)
418420
const monacoEditorRef = useRef<Parameters<OnMount>[0] | null>(null)
419421
const lastSyncedContentRef = useRef('')
422+
const hasAutoFocusedRef = useRef(false)
420423
const contentRef = useRef('')
421424
const textareaStuckRef = useRef(false)
422425
const suppressScrollListenerRef = useRef(false)
@@ -633,6 +636,11 @@ export const TextEditor = memo(function TextEditor({
633636
lastSyncedContentRef.current = currentContent
634637
}
635638

639+
if (autoFocus && !hasAutoFocusedRef.current) {
640+
hasAutoFocusedRef.current = true
641+
editor.focus()
642+
}
643+
636644
const contextMenuDisposable = editor.onContextMenu((e) => {
637645
e.event.preventDefault()
638646
const sel = editor.getSelection()

apps/sim/app/workspace/[workspaceId]/files/files.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,7 @@ export function Files() {
18511851
workspaceId={workspaceId}
18521852
canEdit={canEdit}
18531853
previewMode={previewMode}
1854+
autoFocus={isNewFile || justCreatedFileIdRef.current === selectedFile.id}
18541855
onDirtyChange={setIsDirty}
18551856
onSaveStatusChange={setSaveStatus}
18561857
saveRef={saveRef}

apps/sim/app/workspace/[workspaceId]/tables/tables.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ export function Tables() {
398398
}
399399

400400
setUploadProgress({ completed: 0, total: csvFiles.length })
401+
const failed: string[] = []
401402

402403
for (let i = 0; i < csvFiles.length; i++) {
403404
try {
@@ -410,13 +411,23 @@ export function Tables() {
410411
}
411412
}
412413
} catch (err) {
414+
failed.push(csvFiles[i].name)
413415
logger.error('Error uploading CSV:', err)
414416
} finally {
415417
setUploadProgress({ completed: i + 1, total: csvFiles.length })
416418
}
417419
}
420+
421+
if (failed.length > 0) {
422+
toast.error(
423+
failed.length === 1
424+
? `Failed to import ${failed[0]}`
425+
: `Failed to import ${failed.length} file${failed.length > 1 ? 's' : ''}: ${failed.join(', ')}`
426+
)
427+
}
418428
} catch (err) {
419429
logger.error('Error uploading CSV:', err)
430+
toast.error('Failed to import CSV')
420431
} finally {
421432
setUploading(false)
422433
setUploadProgress({ completed: 0, total: 0 })

0 commit comments

Comments
 (0)