Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing phone search functionality #9466

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading