The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Ignore defaultValue update for select fields (#4193)
Charles Bochet6a1abba9eaa7
diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/utils/__tests__/transform-metadata-for-comparison.util.spec.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/utils/__tests__/transform-metadata-for-comparison.util.spec.tsindex eac21ff46fc..ffa322ebc1f 100644--- a/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/utils/__tests__/transform-metadata-for-comparison.util.spec.ts+++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/utils/__tests__/transform-metadata-for-comparison.util.spec.ts@@ -21,7 +21,7 @@ describe('transformMetadataForComparison', () => {{ name: 'Test2', value: { c: 3 }, extra: 'keepMe' },];const result = transformMetadataForComparison(input, {- propertiesToIgnore: ['ignored'],+ shouldIgnoreProperty: (property) => ['ignored'].includes(property),propertiesToStringify: ['value'],keyFactory: (datum) => datum.name,});diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/utils/transform-metadata-for-comparison.util.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/utils/transform-metadata-for-comparison.util.tsindex 963b568125f..3c55aa1d021 100644--- a/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/utils/transform-metadata-for-comparison.util.ts+++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/utils/transform-metadata-for-comparison.util.ts@@ -8,7 +8,7 @@ type TransformToString<T, Keys extends keyof T> = {export function transformMetadataForComparison<T, Keys extends keyof T>(fieldMetadataCollection: T[],options: {- propertiesToIgnore?: readonly Keys[];+ shouldIgnoreProperty?: (property: string, originalMetadata?: T) => boolean;propertiesToStringify?: readonly Keys[];keyFactory: (datum: T) => string;},@@ -18,7 +18,7 @@ export function transformMetadataForComparison<T, Keys extends keyof T>(export function transformMetadataForComparison<T, Keys extends keyof T>(fieldMetadataCollection: T,options: {- propertiesToIgnore?: readonly Keys[];+ shouldIgnoreProperty?: (property: string, originalMetadata?: T) => boolean;propertiesToStringify?: readonly Keys[];},): TransformToString<T, Keys>;@@ -26,13 +26,11 @@ export function transformMetadataForComparison<T, Keys extends keyof T>(export function transformMetadataForComparison<T, Keys extends keyof T>(metadata: T[] | T,options: {- propertiesToIgnore?: readonly Keys[];+ shouldIgnoreProperty?: (property: string, originalMetadata?: T) => boolean;propertiesToStringify?: readonly Keys[];keyFactory?: (datum: T) => string;},): Record<string, TransformToString<T, Keys>> | TransformToString<T, Keys> {- const propertiesToIgnore = (options.propertiesToIgnore ??- []) as readonly string[];const propertiesToStringify = (options.propertiesToStringify ??[]) as readonly string[];@@ -40,7 +38,10 @@ export function transformMetadataForComparison<T, Keys extends keyof T>(const transformedField = {} as TransformToString<T, Keys>;for (const property in datum) {- if (propertiesToIgnore.includes(property)) {+ if (+ options.shouldIgnoreProperty &&+ options.shouldIgnoreProperty(property, datum)+ ) {continue;}if (diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-field.comparator.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-field.comparator.tsindex 14decf17849..0b85ea648f5 100644--- a/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-field.comparator.ts+++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-field.comparator.ts@@ -11,15 +11,16 @@ import { PartialObjectMetadata } from 'src/workspace/workspace-sync-metadata/intimport { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity';import { transformMetadataForComparison } from 'src/workspace/workspace-sync-metadata/comparators/utils/transform-metadata-for-comparison.util';+import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';-const fieldPropertiesToIgnore = [+const commonFieldPropertiesToIgnore = ['id','createdAt','updatedAt','objectMetadataId','isActive','options',-] as const;+];const fieldPropertiesToStringify = ['targetColumnMap', 'defaultValue'] as const;@@ -36,13 +37,28 @@ export class WorkspaceFieldComparator {string,Partial<PartialFieldMetadata>> = {};+// Double security to only compare non-custom fieldsconst filteredOriginalFieldCollection =originalObjectMetadata.fields.filter((field) => !field.isCustom);const originalFieldMetadataMap = transformMetadataForComparison(filteredOriginalFieldCollection,{- propertiesToIgnore: fieldPropertiesToIgnore,+ shouldIgnoreProperty: (property, originalMetadata) => {+ if (commonFieldPropertiesToIgnore.includes(property)) {+ return true;+ }++ if (+ originalMetadata &&+ property === 'defaultValue' &&+ originalMetadata.type === FieldMetadataType.SELECT+ ) {+ return true;+ }++ return false;+ },propertiesToStringify: fieldPropertiesToStringify,keyFactory(datum) {return datum.name;@@ -52,7 +68,21 @@ export class WorkspaceFieldComparator {const standardFieldMetadataMap = transformMetadataForComparison(standardObjectMetadata.fields,{- propertiesToIgnore: ['options'],+ shouldIgnoreProperty: (property, originalMetadata) => {+ if (['options'].includes(property)) {+ return true;+ }++ if (+ originalMetadata &&+ property === 'defaultValue' &&+ originalMetadata.type === FieldMetadataType.SELECT+ ) {+ return true;+ }++ return false;+ },propertiesToStringify: fieldPropertiesToStringify,keyFactory(datum) {return datum.name;diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-object.comparator.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-object.comparator.tsindex bcbd562703f..45bd6ce1812 100644--- a/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-object.comparator.ts+++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-object.comparator.ts@@ -20,7 +20,7 @@ const objectPropertiesToIgnore = ['imageIdentifierFieldMetadataId','isActive','fields',-] as const;+];@Injectable()export class WorkspaceObjectComparator {@@ -44,7 +44,8 @@ export class WorkspaceObjectComparator {const partialOriginalObjectMetadata = transformMetadataForComparison(originalObjectMetadata,{- propertiesToIgnore: objectPropertiesToIgnore,+ shouldIgnoreProperty: (property) =>+ objectPropertiesToIgnore.includes(property),},);diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-relation.comparator.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-relation.comparator.tsindex 33f5d7c3ac0..9982c27ade4 100644--- a/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-relation.comparator.ts+++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/comparators/workspace-relation.comparator.ts@@ -10,7 +10,7 @@ import {import { RelationMetadataEntity } from 'src/metadata/relation-metadata/relation-metadata.entity';import { transformMetadataForComparison } from 'src/workspace/workspace-sync-metadata/comparators/utils/transform-metadata-for-comparison.util';-const relationPropertiesToIgnore = ['createdAt', 'updatedAt'] as const;+const relationPropertiesToIgnore = ['createdAt', 'updatedAt'];const relationPropertiesToUpdate = ['onDeleteAction'];@Injectable()@@ -38,7 +38,8 @@ export class WorkspaceRelationComparator {const originalRelationMetadataMap = transformMetadataForComparison(originalRelationMetadataCollection,{- propertiesToIgnore: relationPropertiesToIgnore,+ shouldIgnoreProperty: (property) =>+ relationPropertiesToIgnore.includes(property),keyFactory(relationMetadata) {return `${relationMetadata.fromObjectMetadataId}->${relationMetadata.fromFieldMetadataId}`;},