Skip to content

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

Fix row editor treating 0 as empty value and hence throws error when column is not nullable, midway writing tests

Joshen Lim31f901433041
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
index 94f4f39d8d7..81826dcbf9b 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
@@ -75,7 +75,12 @@ export const validateFields = (fields: RowField[]) => {
}
}
if (field.isIdentity || field.defaultValue) return
- if (!field.isNullable && !field.value && field.defaultValue === null) {
+ if (
+ !field.isNullable &&
+ typeof field.value === 'string' &&
+ field.value.length === 0 &&
+ field.defaultValue === null
+ ) {
errors[field.name] = `Please assign a value for this field`
}
})
diff --git a/studio/tests/components/Editor/RowEditor.utils.test.js b/studio/tests/components/Editor/RowEditor.utils.test.js
new file mode 100644
index 00000000000..8062785ad91
--- /dev/null
+++ b/studio/tests/components/Editor/RowEditor.utils.test.js
@@ -0,0 +1,25 @@
+import { validateFields } from 'components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils'
+
+describe('RowEditor.utils: validateFields', () => {
+ test('should non-nullable fields correctly', () => {
+ const mockFields = [
+ {
+ name: 'name',
+ value: '',
+ format: 'text',
+ defaultValue: null,
+ isNullable: false,
+ },
+ {
+ name: 'number',
+ value: 0,
+ format: 'text',
+ defaultValue: null,
+ isNullable: false,
+ },
+ ]
+ const res = validateFields(mockFields)
+ console.log('res', res)
+ expect(res).toHaveProperty('name')
+ })
+})