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:
@ -103,7 +103,6 @@ export type EmailsFilter = {
|
||||
|
||||
export type PhonesFilter = {
|
||||
primaryPhoneNumber?: StringFilter;
|
||||
primaryPhoneCountryCode?: StringFilter;
|
||||
};
|
||||
|
||||
export type SelectFilter = {
|
||||
|
||||
@ -1 +1 @@
|
||||
export const NUMBER_FILTER_TYPES = ['NUMBER', 'CURRENCY'];
|
||||
export const NUMBER_FILTER_TYPES = ['NUMBER', 'CURRENCY', 'PHONES'];
|
||||
|
||||
@ -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',
|
||||
];
|
||||
|
||||
@ -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: {
|
||||
primaryPhoneNumber: {
|
||||
ilike: '%1234567890%',
|
||||
},
|
||||
},
|
||||
{
|
||||
not: {
|
||||
phones: {
|
||||
primaryPhoneCountryCode: {
|
||||
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: '',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -46,7 +46,7 @@ export const getEmptyRecordGqlOperationFilter = (
|
||||
const phonesFilter = generateILikeFiltersForCompositeFields(
|
||||
'',
|
||||
correspondingField.name,
|
||||
['primaryPhoneNumber', 'primaryPhoneCountryCode'],
|
||||
['primaryPhoneNumber'],
|
||||
true,
|
||||
);
|
||||
|
||||
|
||||
@ -324,8 +324,7 @@ export const isRecordMatchingFilter = ({
|
||||
const phonesFilter = filterValue as PhonesFilter;
|
||||
|
||||
const keys: (keyof PhonesFilter)[] = [
|
||||
'primaryPhoneNumber',
|
||||
'primaryPhoneCountryCode',
|
||||
'primaryPhoneNumber'
|
||||
];
|
||||
|
||||
return keys.some((key) => {
|
||||
|
||||
Reference in New Issue
Block a user