From 23c4d7dd26e88823d0b4b475794f8121295e8ee0 Mon Sep 17 00:00:00 2001 From: muraliSingh7 Date: Thu, 9 Jan 2025 00:04:34 +0530 Subject: [PATCH 1/2] Fixing phone search functionality --- .../graphql/types/RecordGqlOperationFilter.ts | 1 - .../constants/NumberFilterTypes.ts | 2 +- .../constants/TextFilterTypes.ts | 2 - ...omputeViewRecordGqlOperationFilter.test.ts | 66 ++----------------- .../computeViewRecordGqlOperationFilter.ts | 36 ++++++---- .../utils/getEmptyRecordGqlOperationFilter.ts | 2 +- .../utils/isRecordMatchingFilter.ts | 3 +- 7 files changed, 32 insertions(+), 80 deletions(-) diff --git a/packages/twenty-front/src/modules/object-record/graphql/types/RecordGqlOperationFilter.ts b/packages/twenty-front/src/modules/object-record/graphql/types/RecordGqlOperationFilter.ts index 1d4fb29bc991..c973e687c55b 100644 --- a/packages/twenty-front/src/modules/object-record/graphql/types/RecordGqlOperationFilter.ts +++ b/packages/twenty-front/src/modules/object-record/graphql/types/RecordGqlOperationFilter.ts @@ -103,7 +103,6 @@ export type EmailsFilter = { export type PhonesFilter = { primaryPhoneNumber?: StringFilter; - primaryPhoneCountryCode?: StringFilter; }; export type SelectFilter = { diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/NumberFilterTypes.ts b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/NumberFilterTypes.ts index 5f36ae347fd8..bef345b8bc0a 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/NumberFilterTypes.ts +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/NumberFilterTypes.ts @@ -1 +1 @@ -export const NUMBER_FILTER_TYPES = ['NUMBER', 'CURRENCY']; +export const NUMBER_FILTER_TYPES = ['NUMBER', 'CURRENCY', 'PHONE', 'PHONES']; diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/TextFilterTypes.ts b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/TextFilterTypes.ts index 9ff7456c42f4..0c702e01cf0a 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/TextFilterTypes.ts +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/TextFilterTypes.ts @@ -2,7 +2,6 @@ export const TEXT_FILTER_TYPES = [ 'TEXT', 'EMAIL', 'EMAILS', - 'PHONE', 'FULL_NAME', 'LINK', 'LINKS', @@ -10,5 +9,4 @@ export const TEXT_FILTER_TYPES = [ 'ACTOR', 'ARRAY', 'RAW_JSON', - 'PHONES', ]; diff --git a/packages/twenty-front/src/modules/object-record/record-filter/utils/__tests__/computeViewRecordGqlOperationFilter.test.ts b/packages/twenty-front/src/modules/object-record/record-filter/utils/__tests__/computeViewRecordGqlOperationFilter.test.ts index 694107ae3c12..9542d5e4280c 100644 --- a/packages/twenty-front/src/modules/object-record/record-filter/utils/__tests__/computeViewRecordGqlOperationFilter.test.ts +++ b/packages/twenty-front/src/modules/object-record/record-filter/utils/__tests__/computeViewRecordGqlOperationFilter.test.ts @@ -588,36 +588,16 @@ describe('should work as expected for the different field types', () => { }, }, }, - { - phones: { - primaryPhoneCountryCode: { - ilike: '%1234567890%', - }, - }, - }, ], }, { - and: [ - { - not: { - phones: { - primaryPhoneNumber: { - ilike: '%1234567890%', - }, - }, - }, - }, - { - not: { - phones: { - primaryPhoneCountryCode: { - ilike: '%1234567890%', - }, - }, + not: { + phones: { + primaryPhoneNumber: { + ilike: '%1234567890%', }, }, - ], + }, }, { and: [ @@ -639,24 +619,6 @@ describe('should work as expected for the different field types', () => { }, ], }, - { - or: [ - { - phones: { - primaryPhoneCountryCode: { - is: 'NULL', - }, - }, - }, - { - phones: { - primaryPhoneCountryCode: { - ilike: '', - }, - }, - }, - ], - }, ], }, { @@ -680,24 +642,6 @@ describe('should work as expected for the different field types', () => { }, ], }, - { - or: [ - { - phones: { - primaryPhoneCountryCode: { - is: 'NULL', - }, - }, - }, - { - phones: { - primaryPhoneCountryCode: { - ilike: '', - }, - }, - }, - ], - }, ], }, }, diff --git a/packages/twenty-front/src/modules/object-record/record-filter/utils/computeViewRecordGqlOperationFilter.ts b/packages/twenty-front/src/modules/object-record/record-filter/utils/computeViewRecordGqlOperationFilter.ts index c806dd3fe41d..c47c0f86fe2e 100644 --- a/packages/twenty-front/src/modules/object-record/record-filter/utils/computeViewRecordGqlOperationFilter.ts +++ b/packages/twenty-front/src/modules/object-record/record-filter/utils/computeViewRecordGqlOperationFilter.ts @@ -10,6 +10,7 @@ import { EmailsFilter, FloatFilter, MultiSelectFilter, + PhonesFilter, RatingFilter, RawJsonFilter, RecordGqlOperationFilter, @@ -831,23 +832,34 @@ const computeFilterRecordGqlOperationFilter = ( ); } case 'PHONES': { - const phonesFilters = generateILikeFiltersForCompositeFields( - filter.value, - correspondingField.name, - ['primaryPhoneNumber', 'primaryPhoneCountryCode'], - ); + const filterValue = filter.value.replace(/[^0-9]/g, ''); + switch (filter.operand) { case ViewFilterOperand.Contains: return { - or: phonesFilters, + or: [ + { + [correspondingField.name]: { + primaryPhoneNumber: { + ilike: `%${filterValue}%`, + }, + } as PhonesFilter, + }, + ], }; case ViewFilterOperand.DoesNotContain: - return { - and: phonesFilters.map((filter) => { - return { - not: filter, - }; - }), + return { + and: [ + { + not: { + [correspondingField.name]: { + primaryPhoneNumber: { + ilike: `%${filterValue}%`, + }, + } as PhonesFilter, + }, + }, + ], }; case ViewFilterOperand.IsEmpty: case ViewFilterOperand.IsNotEmpty: diff --git a/packages/twenty-front/src/modules/object-record/record-filter/utils/getEmptyRecordGqlOperationFilter.ts b/packages/twenty-front/src/modules/object-record/record-filter/utils/getEmptyRecordGqlOperationFilter.ts index b2cce9468bc5..5fb5a09464f0 100644 --- a/packages/twenty-front/src/modules/object-record/record-filter/utils/getEmptyRecordGqlOperationFilter.ts +++ b/packages/twenty-front/src/modules/object-record/record-filter/utils/getEmptyRecordGqlOperationFilter.ts @@ -46,7 +46,7 @@ export const getEmptyRecordGqlOperationFilter = ( const phonesFilter = generateILikeFiltersForCompositeFields( '', correspondingField.name, - ['primaryPhoneNumber', 'primaryPhoneCountryCode'], + ['primaryPhoneNumber'], true, ); diff --git a/packages/twenty-front/src/modules/object-record/record-filter/utils/isRecordMatchingFilter.ts b/packages/twenty-front/src/modules/object-record/record-filter/utils/isRecordMatchingFilter.ts index 88b3780b8c7e..e11a8fab0322 100644 --- a/packages/twenty-front/src/modules/object-record/record-filter/utils/isRecordMatchingFilter.ts +++ b/packages/twenty-front/src/modules/object-record/record-filter/utils/isRecordMatchingFilter.ts @@ -324,8 +324,7 @@ export const isRecordMatchingFilter = ({ const phonesFilter = filterValue as PhonesFilter; const keys: (keyof PhonesFilter)[] = [ - 'primaryPhoneNumber', - 'primaryPhoneCountryCode', + 'primaryPhoneNumber' ]; return keys.some((key) => { From 67646db86eae72245b7aacf363b59af390151a3b Mon Sep 17 00:00:00 2001 From: muraliSingh7 Date: Thu, 9 Jan 2025 11:37:05 +0530 Subject: [PATCH 2/2] Removed "PHONE" from number filter types --- .../object-filter-dropdown/constants/NumberFilterTypes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/NumberFilterTypes.ts b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/NumberFilterTypes.ts index bef345b8bc0a..c17732c2dd94 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/NumberFilterTypes.ts +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/constants/NumberFilterTypes.ts @@ -1 +1 @@ -export const NUMBER_FILTER_TYPES = ['NUMBER', 'CURRENCY', 'PHONE', 'PHONES']; +export const NUMBER_FILTER_TYPES = ['NUMBER', 'CURRENCY', 'PHONES'];