Skip to content

Commit bbfb596

Browse files
fix(files): disable CSV import action in read-only preview (public share)
1 parent 672a267 commit bbfb596

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export type CsvImportFileDescriptor = Pick<WorkspaceFileRecord, 'key' | 'name'>
1919
export function useCsvTruncationImport(
2020
workspaceId: string,
2121
file: CsvImportFileDescriptor,
22-
truncated: boolean
22+
truncated: boolean,
23+
disableImport = false
2324
) {
2425
const router = useRouter()
2526
const importFile = useImportFileAsTable()
@@ -58,11 +59,11 @@ export function useCsvTruncationImport(
5859
// Surface the cap as a warning toast with an import action, once per file.
5960
const notifiedKeyRef = useRef<string | null>(null)
6061
useEffect(() => {
61-
if (!truncated || notifiedKeyRef.current === file.key) return
62+
if (disableImport || !truncated || notifiedKeyRef.current === file.key) return
6263
notifiedKeyRef.current = file.key
6364
toast.warning(`Showing the first ${CSV_PREVIEW_MAX_ROWS.toLocaleString()} rows`, {
6465
description: 'Import this file as a table to view all of its rows.',
6566
action: { label: 'Import as a table', onClick: importAsTable },
6667
})
67-
}, [truncated, file.key, importAsTable])
68+
}, [disableImport, truncated, file.key, importAsTable])
6869
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ const ReadOnlyTextPreview = memo(function ReadOnlyTextPreview({
203203
filename={file.name}
204204
workspaceId={workspaceId}
205205
fileKey={file.key}
206+
disableImport
206207
/>
207208
</div>
208209
)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ interface PreviewPanelProps {
8383
isStreaming?: boolean
8484
disableAutoScroll?: boolean
8585
onCheckboxToggle?: (checkboxIndex: number, checked: boolean) => void
86+
/**
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.
89+
*/
90+
disableImport?: boolean
8691
}
8792

8893
export const PreviewPanel = memo(function PreviewPanel({
@@ -94,6 +99,7 @@ export const PreviewPanel = memo(function PreviewPanel({
9499
isStreaming,
95100
disableAutoScroll,
96101
onCheckboxToggle,
102+
disableImport,
97103
}: PreviewPanelProps) {
98104
const previewType = resolvePreviewType(mimeType, filename)
99105

@@ -113,6 +119,7 @@ export const PreviewPanel = memo(function PreviewPanel({
113119
content={content}
114120
workspaceId={workspaceId}
115121
file={{ key: fileKey, name: filename }}
122+
disableImport={disableImport}
116123
/>
117124
)
118125
if (previewType === 'svg') return <SvgPreview content={content} />
@@ -1167,13 +1174,15 @@ const CsvPreview = memo(function CsvPreview({
11671174
content,
11681175
workspaceId,
11691176
file,
1177+
disableImport,
11701178
}: {
11711179
content: string
11721180
workspaceId: string
11731181
file: CsvImportFileDescriptor
1182+
disableImport?: boolean
11741183
}) {
11751184
const { headers, rows, truncated } = useMemo(() => parseCsv(content), [content])
1176-
useCsvTruncationImport(workspaceId, file, truncated)
1185+
useCsvTruncationImport(workspaceId, file, truncated, disableImport)
11771186

11781187
if (headers.length === 0) {
11791188
return (

0 commit comments

Comments
 (0)