Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Joshen/fe 2540 fix safari csv drag drop typeerror in table editor (#42852)

Joshen Lim4651480f28f0
diff --git a/apps/studio/components/grid/components/grid/Grid.tsx b/apps/studio/components/grid/components/grid/Grid.tsx
index 0b589f5451f..2079e3692ea 100644
--- a/apps/studio/components/grid/components/grid/Grid.tsx
+++ b/apps/studio/components/grid/components/grid/Grid.tsx
@@ -97,12 +97,7 @@ export const Grid = memo(
const { mutate: sendEvent } = useSendEventMutation()
- const {
- isValidFile: isValidFileDraggedOver,
- isDraggedOver,
- onDragOver,
- onFileDrop,
- } = useCsvFileDrop({
+ const { isDraggedOver, onDragOver, onFileDrop } = useCsvFileDrop({
enabled: isTableEmpty && !isForeignTable,
onFileDropped: (file) => tableEditorSnap.onImportData(valtioRef(file)),
onTelemetryEvent: (eventName) => {
@@ -241,9 +236,7 @@ export const Grid = memo(
{(rows ?? []).length === 0 && (
<div
className={cn(
- 'absolute w-full inset-0 flex flex-col items-center justify-center p-2 z-[1] pointer-events-none',
- isTableEmpty && isDraggedOver && 'border-2 border-dashed',
- isValidFileDraggedOver ? 'border-brand-600' : 'border-destructive-600'
+ 'absolute w-full inset-0 flex flex-col items-center justify-center p-2 z-[1] pointer-events-none'
)}
>
{isLoading && !isDisabled && (
@@ -272,18 +265,13 @@ export const Grid = memo(
</div>
</div>
) : (filters ?? []).length === 0 ? (
- <div className="flex flex-col items-center justify-center">
- <p className="text-sm text-light pointer-events-auto">
- {isDraggedOver ? (
- isValidFileDraggedOver ? (
- 'Drop your CSV file here'
- ) : (
- <span className="text-destructive">Only CSV files are accepted</span>
- )
- ) : (
- 'This table is empty'
- )}
- </p>
+ <div
+ className={cn(
+ 'flex flex-col items-center justify-center w-full h-full mt-9 transition',
+ isTableEmpty && isDraggedOver && 'border-2 border-dashed border-brand'
+ )}
+ >
+ <p className="text-sm text-light pointer-events-auto">This table is empty</p>
{tableEntityType === ENTITY_TYPE.FOREIGN_TABLE ? (
<div className="flex items-center space-x-2 mt-4">
<p className="text-sm text-light pointer-events-auto">
@@ -292,30 +280,28 @@ export const Grid = memo(
</p>
</div>
) : (
- !isDraggedOver && (
- <div className="flex flex-col items-center gap-4 mt-4">
- <Button
- type="default"
- className="pointer-events-auto"
- onClick={() => {
- tableEditorSnap.onImportData()
- sendEvent({
- action: 'import_data_button_clicked',
- properties: { tableType: 'Existing Table' },
- groups: {
- project: project?.ref ?? 'Unknown',
- organization: org?.slug ?? 'Unknown',
- },
- })
- }}
- >
- Import data from CSV
- </Button>
- <p className="text-xs text-foreground-light pointer-events-auto">
- or drag and drop a CSV file here
- </p>
- </div>
- )
+ <div className="flex flex-col items-center gap-4 mt-4">
+ <Button
+ type="default"
+ className="pointer-events-auto"
+ onClick={() => {
+ tableEditorSnap.onImportData()
+ sendEvent({
+ action: 'import_data_button_clicked',
+ properties: { tableType: 'Existing Table' },
+ groups: {
+ project: project?.ref ?? 'Unknown',
+ organization: org?.slug ?? 'Unknown',
+ },
+ })
+ }}
+ >
+ Import data from CSV
+ </Button>
+ <p className="text-xs text-foreground-light pointer-events-auto">
+ or drag and drop a CSV file here
+ </p>
+ </div>
)}
</div>
) : (
diff --git a/apps/studio/hooks/ui/useCsvFileDrop.ts b/apps/studio/hooks/ui/useCsvFileDrop.ts
index 2f2da36a188..26119d23135 100644
--- a/apps/studio/hooks/ui/useCsvFileDrop.ts
+++ b/apps/studio/hooks/ui/useCsvFileDrop.ts
@@ -1,7 +1,6 @@
-import { type DragEvent, useCallback, useState } from 'react'
-
import { type ImportDataFileDroppedEvent } from 'common/telemetry-constants'
import { flagInvalidFileImport } from 'components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.utils'
+import { useCallback, useState, type DragEvent } from 'react'
interface UseCsvFileDropOptions {
enabled: boolean
@@ -11,7 +10,6 @@ interface UseCsvFileDropOptions {
interface UseCsvFileDropReturn {
isDraggedOver: boolean
- isValidFile: boolean
onDragOver: (event: DragEvent<HTMLDivElement>) => void
onFileDrop: (event: DragEvent<HTMLDivElement>) => void
}
@@ -22,7 +20,6 @@ export function useCsvFileDrop({
onTelemetryEvent,
}: UseCsvFileDropOptions): UseCsvFileDropReturn {
const [isDraggedOver, setIsDraggedOver] = useState(false)
- const [isValidFile, setIsValidFile] = useState(false)
const onDragOver = useCallback(
(event: DragEvent<HTMLDivElement>) => {
@@ -35,15 +32,13 @@ export function useCsvFileDrop({
if (event.type === 'dragover' && !isDraggedOver) {
setIsDraggedOver(true)
- setIsValidFile(item.type === 'text/csv')
} else if (event.type === 'dragleave' || event.type === 'drop') {
setIsDraggedOver(false)
- setIsValidFile(false)
}
event.stopPropagation()
event.preventDefault()
},
- [enabled, isDraggedOver, isValidFile]
+ [enabled, isDraggedOver]
)
const onFileDrop = useCallback(
@@ -68,7 +63,6 @@ export function useCsvFileDrop({
)
return {
- isValidFile: isValidFile && isDraggedOver,
isDraggedOver,
onDragOver,
onFileDrop,
diff --git a/e2e/studio/features/table-editor.spec.ts b/e2e/studio/features/table-editor.spec.ts
index 7cc237fc4fd..e3a4429f71b 100644
--- a/e2e/studio/features/table-editor.spec.ts
+++ b/e2e/studio/features/table-editor.spec.ts
@@ -1208,9 +1208,12 @@ testRunner('table editor', () => {
const gridContainer = page.getByTestId('table-editor-grid-container')
await gridContainer.dispatchEvent('dragover', { dataTransfer })
+
+ // After the refactor, the empty state text and import button remain visible during drag
+ // (no more "Drop your CSV file here" overlay), just a dashed border is shown
await expect(
- page.getByText('Drop your CSV file here'),
- 'Drag feedback should show when CSV is dragged over'
+ page.getByText('This table is empty'),
+ 'Empty table message should remain visible during drag'
).toBeVisible()
await gridContainer.dispatchEvent('drop', { dataTransfer })