Skip to content

Commit

Permalink
Fix for default values bug in undefined properties
Browse files Browse the repository at this point in the history
  • Loading branch information
fgatti675 committed Dec 12, 2024
1 parent 3f681c8 commit 86b6256
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/firecms_core/src/util/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ export function getDefaultValuesFor<M extends Record<string, any>>(properties: P
if (!properties) return {};
return Object.entries(properties)
.map(([key, property]) => {
if (!property) return {};
const value = getDefaultValueFor(property as PropertyOrBuilder);
return value === undefined ? {} : { [key]: value };
})
.reduce((a, b) => ({ ...a, ...b }), {}) as EntityValues<M>;
}

export function getDefaultValueFor(property: PropertyOrBuilder) {
export function getDefaultValueFor(property?: PropertyOrBuilder) {
if (!property) return undefined;
if (isPropertyBuilder(property)) return undefined;
if (property.defaultValue || property.defaultValue === null) {
return property.defaultValue;
Expand Down

0 comments on commit 86b6256

Please sign in to comment.