From 276b32f3312a87cd97bb3db2718d8955d51db6fd Mon Sep 17 00:00:00 2001 From: Ivan Vasilov Date: Wed, 4 Oct 2023 07:50:15 +0200 Subject: [PATCH] fix: Set the default value for boolean fields when creating a new row (#17844) * When creating a new row with boolean fields, preselect the default value for those fields. * When preparing row fields to be sent to the API, omit only fields which are not nullable. The not nullables can be sent to the API and they'll be interpreted correctly. --- .../SidePanelEditor/RowEditor/RowEditor.utils.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts index 0e3c82dd983..22dad69e460 100644 --- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts +++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts @@ -25,7 +25,7 @@ export const generateRowFields = ( isUndefined(row) && TEXT_TYPES.includes(column.format) ? null : isUndefined(row) && column.format === 'bool' && !column.is_nullable - ? 'true' + ? column.default_value : isUndefined(row) && column.format === 'bool' && column.is_nullable ? 'null' : isUndefined(row) @@ -188,7 +188,17 @@ export const generateRowObjectFromFields = ( rowObject[field.name] = value } }) - return includeNullProperties ? rowObject : omitBy(rowObject, isNull) + if (includeNullProperties) { + return rowObject + } else { + return omitBy(rowObject, (v, k) => { + const field = fields.find((f) => f.name === k) + if (field && field.isNullable) { + return false + } + return isNull(v) + }) + } } export const generateUpdateRowPayload = (originalRow: any, field: RowField[]) => {