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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand",
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=112 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=111 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto",
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
"check-lazy-loading": "ts-node scripts/checkLazyLoading.ts",
"lint-watch": "npx eslint-watch --watch --changed",
Expand Down
8 changes: 5 additions & 3 deletions src/components/Search/FilterDropdowns/UserSelectPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function UserSelectPopup({value, closeOverlay, onChange, isSearchable}: UserSele
const [accountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: accountIDSelector});
const shouldFocusInputOnScreenFocus = canFocusInputOnScreenFocus();
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});
const [searchTerm, setSearchTerm] = useState('');
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true});
Expand Down Expand Up @@ -98,21 +99,22 @@ function UserSelectPopup({value, closeOverlay, onChange, isSearchable}: UserSele
},
draftComments,
nvpDismissedProductTraining,
loginList,
{
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
includeCurrentUser: true,
},
countryCode,
);
}, [options.reports, options.personalDetails, draftComments, nvpDismissedProductTraining, countryCode]);
}, [options.reports, options.personalDetails, draftComments, nvpDismissedProductTraining, loginList, countryCode]);

const filteredOptions = useMemo(() => {
return filterAndOrderOptions(optionsList, cleanSearchTerm, countryCode, {
return filterAndOrderOptions(optionsList, cleanSearchTerm, countryCode, loginList, {
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
canInviteUser: false,
});
}, [optionsList, cleanSearchTerm, countryCode]);
}, [optionsList, cleanSearchTerm, countryCode, loginList]);

const listData = useMemo(() => {
const personalDetailList = filteredOptions.personalDetails.map((participant) => ({
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 @@ -191,6 +191,7 @@ function SearchAutocompleteList({
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {canBeMissing: true});
const [recentSearches] = useOnyx(ONYXKEYS.RECENT_SEARCHES, {canBeMissing: true});
const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});
const expensifyIcons = useMemoizedLazyExpensifyIcons(['History', 'MagnifyingGlass']);

const {options, areOptionsInitialized} = useOptionsList();
Expand All @@ -213,8 +214,9 @@ function SearchAutocompleteList({
countryCode,
shouldShowGBR: false,
shouldUnreadBeBold: true,
loginList,
});
}, [areOptionsInitialized, options, draftComments, nvpDismissedProductTraining, betas, autocompleteQueryValue, countryCode]);
}, [areOptionsInitialized, options, draftComments, nvpDismissedProductTraining, betas, autocompleteQueryValue, countryCode, loginList]);

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

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

Expand Down Expand Up @@ -609,6 +613,7 @@ function SearchAutocompleteList({
nvpDismissedProductTraining,
betas,
countryCode,
loginList,
currentUserLogin,
groupByAutocompleteList,
statusAutocompleteList,
Expand Down
10 changes: 6 additions & 4 deletions src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen

const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});

const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false, canBeMissing: true});
const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportsSelector});
const [selectedReportIDs, setSelectedReportIDs] = useState<string[]>(initialReportIDs);
Expand All @@ -72,15 +74,15 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
if (!areOptionsInitialized || !isScreenTransitionEnd) {
return defaultListOptions;
}
return getSearchOptions({options, draftComments, nvpDismissedProductTraining, betas: undefined, isUsedInChatFinder: false, countryCode});
}, [areOptionsInitialized, draftComments, nvpDismissedProductTraining, isScreenTransitionEnd, options, countryCode]);
return getSearchOptions({options, draftComments, nvpDismissedProductTraining, betas: undefined, isUsedInChatFinder: false, countryCode, loginList});
}, [areOptionsInitialized, isScreenTransitionEnd, options, draftComments, nvpDismissedProductTraining, countryCode, loginList]);

const chatOptions = useMemo(() => {
return filterAndOrderOptions(defaultOptions, cleanSearchTerm, countryCode, {
return filterAndOrderOptions(defaultOptions, cleanSearchTerm, countryCode, loginList, {
selectedOptions,
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
});
}, [defaultOptions, cleanSearchTerm, selectedOptions, countryCode]);
}, [defaultOptions, cleanSearchTerm, countryCode, loginList, selectedOptions]);

const {sections, headerMessage} = useMemo(() => {
const newSections: Section[] = [];
Expand Down
8 changes: 5 additions & 3 deletions src/components/Search/SearchFiltersParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {canBeMissing: false, initWithStoredValues: false});
const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportsSelector});
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});
const [selectedOptions, setSelectedOptions] = useState<OptionData[]>([]);
const [searchTerm, setSearchTerm] = useState('');
const cleanSearchTerm = useMemo(() => searchTerm.trim().toLowerCase(), [searchTerm]);
Expand All @@ -67,20 +68,21 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
},
draftComments,
nvpDismissedProductTraining,
loginList,
{
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
includeCurrentUser: true,
},
countryCode,
);
}, [areOptionsInitialized, draftComments, options.personalDetails, options.reports, nvpDismissedProductTraining, countryCode]);
}, [areOptionsInitialized, options.reports, options.personalDetails, draftComments, nvpDismissedProductTraining, loginList, countryCode]);

const unselectedOptions = useMemo(() => {
return filterSelectedOptions(defaultOptions, new Set(selectedOptions.map((option) => option.accountID)));
}, [defaultOptions, selectedOptions]);

const chatOptions = useMemo(() => {
const filteredOptions = filterAndOrderOptions(unselectedOptions, cleanSearchTerm, countryCode, {
const filteredOptions = filterAndOrderOptions(unselectedOptions, cleanSearchTerm, countryCode, loginList, {
selectedOptions,
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
Expand All @@ -95,7 +97,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
}

return filteredOptions;
}, [unselectedOptions, cleanSearchTerm, selectedOptions, countryCode]);
}, [unselectedOptions, cleanSearchTerm, countryCode, loginList, selectedOptions]);

const {sections, headerMessage} = useMemo(() => {
const newSections: Section[] = [];
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useContactImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ function useContactImport(): UseContactImportResult {
const [contacts, setContacts] = useState<Array<SearchOption<PersonalDetails>>>([]);
const {localeCompare} = useLocalize();
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});

const importAndSaveContacts = useCallback(() => {
contactImport().then(({contactList, permissionStatus}: ContactImportResult) => {
setContactPermissionState(permissionStatus);
const usersFromContact = getContacts(contactList, localeCompare, countryCode);
const usersFromContact = getContacts(contactList, localeCompare, countryCode, loginList);
setContacts(usersFromContact);
});
}, [localeCompare, countryCode]);
}, [localeCompare, countryCode, loginList]);

useContactPermissions({
importAndSaveContacts,
Expand Down
12 changes: 8 additions & 4 deletions src/hooks/useSearchSelector.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function useSearchSelectorBase({
const [selectedOptions, setSelectedOptions] = useState<OptionData[]>(initialSelected ?? []);
const [maxResults, setMaxResults] = useState(maxResultsPerPage);
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true});
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {canBeMissing: true});

Expand Down Expand Up @@ -193,9 +194,10 @@ function useSearchSelectorBase({
maxResults,
includeUserToInvite,
countryCode,
loginList,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_MEMBER_INVITE:
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, {
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, loginList, {
betas: betas ?? [],
includeP2P: true,
includeSelectedOptions: false,
Expand All @@ -207,7 +209,7 @@ function useSearchSelectorBase({
includeUserToInvite,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_GENERAL:
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, {
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, loginList, {
...getValidOptionsConfig,
betas: betas ?? [],
searchString: computedSearchTerm,
Expand All @@ -221,6 +223,7 @@ function useSearchSelectorBase({
optionsWithContacts,
draftComments,
nvpDismissedProductTraining,
loginList,
{
betas,
includeMultipleParticipantReports: true,
Expand All @@ -237,7 +240,7 @@ function useSearchSelectorBase({
countryCode,
);
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_SHARE_DESTINATION:
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, {
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, loginList, {
betas,
selectedOptions,
includeMultipleParticipantReports: true,
Expand All @@ -255,7 +258,7 @@ function useSearchSelectorBase({
includeUserToInvite,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_ATTENDEES:
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, {
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, loginList, {
...getValidOptionsConfig,
betas: betas ?? [],
includeP2P: true,
Expand Down Expand Up @@ -283,6 +286,7 @@ function useSearchSelectorBase({
maxResults,
includeUserToInvite,
countryCode,
loginList,
excludeLogins,
includeRecentReports,
maxRecentReportsToShow,
Expand Down
11 changes: 9 additions & 2 deletions src/libs/ContactUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import CONST from '@src/CONST';
import type {PersonalDetails} from '@src/types/onyx';
import type {Login, PersonalDetails} from '@src/types/onyx';
import type {DeviceContact, StringHolder} from './ContactImport/types';
import {getUserToInviteContactOption} from './OptionsListUtils';
import type {SearchOption} from './OptionsListUtils';
Expand Down Expand Up @@ -28,7 +29,12 @@ function sortEmailObjects(emails: StringHolder[], localeCompare: LocaleContextPr
});
}

const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: LocaleContextProps['localeCompare'], countryCode: number): Array<SearchOption<PersonalDetails>> => {
const getContacts = (
deviceContacts: DeviceContact[] | [],
localeCompare: LocaleContextProps['localeCompare'],
countryCode: number,
loginList: OnyxEntry<Login>,
): Array<SearchOption<PersonalDetails>> => {
return deviceContacts
.map((contact) => {
const email = sortEmailObjects(contact?.emailAddresses ?? [], localeCompare)?.at(0) ?? '';
Expand All @@ -48,6 +54,7 @@ const getContacts = (deviceContacts: DeviceContact[] | [], localeCompare: Locale
phone: phoneNumber,
avatar: avatarSource,
countryCode,
loginList,
});
})
.filter((contact): contact is SearchOption<PersonalDetails> => contact !== null);
Expand Down
Loading
Loading