Skip to content

The open alternative to Salesforce, designed for AI.

Fix bulk update of emptied list fields, full name pasting and address separators (#28752)

Charles Bocheta5379312e6a6
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/utils/__tests__/formatAddressDisplay.test.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/utils/__tests__/formatAddressDisplay.test.ts
index 23f1c4f8d4f..22bf3d07449 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/utils/__tests__/formatAddressDisplay.test.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/utils/__tests__/formatAddressDisplay.test.ts
@@ -29,22 +29,28 @@ describe('formatAddressDisplay', () => {
'addressCity',
'addressState',
]);
- expect(result).toBe('123 Main St,New York,NY');
+ expect(result).toBe('123 Main St, New York, NY');
});
it('should format address with all fields when subFields is null', () => {
const result = formatAddressDisplay(mockAddressValue, null);
- expect(result).toBe('123 Main St,Apt 4B,New York,NY,10001,United States');
+ expect(result).toBe(
+ '123 Main St, Apt 4B, New York, NY, 10001, United States',
+ );
});
it('should format address with all fields when subFields is undefined', () => {
const result = formatAddressDisplay(mockAddressValue, undefined);
- expect(result).toBe('123 Main St,Apt 4B,New York,NY,10001,United States');
+ expect(result).toBe(
+ '123 Main St, Apt 4B, New York, NY, 10001, United States',
+ );
});
it('should format address with all fields when subFields is empty array', () => {
const result = formatAddressDisplay(mockAddressValue, []);
- expect(result).toBe('123 Main St,Apt 4B,New York,NY,10001,United States');
+ expect(result).toBe(
+ '123 Main St, Apt 4B, New York, NY, 10001, United States',
+ );
});
it('should handle address with some empty fields', () => {
@@ -66,7 +72,7 @@ describe('formatAddressDisplay', () => {
'addressState',
'addressPostcode',
]);
- expect(result).toBe('456 Oak Ave,Boston,02101');
+ expect(result).toBe('456 Oak Ave, Boston, 02101');
});
it('should handle single field selection', () => {
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/utils/__tests__/joinAddressFieldValues.test.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/utils/__tests__/joinAddressFieldValues.test.ts
index bc8548f6f32..f044182aa37 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/utils/__tests__/joinAddressFieldValues.test.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/utils/__tests__/joinAddressFieldValues.test.ts
@@ -19,7 +19,7 @@ describe('joinAddressFieldValues', () => {
'addressCity',
'addressState',
]);
- expect(result).toBe('123 Main St,New York,NY');
+ expect(result).toBe('123 Main St, New York, NY');
});
it('should filter out null and empty string values', () => {
@@ -42,7 +42,7 @@ describe('joinAddressFieldValues', () => {
'addressPostcode',
'addressCountry',
]);
- expect(result).toBe('456 Oak Ave,CA,90210');
+ expect(result).toBe('456 Oak Ave, CA, 90210');
});
it('should handle empty subFields array', () => {
@@ -64,7 +64,9 @@ describe('joinAddressFieldValues', () => {
'addressPostcode',
'addressCountry',
]);
- expect(result).toBe('123 Main St,Apt 4B,New York,NY,10001,United States');
+ expect(result).toBe(
+ '123 Main St, Apt 4B, New York, NY, 10001, United States',
+ );
});
it('should handle address with empty and null values', () => {
@@ -110,6 +112,6 @@ describe('joinAddressFieldValues', () => {
'addressState',
'addressPostcode',
]);
- expect(result).toBe('123 Main St,New York,10001');
+ expect(result).toBe('123 Main St, New York, 10001');
});
});
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/utils/joinAddressFieldValues.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/utils/joinAddressFieldValues.ts
index 49ef1b2d024..4ef98ded9e3 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/utils/joinAddressFieldValues.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/utils/joinAddressFieldValues.ts
@@ -9,5 +9,5 @@ export const joinAddressFieldValues = (
return subFields
.map((subField) => fieldValue[subField])
.filter(isNonEmptyString)
- .join(',');
+ .join(', ');
};
diff --git a/packages/twenty-front/src/modules/object-record/record-update-multiple/utils/__tests__/isUpdateRecordValueEmpty.test.ts b/packages/twenty-front/src/modules/object-record/record-update-multiple/utils/__tests__/isUpdateRecordValueEmpty.test.ts
index fc06f9e1062..b69cab8e1e3 100644
--- a/packages/twenty-front/src/modules/object-record/record-update-multiple/utils/__tests__/isUpdateRecordValueEmpty.test.ts
+++ b/packages/twenty-front/src/modules/object-record/record-update-multiple/utils/__tests__/isUpdateRecordValueEmpty.test.ts
@@ -26,6 +26,28 @@ describe('isUpdateRecordValueEmpty', () => {
expect(isUpdateRecordValueEmpty({ a: 1 })).toBe(false);
});
+ it('should return true for an emptied list field', () => {
+ expect(
+ isUpdateRecordValueEmpty({ primaryEmail: '', additionalEmails: [] }),
+ ).toBe(true);
+ expect(
+ isUpdateRecordValueEmpty({
+ primaryLinkUrl: '',
+ primaryLinkLabel: '',
+ secondaryLinks: [],
+ }),
+ ).toBe(true);
+ });
+
+ it('should return false for a list field with a value', () => {
+ expect(
+ isUpdateRecordValueEmpty({
+ primaryEmail: '[email protected]',
+ additionalEmails: [],
+ }),
+ ).toBe(false);
+ });
+
it('should return false for Date object', () => {
expect(isUpdateRecordValueEmpty(new Date())).toBe(false);
});
diff --git a/packages/twenty-front/src/modules/object-record/record-update-multiple/utils/isUpdateRecordValueEmpty.ts b/packages/twenty-front/src/modules/object-record/record-update-multiple/utils/isUpdateRecordValueEmpty.ts
index f58ee19bb29..7882ed4d113 100644
--- a/packages/twenty-front/src/modules/object-record/record-update-multiple/utils/isUpdateRecordValueEmpty.ts
+++ b/packages/twenty-front/src/modules/object-record/record-update-multiple/utils/isUpdateRecordValueEmpty.ts
@@ -1,5 +1,7 @@
-export const isUpdateRecordValueEmpty = (value: any): boolean => {
- if (value == null || value === '') {
+import { isDefined } from 'twenty-shared/utils';
+
+export const isUpdateRecordValueEmpty = (value: unknown): boolean => {
+ if (!isDefined(value) || value === '') {
return true;
}
@@ -12,9 +14,7 @@ export const isUpdateRecordValueEmpty = (value: any): boolean => {
}
if (typeof value === 'object') {
- return Object.values(value).every(
- (val) => val === null || val === undefined || val === '',
- );
+ return Object.values(value).every(isUpdateRecordValueEmpty);
}
return false;
diff --git a/packages/twenty-front/src/utils/format/__tests__/splitFullName.test.ts b/packages/twenty-front/src/utils/format/__tests__/splitFullName.test.ts
index 5ba3bc36bac..ed9465465d9 100644
--- a/packages/twenty-front/src/utils/format/__tests__/splitFullName.test.ts
+++ b/packages/twenty-front/src/utils/format/__tests__/splitFullName.test.ts
@@ -28,12 +28,12 @@ describe('splitFullName', () => {
it('should handle names with more than two parts', () => {
const result = splitFullName('John Michael Doe');
- expect(result).toEqual(['John', 'Michael']);
+ expect(result).toEqual(['John', 'Michael Doe']);
});
it('should handle names with multiple middle names', () => {
const result = splitFullName('John Michael Christopher Doe');
- expect(result).toEqual(['John', 'Michael']);
+ expect(result).toEqual(['John', 'Michael Christopher Doe']);
});
it('should handle names with hyphenated parts', () => {
@@ -65,7 +65,10 @@ describe('splitFullName', () => {
const result = splitFullName(
'John Michael Christopher Alexander Doe Smith Johnson',
);
- expect(result).toEqual(['John', 'Michael']);
+ expect(result).toEqual([
+ 'John',
+ 'Michael Christopher Alexander Doe Smith Johnson',
+ ]);
});
it('should handle single character names', () => {
@@ -75,6 +78,6 @@ describe('splitFullName', () => {
it('should handle names with numbers', () => {
const result = splitFullName('John Doe II');
- expect(result).toEqual(['John', 'Doe']);
+ expect(result).toEqual(['John', 'Doe II']);
});
});
diff --git a/packages/twenty-front/src/utils/format/splitFullName.ts b/packages/twenty-front/src/utils/format/splitFullName.ts
index 6ec1ac2d8ca..c1e95dc6ea1 100644
--- a/packages/twenty-front/src/utils/format/splitFullName.ts
+++ b/packages/twenty-front/src/utils/format/splitFullName.ts
@@ -1,13 +1,5 @@
export const splitFullName = (name: string) => {
- const splittedName = name.trim().split(/\s+/);
+ const [firstName = '', ...lastNameWords] = name.trim().split(/\s+/);
- if (splittedName.length === 2) {
- return splittedName;
- }
-
- if (splittedName.length > 2) {
- return [splittedName[0].trim(), splittedName[1].trim()];
- }
-
- return [name.trim(), ''];
+ return [firstName, lastNameWords.join(' ')];
};