Skip to content

Commit e0fbd43

Browse files
refactor(files): drive CSV preview import affordance off readOnly, not disableImport
1 parent bbfb596 commit e0fbd43

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/csv-import.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function useCsvTruncationImport(
2020
workspaceId: string,
2121
file: CsvImportFileDescriptor,
2222
truncated: boolean,
23-
disableImport = false
23+
readOnly = false
2424
) {
2525
const router = useRouter()
2626
const importFile = useImportFileAsTable()
@@ -59,11 +59,11 @@ export function useCsvTruncationImport(
5959
// Surface the cap as a warning toast with an import action, once per file.
6060
const notifiedKeyRef = useRef<string | null>(null)
6161
useEffect(() => {
62-
if (disableImport || !truncated || notifiedKeyRef.current === file.key) return
62+
if (readOnly || !truncated || notifiedKeyRef.current === file.key) return
6363
notifiedKeyRef.current = file.key
6464
toast.warning(`Showing the first ${CSV_PREVIEW_MAX_ROWS.toLocaleString()} rows`, {
6565
description: 'Import this file as a table to view all of its rows.',
6666
action: { label: 'Import as a table', onClick: importAsTable },
6767
})
68-
}, [disableImport, truncated, file.key, importAsTable])
68+
}, [readOnly, truncated, file.key, importAsTable])
6969
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ const ReadOnlyTextPreview = memo(function ReadOnlyTextPreview({
203203
filename={file.name}
204204
workspaceId={workspaceId}
205205
fileKey={file.key}
206-
disableImport
206+
readOnly
207207
/>
208208
</div>
209209
)

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ interface PreviewPanelProps {
8484
disableAutoScroll?: boolean
8585
onCheckboxToggle?: (checkboxIndex: number, checked: boolean) => void
8686
/**
87-
* Suppress the CSV "Import as a table" affordance. Set on read-only surfaces
88-
* (e.g. the public share page) where there is no authenticated workspace import.
87+
* Read-only surface (e.g. the public share page) — disables interactive
88+
* affordances such as the CSV "Import as a table" action, which needs an
89+
* authenticated workspace import.
8990
*/
90-
disableImport?: boolean
91+
readOnly?: boolean
9192
}
9293

9394
export const PreviewPanel = memo(function PreviewPanel({
@@ -99,7 +100,7 @@ export const PreviewPanel = memo(function PreviewPanel({
99100
isStreaming,
100101
disableAutoScroll,
101102
onCheckboxToggle,
102-
disableImport,
103+
readOnly,
103104
}: PreviewPanelProps) {
104105
const previewType = resolvePreviewType(mimeType, filename)
105106

@@ -119,7 +120,7 @@ export const PreviewPanel = memo(function PreviewPanel({
119120
content={content}
120121
workspaceId={workspaceId}
121122
file={{ key: fileKey, name: filename }}
122-
disableImport={disableImport}
123+
readOnly={readOnly}
123124
/>
124125
)
125126
if (previewType === 'svg') return <SvgPreview content={content} />
@@ -1174,15 +1175,15 @@ const CsvPreview = memo(function CsvPreview({
11741175
content,
11751176
workspaceId,
11761177
file,
1177-
disableImport,
1178+
readOnly,
11781179
}: {
11791180
content: string
11801181
workspaceId: string
11811182
file: CsvImportFileDescriptor
1182-
disableImport?: boolean
1183+
readOnly?: boolean
11831184
}) {
11841185
const { headers, rows, truncated } = useMemo(() => parseCsv(content), [content])
1185-
useCsvTruncationImport(workspaceId, file, truncated, disableImport)
1186+
useCsvTruncationImport(workspaceId, file, truncated, readOnly)
11861187

11871188
if (headers.length === 0) {
11881189
return (

0 commit comments

Comments
 (0)