Fixing phone search functionality (#9466)

This PR targets twentyhq/core-team-issues#85. 

@FelixMalfait As we discussed I have made those changes . Could you
please test it at your end?

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Murali Singh
2025-01-13 15:24:00 +05:30
committed by GitHub
parent 128abb2b85
commit 002cbd3b78
7 changed files with 32 additions and 80 deletions

View File

@ -103,7 +103,6 @@ export type EmailsFilter = {
export type PhonesFilter = { export type PhonesFilter = {
primaryPhoneNumber?: StringFilter; primaryPhoneNumber?: StringFilter;
primaryPhoneCountryCode?: StringFilter;
}; };
export type SelectFilter = { export type SelectFilter = {

View File

@ -1 +1 @@
export const NUMBER_FILTER_TYPES = ['NUMBER', 'CURRENCY']; export const NUMBER_FILTER_TYPES = ['NUMBER', 'CURRENCY', 'PHONES'];

View File

@ -2,7 +2,6 @@ export const TEXT_FILTER_TYPES = [
'TEXT', 'TEXT',
'EMAIL', 'EMAIL',
'EMAILS', 'EMAILS',
'PHONE',
'FULL_NAME', 'FULL_NAME',
'LINK', 'LINK',
'LINKS', 'LINKS',
@ -10,5 +9,4 @@ export const TEXT_FILTER_TYPES = [
'ACTOR', 'ACTOR',
'ARRAY', 'ARRAY',
'RAW_JSON', 'RAW_JSON',
'PHONES',
]; ];

View File

@ -588,36 +588,16 @@ describe('should work as expected for the different field types', () => {
}, },
}, },
}, },
{
phones: {
primaryPhoneCountryCode: {
ilike: '%1234567890%',
},
},
},
], ],
}, },
{ {
and: [ not: {
{ phones: {
not: { primaryPhoneNumber: {
phones: { ilike: '%1234567890%',
primaryPhoneNumber: {
ilike: '%1234567890%',
},
},
}, },
}, },
{ },
not: {
phones: {
primaryPhoneCountryCode: {
ilike: '%1234567890%',
},
},
},
},
],
}, },
{ {
and: [ 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: '',
},
},
},
],
},
], ],
}, },
}, },

View File

@ -10,6 +10,7 @@ import {
EmailsFilter, EmailsFilter,
FloatFilter, FloatFilter,
MultiSelectFilter, MultiSelectFilter,
PhonesFilter,
RatingFilter, RatingFilter,
RawJsonFilter, RawJsonFilter,
RecordGqlOperationFilter, RecordGqlOperationFilter,
@ -831,23 +832,34 @@ const computeFilterRecordGqlOperationFilter = (
); );
} }
case 'PHONES': { case 'PHONES': {
const phonesFilters = generateILikeFiltersForCompositeFields( const filterValue = filter.value.replace(/[^0-9]/g, '');
filter.value,
correspondingField.name,
['primaryPhoneNumber', 'primaryPhoneCountryCode'],
);
switch (filter.operand) { switch (filter.operand) {
case ViewFilterOperand.Contains: case ViewFilterOperand.Contains:
return { return {
or: phonesFilters, or: [
{
[correspondingField.name]: {
primaryPhoneNumber: {
ilike: `%${filterValue}%`,
},
} as PhonesFilter,
},
],
}; };
case ViewFilterOperand.DoesNotContain: case ViewFilterOperand.DoesNotContain:
return { return {
and: phonesFilters.map((filter) => { and: [
return { {
not: filter, not: {
}; [correspondingField.name]: {
}), primaryPhoneNumber: {
ilike: `%${filterValue}%`,
},
} as PhonesFilter,
},
},
],
}; };
case ViewFilterOperand.IsEmpty: case ViewFilterOperand.IsEmpty:
case ViewFilterOperand.IsNotEmpty: case ViewFilterOperand.IsNotEmpty:

View File

@ -46,7 +46,7 @@ export const getEmptyRecordGqlOperationFilter = (
const phonesFilter = generateILikeFiltersForCompositeFields( const phonesFilter = generateILikeFiltersForCompositeFields(
'', '',
correspondingField.name, correspondingField.name,
['primaryPhoneNumber', 'primaryPhoneCountryCode'], ['primaryPhoneNumber'],
true, true,
); );

View File

@ -324,8 +324,7 @@ export const isRecordMatchingFilter = ({
const phonesFilter = filterValue as PhonesFilter; const phonesFilter = filterValue as PhonesFilter;
const keys: (keyof PhonesFilter)[] = [ const keys: (keyof PhonesFilter)[] = [
'primaryPhoneNumber', 'primaryPhoneNumber'
'primaryPhoneCountryCode',
]; ];
return keys.some((key) => { return keys.some((key) => {