Skip to content

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

Add set to null action in row side panel editor for text types

Joshen Lim7d07ae893231
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnDefaultValue.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnDefaultValue.tsx
index 60bd565fb0b..5e58fa116b3 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnDefaultValue.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnDefaultValue.tsx
@@ -55,7 +55,7 @@ const ColumnDefaultValue: FC<Props> = ({
description="Can either be a literal or an expression (e.g uuid_generate_v4())"
placeholder={
typeof columnFields.defaultValue === 'string' && columnFields.defaultValue.length === 0
- ? 'Empty string'
+ ? 'EMPTY'
: 'NULL'
}
value={columnFields?.defaultValue ?? ''}
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx
index 065831046cc..508206a910b 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx
@@ -42,7 +42,7 @@ const InputField: FC<Props> = ({
field.defaultValue === null
? ''
: typeof field.defaultValue === 'string' && field.defaultValue.length === 0
- ? 'Default: Empty string'
+ ? 'EMPTY'
: `Default: ${field.defaultValue}`
}
onChange={(event: any) => onUpdateField({ [field.name]: event.target.value })}
@@ -127,11 +127,26 @@ const InputField: FC<Props> = ({
rows={5}
value={field.value ?? ''}
placeholder={
- field.defaultValue === null
+ field.value === null && field.defaultValue === null
? 'NULL'
+ : field.value === ''
+ ? 'EMPTY'
: typeof field.defaultValue === 'string' && field.defaultValue.length === 0
? 'EMPTY'
- : `Default: ${field.defaultValue}`
+ : `NULL (Default: ${field.defaultValue})`
+ }
+ actions={
+ <div className="mr-1 mt-0.5">
+ {(field.isNullable || (!field.isNullable && field.defaultValue)) && (
+ <Button
+ type="default"
+ size="tiny"
+ onClick={() => onUpdateField({ [field.name]: null })}
+ >
+ Set to NULL
+ </Button>
+ )}
+ </div>
}
onChange={(event: any) => onUpdateField({ [field.name]: event.target.value })}
/>
@@ -148,7 +163,7 @@ const InputField: FC<Props> = ({
descriptionText={field.comment}
labelOptional={field.format}
disabled={!isEditable}
- placeholder={field?.defaultValue ?? ''}
+ placeholder={field?.defaultValue ?? 'NULL'}
error={errors[field.name]}
onChange={(event: any) => onUpdateField({ [field.name]: event.target.value })}
actions={
@@ -195,7 +210,7 @@ const InputField: FC<Props> = ({
? 'Automatically generated as identity'
: field.defaultValue !== null
? `Default: ${field.defaultValue}`
- : ''
+ : 'NULL'
}
disabled={!isEditable}
onChange={(event: any) => onUpdateField({ [field.name]: event.target.value })}
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
index 4ebd6a4f6bc..46674767e88 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
@@ -139,6 +139,8 @@ const RowEditor: FC<Props> = ({
configuration.rowIdx = row!.idx
}
+ console.log({ payload })
+
saveChanges(payload, isNewRecord, configuration, () => setLoading(false))
} else {
setLoading(false)
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
index 7bbe183f5f7..25112532558 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
@@ -5,7 +5,12 @@ import type { PostgresTable } from '@supabase/postgres-meta'
import { uuidv4, minifyJSON, tryParseJson } from 'lib/helpers'
import { RowField } from './RowEditor.types'
-import { DATETIME_TYPES, TIME_TYPES, TIMESTAMP_TYPES } from '../SidePanelEditor.constants'
+import {
+ DATETIME_TYPES,
+ TIME_TYPES,
+ TIMESTAMP_TYPES,
+ TEXT_TYPES,
+} from '../SidePanelEditor.constants'
export const generateRowFields = (
row: Dictionary<any> | undefined,
@@ -16,11 +21,14 @@ export const generateRowFields = (
const primaryKeyColumns = primary_keys.map((key) => key.name)
return table.columns!.map((column) => {
- const value = isUndefined(row)
- ? ''
- : DATETIME_TYPES.includes(column.format)
- ? convertPostgresDatetimeToInputDatetime(column.format, row[column.name])
- : parseValue(row[column.name], column.format)
+ const value =
+ isUndefined(row) && TEXT_TYPES.includes(column.format)
+ ? null
+ : isUndefined(row)
+ ? ''
+ : DATETIME_TYPES.includes(column.format)
+ ? convertPostgresDatetimeToInputDatetime(column.format, row[column.name])
+ : parseValue(row[column.name], column.format)
const foreignKey = find(relationships, (relationship) => {
return (
@@ -162,7 +170,14 @@ export const generateRowObjectFromFields = (
const rowObject = {} as any
fields.forEach((field) => {
const isArray = field.format.startsWith('_')
- const value = (field?.value ?? '').length === 0 ? null : field.value
+
+ // Do not convert empty field inputs to NULL for text types
+ // so that we discern NULL and EMPTY
+ const value = TEXT_TYPES.includes(field.format)
+ ? field.value
+ : (field?.value ?? '').length === 0
+ ? null
+ : field.value
if (isArray && value !== null) {
rowObject[field.name] = tryParseJson(value)
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
index ceb74988e6c..1305a22b45f 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
@@ -157,7 +157,7 @@ const Column: FC<Props> = ({
<InputWithSuggestions
placeholder={
typeof column.defaultValue === 'string' && column.defaultValue.length === 0
- ? 'Empty string'
+ ? 'EMPTY'
: 'NULL'
}
size="small"