Files
supabase/apps/studio/hooks/ui/useVisibleKey.ts
Usama Nadeem 55e0b34a18 fix(studio): add option to treat empty CSV cells as NULL on import (#43281)
When importing a CSV file, empty cells were always imported as empty
strings with no way to import NULL values instead. This adds a "Treat
empty cells as NULL" checkbox to the import configuration panel.

When enabled, PapaParse's transform option converts empty strings to
null before the data is parsed and previewed, so the imported rows
correctly contain NULL rather than empty strings.

Fixes #43258.

## What kind of change does this PR introduce?

Bug fix

## What is the current behavior?

Empty cells in a CSV file are always imported as empty strings with no
way to import NULL values instead. Fixes #43258.

## What is the new behavior?

"Treat empty cells as NULL" checkbox is added to the import
configuration panel. When enabled, empty cells are imported as NULL
instead of empty strings. Toggling the checkbox instantly re-parses the
preview.

## Additional context

The fix uses PapaParse's transform option to convert empty strings to
null before parsing. Applies to both file uploads and pasted text.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
2026-03-31 11:05:08 -04:00

21 lines
620 B
TypeScript

import { useState } from 'react'
/**
* Returns a key that increments each time `isVisible` transitions from false to true.
* Use this as the `key` prop on a component to force a clean remount on each open,
* instead of a `useEffect` that imperatively resets internal state.
*/
export function useVisibleKey(isVisible: boolean): number {
const [key, setKey] = useState(0)
const [prevIsVisible, setPrevIsVisible] = useState(false)
if (isVisible && !prevIsVisible) {
setPrevIsVisible(true)
setKey((k) => k + 1)
} else if (!isVisible && prevIsVisible) {
setPrevIsVisible(false)
}
return key
}