Skip to content

Commit

Permalink
Merge pull request #15594 from narefyev91/fix-phone-search
Browse files Browse the repository at this point in the history
Allow searching for phone numbers with parenthesis, spaces and dashes in them
  • Loading branch information
puneetlath authored Mar 6, 2023
2 parents 63d5a7e + 8690bd7 commit ace7d0a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ const CONST = {
US_PHONE_WITH_OPTIONAL_COUNTRY_CODE: /^(\+1)?\d{10}$/,
DIGITS_AND_PLUS: /^\+?[0-9]*$/,
PHONE_E164_PLUS: /^\+?[1-9]\d{1,14}$/,
PHONE_WITH_SPECIAL_CHARS: /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\\./0-9]{0,12}$/,
PHONE_WITH_SPECIAL_CHARS: /^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/,
ALPHABETIC_CHARS: /[a-zA-Z]+/,
POSITIVE_INTEGER: /^\d+$/,
NON_ALPHA_NUMERIC: /[^A-Za-z0-9+]/g,
Expand All @@ -821,6 +821,7 @@ const CONST = {
EMOJIS: /[\p{Extended_Pictographic}\u200d\u{1f1e6}-\u{1f1ff}\u{1f3fb}-\u{1f3ff}\u{e0020}-\u{e007f}\u20E3\uFE0F]|[#*0-9]\uFE0F?\u20E3/gu,
TAX_ID: /^\d{9}$/,
NON_NUMERIC: /\D/g,
NON_NUMERIC_WITH_PLUS: /[^0-9+]/g,
EMOJI_NAME: /:[\w+-]+:/g,
EMOJI_SUGGESTIONS: /:[a-zA-Z0-9_+-]{1,40}$/,
AFTER_FIRST_LINE_BREAK: /\n.*/g,
Expand Down
10 changes: 6 additions & 4 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,16 @@ function getOptions(reports, personalDetails, {

// When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well.
sortByReportTypeInSearch = false,
searchValue = '',
searchInputValue = '',
showChatPreviewLine = false,
sortPersonalDetailsByAlphaAsc = true,
forcePolicyNamePreview = false,
}) {
let recentReportOptions = [];
let personalDetailsOptions = [];
const reportMapForLogins = {};
const isPhoneNumber = CONST.REGEX.PHONE_WITH_SPECIAL_CHARS.test(searchInputValue);
const searchValue = isPhoneNumber ? searchInputValue.replace(CONST.REGEX.NON_NUMERIC_WITH_PLUS, '') : searchInputValue;

// Filter out all the reports that shouldn't be displayed
const filteredReports = _.filter(reports, report => ReportUtils.shouldReportBeInOptionList(
Expand Down Expand Up @@ -645,7 +647,7 @@ function getSearchOptions(
) {
return getOptions(reports, personalDetails, {
betas,
searchValue: searchValue.trim(),
searchInputValue: searchValue.trim(),
includeRecentReports: true,
includeMultipleParticipantReports: true,
maxRecentReportsToShow: 0, // Unlimited
Expand Down Expand Up @@ -713,7 +715,7 @@ function getNewChatOptions(
) {
return getOptions(reports, personalDetails, {
betas,
searchValue: searchValue.trim(),
searchInputValue: searchValue.trim(),
selectedOptions,
excludeChatRooms: true,
includeRecentReports: true,
Expand All @@ -740,7 +742,7 @@ function getMemberInviteOptions(
) {
return getOptions([], personalDetails, {
betas,
searchValue: searchValue.trim(),
searchInputValue: searchValue.trim(),
excludeDefaultRooms: true,
includePersonalDetails: true,
excludeLogins,
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,17 @@ describe('OptionsListUtils', () => {
expect(results.userToInvite).not.toBe(null);
expect(results.userToInvite.login).toBe('+15005550006');

// When we add a search term for which no options exist and the searchValue itself
// is a potential phone number with special characters added
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '+1 (800)324-3233');

// Then we should have no options or personal details at all but there should be a userToInvite and the login
// should have the country code included
expect(results.recentReports.length).toBe(0);
expect(results.personalDetails.length).toBe(0);
expect(results.userToInvite).not.toBe(null);
expect(results.userToInvite.login).toBe('+18003243233');

// Test Concierge's existence in new group options
results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE);

Expand Down

0 comments on commit ace7d0a

Please sign in to comment.