Skip to content

Commit

Permalink
Fixing phone search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
muraliSingh7 committed Jan 8, 2025
1 parent 27b58e9 commit 23c4d7d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export type EmailsFilter = {

export type PhonesFilter = {
primaryPhoneNumber?: StringFilter;
primaryPhoneCountryCode?: StringFilter;
};

export type SelectFilter = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const NUMBER_FILTER_TYPES = ['NUMBER', 'CURRENCY'];
export const NUMBER_FILTER_TYPES = ['NUMBER', 'CURRENCY', 'PHONE', 'PHONES'];
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ export const TEXT_FILTER_TYPES = [
'TEXT',
'EMAIL',
'EMAILS',
'PHONE',
'FULL_NAME',
'LINK',
'LINKS',
'ADDRESS',
'ACTOR',
'ARRAY',
'RAW_JSON',
'PHONES',
];
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -639,24 +619,6 @@ describe('should work as expected for the different field types', () => {
},
],
},
{
or: [
{
phones: {
primaryPhoneCountryCode: {
is: 'NULL',
},
},
},
{
phones: {
primaryPhoneCountryCode: {
ilike: '',
},
},
},
],
},
],
},
{
Expand All @@ -680,24 +642,6 @@ describe('should work as expected for the different field types', () => {
},
],
},
{
or: [
{
phones: {
primaryPhoneCountryCode: {
is: 'NULL',
},
},
},
{
phones: {
primaryPhoneCountryCode: {
ilike: '',
},
},
},
],
},
],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EmailsFilter,
FloatFilter,
MultiSelectFilter,
PhonesFilter,
RatingFilter,
RawJsonFilter,
RecordGqlOperationFilter,
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const getEmptyRecordGqlOperationFilter = (
const phonesFilter = generateILikeFiltersForCompositeFields(
'',
correspondingField.name,
['primaryPhoneNumber', 'primaryPhoneCountryCode'],
['primaryPhoneNumber'],
true,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ export const isRecordMatchingFilter = ({
const phonesFilter = filterValue as PhonesFilter;

const keys: (keyof PhonesFilter)[] = [
'primaryPhoneNumber',
'primaryPhoneCountryCode',
'primaryPhoneNumber'
];

return keys.some((key) => {
Expand Down

0 comments on commit 23c4d7d

Please sign in to comment.