Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/components/Search/FilterDropdowns/UserSelectPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ function UserSelectPopup({value, closeOverlay, onChange}: UserSelectPopupProps)
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
includeCurrentUser: true,
},
countryCode,
);
}, [options.reports, options.personalDetails, draftComments]);
}, [options.reports, options.personalDetails, draftComments, countryCode]);

const filteredOptions = useMemo(() => {
return filterAndOrderOptions(optionsList, cleanSearchTerm, countryCode, {
Expand Down
7 changes: 6 additions & 1 deletion src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function SearchAutocompleteList({
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true});
const [recentSearches] = useOnyx(ONYXKEYS.RECENT_SEARCHES, {canBeMissing: true});
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const taxRates = getAllTaxRates();

const {options, areOptionsInitialized} = useOptionsList();
Expand All @@ -199,9 +200,10 @@ function SearchAutocompleteList({
includeUserToInvite: true,
includeRecentReports: true,
includeCurrentUser: true,
countryCode,
shouldShowGBR: false,
});
}, [areOptionsInitialized, options, draftComments, betas, autocompleteQueryValue]);
}, [areOptionsInitialized, options, draftComments, betas, autocompleteQueryValue, countryCode]);

const [isInitialRender, setIsInitialRender] = useState(true);
const parsedQuery = parseForAutocomplete(autocompleteQueryValue);
Expand Down Expand Up @@ -402,6 +404,7 @@ function SearchAutocompleteList({
includeUserToInvite: false,
includeRecentReports: false,
includeCurrentUser: true,
countryCode,
shouldShowGBR: true,
}).personalDetails.filter((participant) => participant.text && !alreadyAutocompletedKeys.includes(participant.text.toLowerCase()));

Expand All @@ -424,6 +427,7 @@ function SearchAutocompleteList({
includeUserToInvite: false,
includeRecentReports: true,
includeCurrentUser: false,
countryCode,
shouldShowGBR: true,
}).recentReports;

Expand Down Expand Up @@ -584,6 +588,7 @@ function SearchAutocompleteList({
options,
draftComments,
betas,
countryCode,
currentUserLogin,
typeAutocompleteList,
groupByAutocompleteList,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
if (!areOptionsInitialized || !isScreenTransitionEnd) {
return defaultListOptions;
}
return getSearchOptions({options, draftComments, betas: undefined, isUsedInChatFinder: false});
}, [areOptionsInitialized, draftComments, isScreenTransitionEnd, options]);
return getSearchOptions({options, draftComments, betas: undefined, isUsedInChatFinder: false, countryCode});
}, [areOptionsInitialized, draftComments, isScreenTransitionEnd, options, countryCode]);

const chatOptions = useMemo(() => {
return filterAndOrderOptions(defaultOptions, cleanSearchTerm, countryCode, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
includeCurrentUser: true,
},
countryCode,
);
}, [areOptionsInitialized, draftComments, options.personalDetails, options.reports]);
}, [areOptionsInitialized, draftComments, options.personalDetails, options.reports, countryCode]);

const unselectedOptions = useMemo(() => {
return filterSelectedOptions(defaultOptions, new Set(selectedOptions.map((option) => option.accountID)));
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useSearchSelector.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function useSearchSelectorBase({
searchQuery: computedSearchTerm,
maxResults,
includeUserToInvite,
countryCode,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_MEMBER_INVITE:
return getValidOptions(optionsWithContacts, draftComments, {
Expand Down Expand Up @@ -232,6 +233,7 @@ function useSearchSelectorBase({
computedSearchTerm,
maxResults,
includeUserToInvite,
countryCode,
excludeLogins,
includeRecentReports,
maxRecentReportsToShow,
Expand Down
200 changes: 130 additions & 70 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1370,12 +1370,13 @@ function getUserToInviteOption({
selectedOptions = [],
showChatPreviewLine = false,
shouldAcceptName = false,
countryCode = CONST.DEFAULT_COUNTRY_CODE,
}: GetUserToInviteConfig): SearchOptionData | null {
if (!searchValue) {
return null;
}

const parsedPhoneNumber = parsePhoneNumber(appendCountryCode(Str.removeSMSDomain(searchValue)));
const parsedPhoneNumber = parsePhoneNumber(appendCountryCodeWithCountryCode(Str.removeSMSDomain(searchValue), countryCode));
const isCurrentUserLogin = isCurrentUser({login: searchValue} as PersonalDetails);
const isInSelectedOption = selectedOptions.some((option) => 'login' in option && option.login === searchValue);
const isValidEmail = Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue) && !Str.endsWith(searchValue, CONST.SMS.DOMAIN);
Expand Down Expand Up @@ -1783,6 +1784,7 @@ function getValidOptions(
maxRecentReportElements = undefined,
...config
}: GetOptionsConfig = {},
countryCode: number = CONST.DEFAULT_COUNTRY_CODE,
): Options {
const restrictedLogins = getRestrictedLogins(config, options, canShowManagerMcTest);

Expand Down Expand Up @@ -1932,9 +1934,14 @@ function getValidOptions(

let userToInvite: SearchOptionData | null = null;
if (includeUserToInvite) {
userToInvite = filterUserToInvite({currentUserOption: currentUserRef.current, recentReports: recentReportOptions, personalDetails: personalDetailsOptions}, searchString ?? '', {
excludeLogins: loginsToExclude,
});
userToInvite = filterUserToInvite(
{currentUserOption: currentUserRef.current, recentReports: recentReportOptions, personalDetails: personalDetailsOptions},
searchString ?? '',
countryCode,
{
excludeLogins: loginsToExclude,
},
);
}

return {
Expand All @@ -1958,6 +1965,7 @@ type SearchOptionsConfig = {
includeUserToInvite?: boolean;
includeRecentReports?: boolean;
includeCurrentUser?: boolean;
countryCode?: number;
shouldShowGBR?: boolean;
};

Expand All @@ -1975,52 +1983,71 @@ function getSearchOptions({
includeUserToInvite,
includeRecentReports = true,
includeCurrentUser = false,
countryCode = CONST.DEFAULT_COUNTRY_CODE,
shouldShowGBR = false,
}: SearchOptionsConfig): Options {
Timing.start(CONST.TIMING.LOAD_SEARCH_OPTIONS);
Performance.markStart(CONST.TIMING.LOAD_SEARCH_OPTIONS);

const optionList = getValidOptions(options, draftComments, {
betas,
includeRecentReports,
includeMultipleParticipantReports: true,
showChatPreviewLine: isUsedInChatFinder,
includeP2P: true,
includeOwnedWorkspaceChats: true,
includeThreads: true,
includeMoneyRequests: true,
includeTasks: true,
includeReadOnly,
includeSelfDM: true,
shouldBoldTitleByDefault: !isUsedInChatFinder,
excludeHiddenThreads: true,
maxElements: maxResults,
includeCurrentUser,
searchString: searchQuery,
includeUserToInvite,
shouldShowGBR,
});
const optionList = getValidOptions(
options,
draftComments,
{
betas,
includeRecentReports,
includeMultipleParticipantReports: true,
showChatPreviewLine: isUsedInChatFinder,
includeP2P: true,
includeOwnedWorkspaceChats: true,
includeThreads: true,
includeMoneyRequests: true,
includeTasks: true,
includeReadOnly,
includeSelfDM: true,
shouldBoldTitleByDefault: !isUsedInChatFinder,
excludeHiddenThreads: true,
maxElements: maxResults,
includeCurrentUser,
searchString: searchQuery,
includeUserToInvite,
shouldShowGBR,
},
countryCode,
);

Timing.end(CONST.TIMING.LOAD_SEARCH_OPTIONS);
Performance.markEnd(CONST.TIMING.LOAD_SEARCH_OPTIONS);

return optionList;
}

function getShareLogOptions(options: OptionList, draftComments: OnyxCollection<string>, betas: Beta[] = [], searchString = '', maxElements?: number, includeUserToInvite = false): Options {
return getValidOptions(options, draftComments, {
betas,
includeMultipleParticipantReports: true,
includeP2P: true,
forcePolicyNamePreview: true,
includeOwnedWorkspaceChats: true,
includeSelfDM: true,
includeThreads: true,
includeReadOnly: false,
searchString,
maxElements,
includeUserToInvite,
});
function getShareLogOptions(
options: OptionList,
draftComments: OnyxCollection<string>,
betas: Beta[] = [],
searchString = '',
maxElements?: number,
includeUserToInvite = false,
countryCode: number = CONST.DEFAULT_COUNTRY_CODE,
): Options {
return getValidOptions(
options,
draftComments,
{
betas,
includeMultipleParticipantReports: true,
includeP2P: true,
forcePolicyNamePreview: true,
includeOwnedWorkspaceChats: true,
includeSelfDM: true,
includeThreads: true,
includeReadOnly: false,
searchString,
maxElements,
includeUserToInvite,
},
countryCode,
);
}

/**
Expand All @@ -2047,18 +2074,33 @@ function getIOUConfirmationOptionsFromPayeePersonalDetail(personalDetail: OnyxEn
};
}

function getAttendeeOptions(
reports: Array<SearchOption<Report>>,
personalDetails: Array<SearchOption<PersonalDetails>>,
betas: OnyxEntry<Beta[]>,
attendees: Attendee[],
recentAttendees: Attendee[],
draftComments: OnyxCollection<string>,
type GetAttendeeOptionsParams = {
reports: Array<SearchOption<Report>>;
personalDetails: Array<SearchOption<PersonalDetails>>;
betas: OnyxEntry<Beta[]>;
attendees: Attendee[];
recentAttendees: Attendee[];
draftComments: OnyxCollection<string>;
includeOwnedWorkspaceChats: boolean;
includeP2P: boolean;
includeInvoiceRooms: boolean;
action: IOUAction | undefined;
countryCode: number;
};

function getAttendeeOptions({
reports,
personalDetails,
betas,
attendees,
recentAttendees,
draftComments,
includeOwnedWorkspaceChats = false,
includeP2P = true,
includeInvoiceRooms = false,
action: IOUAction | undefined = undefined,
) {
action = undefined,
countryCode = CONST.DEFAULT_COUNTRY_CODE,
}: GetAttendeeOptionsParams) {
const personalDetailList = keyBy(
personalDetails.map(({item}) => item),
'accountID',
Expand Down Expand Up @@ -2087,19 +2129,24 @@ function getAttendeeOptions(
}))
.map((attendee) => getParticipantsOption(attendee, personalDetailList as never));

return getValidOptions({reports, personalDetails}, draftComments, {
betas,
selectedOptions: attendees.map((attendee) => ({...attendee, login: attendee.email})),
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
includeOwnedWorkspaceChats,
includeRecentReports: false,
includeP2P,
includeSelectedOptions: false,
includeSelfDM: false,
includeInvoiceRooms,
action,
recentAttendees: filteredRecentAttendees,
});
return getValidOptions(
{reports, personalDetails},
draftComments,
{
betas,
selectedOptions: attendees.map((attendee) => ({...attendee, login: attendee.email})),
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
includeOwnedWorkspaceChats,
includeRecentReports: false,
includeP2P,
includeSelectedOptions: false,
includeSelfDM: false,
includeInvoiceRooms,
action,
recentAttendees: filteredRecentAttendees,
},
countryCode,
);
}

/**
Expand Down Expand Up @@ -2137,16 +2184,22 @@ function getMemberInviteOptions(
betas: Beta[] = [],
excludeLogins: Record<string, boolean> = {},
includeSelectedOptions = false,
countryCode: number = CONST.DEFAULT_COUNTRY_CODE,
): Options {
return getValidOptions({personalDetails, reports: []}, undefined, {
betas,
includeP2P: true,
excludeLogins,
includeSelectedOptions,
includeRecentReports: false,
searchString: '',
maxElements: undefined,
});
return getValidOptions(
{personalDetails, reports: []},
undefined,
{
betas,
includeP2P: true,
excludeLogins,
includeSelectedOptions,
includeRecentReports: false,
searchString: '',
maxElements: undefined,
},
countryCode,
);
}

/**
Expand Down Expand Up @@ -2365,7 +2418,12 @@ function filterCurrentUserOption(currentUserOption: SearchOptionData | null | un
}, currentUserOption);
}

function filterUserToInvite(options: Omit<Options, 'userToInvite'>, searchValue: string, config?: FilterUserToInviteConfig): SearchOptionData | null {
function filterUserToInvite(
options: Omit<Options, 'userToInvite'>,
searchValue: string,
countryCode: number = CONST.DEFAULT_COUNTRY_CODE,
config?: FilterUserToInviteConfig,
): SearchOptionData | null {
const {canInviteUser = true, excludeLogins = {}} = config ?? {};
if (!canInviteUser) {
return null;
Expand All @@ -2389,6 +2447,7 @@ function filterUserToInvite(options: Omit<Options, 'userToInvite'>, searchValue:
return getUserToInviteOption({
searchValue,
loginsToExclude,
countryCode,
...config,
});
}
Expand Down Expand Up @@ -2437,6 +2496,7 @@ function filterOptions(options: Options, searchInputValue: string, countryCode:
currentUserOption,
},
searchValue,
countryCode,
config,
);
const workspaceChats = filterWorkspaceChats(options.workspaceChats ?? [], searchTerms);
Expand Down
1 change: 1 addition & 0 deletions src/libs/OptionsListUtils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ type GetUserToInviteConfig = {
avatar?: AvatarSource;
shouldAcceptName?: boolean;
optionsToExclude?: GetOptionsConfig['selectedOptions'];
countryCode?: number;
} & Pick<GetOptionsConfig, 'selectedOptions' | 'showChatPreviewLine'>;

type MemberForList = {
Expand Down
Loading
Loading