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.
This commit is contained in:
Ivan Vasilov authored and GitHub committed 2023-10-04 13:50:15 +08:00
1 parent cecb244ac6
commit 276b32f331
1 file changed
+12 -2
@@ -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[]) => {