Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {accountIDSelector} from '@selectors/Session';
import {deepEqual} from 'fast-equals';
import React, {useMemo, useRef} from 'react';
import useCurrentReportID from '@hooks/useCurrentReportID';
Expand Down Expand Up @@ -50,6 +51,7 @@ function OptionRowLHNData({

const [movedFromReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(lastAction, CONST.REPORT.MOVE_TYPE.FROM)}`, {canBeMissing: true});
const [movedToReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(lastAction, CONST.REPORT.MOVE_TYPE.TO)}`, {canBeMissing: true});
const [currentUserAccountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: accountIDSelector});
// Check the report errors equality to avoid re-rendering when there are no changes
const prevReportErrors = usePrevious(reportAttributes?.reportErrors);
const areReportErrorsEqual = useMemo(() => deepEqual(prevReportErrors, reportAttributes?.reportErrors), [prevReportErrors, reportAttributes?.reportErrors]);
Expand All @@ -76,6 +78,7 @@ function OptionRowLHNData({
lastActionReport,
movedFromReport,
movedToReport,
currentUserAccountID,
});
// eslint-disable-next-line react-compiler/react-compiler
if (deepEqual(item, optionItemRef.current)) {
Expand Down Expand Up @@ -114,6 +117,7 @@ function OptionRowLHNData({
isReportArchived,
movedFromReport,
movedToReport,
currentUserAccountID,
]);

return (
Expand Down
19 changes: 13 additions & 6 deletions src/components/Search/FilterDropdowns/UserSelectPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,19 @@ function UserSelectPopup({value, closeOverlay, onChange, isSearchable}: UserSele
}, [options.reports, options.personalDetails, draftComments, nvpDismissedProductTraining, loginList, countryCode]);

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

const listData = useMemo(() => {
const personalDetailList = filteredOptions.personalDetails.map((participant) => ({
Expand Down
12 changes: 9 additions & 3 deletions src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@
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 [currentUserLogin] = useOnyx(ONYXKEYS.SESSION, {selector: emailSelector, canBeMissing: false});
const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector, canBeMissing: false});
const expensifyIcons = useMemoizedLazyExpensifyIcons(['History', 'MagnifyingGlass']);

const {options, areOptionsInitialized} = useOptionsList();
Expand All @@ -215,8 +217,10 @@
shouldShowGBR: false,
shouldUnreadBeBold: true,
loginList,
currentUserAccountID,
currentUserEmail: currentUserLogin,
});
}, [areOptionsInitialized, options, draftComments, nvpDismissedProductTraining, betas, autocompleteQueryValue, countryCode, loginList]);
}, [areOptionsInitialized, options, draftComments, nvpDismissedProductTraining, betas, autocompleteQueryValue, countryCode, loginList, currentUserAccountID, currentUserLogin]);

const [isInitialRender, setIsInitialRender] = useState(true);
const parsedQuery = useMemo(() => parseForAutocomplete(autocompleteQueryValue), [autocompleteQueryValue]);
Expand Down Expand Up @@ -290,8 +294,6 @@
}, [allRecentCategories]);

const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false});
const [currentUserLogin] = useOnyx(ONYXKEYS.SESSION, {selector: emailSelector, canBeMissing: false});
const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector, canBeMissing: false});

const taxRates = useMemo(() => getAllTaxRates(policies), [policies]);

Expand Down Expand Up @@ -425,6 +427,8 @@
countryCode,
loginList,
shouldShowGBR: true,
currentUserAccountID,
currentUserEmail: currentUserLogin,
}).personalDetails.filter((participant) => participant.text && !alreadyAutocompletedKeys.has(participant.text.toLowerCase()));

return participants.map((participant) => ({
Expand Down Expand Up @@ -456,6 +460,8 @@
countryCode,
loginList,
shouldShowGBR: true,
currentUserAccountID,
currentUserEmail: currentUserLogin,
}).recentReports.filter((chat) => {
if (!chat.text) {
return false;
Expand Down Expand Up @@ -609,7 +615,7 @@
return [];
}
}
}, [

Check warning on line 618 in src/components/Search/SearchAutocompleteList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has a missing dependency: 'currentUserAccountID'. Either include it or remove the dependency array

Check warning on line 618 in src/components/Search/SearchAutocompleteList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useMemo has a missing dependency: 'currentUserAccountID'. Either include it or remove the dependency array
autocompleteParsedQuery,
autocompleteQueryValue,
tagAutocompleteList,
Expand Down
37 changes: 30 additions & 7 deletions src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import reportsSelector from '@selectors/Attributes';
import {accountIDSelector, emailSelector} from '@selectors/Session';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import {useOptionsList} from '@components/OptionListContextProvider';
Expand Down Expand Up @@ -51,6 +52,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 [currentUserAccountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: accountIDSelector});
const [currentUserEmail] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: emailSelector});

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

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

const {sections, headerMessage} = useMemo(() => {
const newSections: Section[] = [];
Expand All @@ -99,6 +120,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
false,
undefined,
reportAttributesDerived,
currentUserAccountID,
);

newSections.push(formattedResults.section);
Expand Down Expand Up @@ -131,6 +153,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
selectedOptions,
selectedReportIDs,
translate,
currentUserAccountID,
]);

useEffect(() => {
Expand Down
32 changes: 23 additions & 9 deletions src/components/Search/SearchFiltersParticipantsSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import reportsSelector from '@selectors/Attributes';
import {accountIDSelector, emailSelector} from '@selectors/Session';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import {useOptionsList} from '@components/OptionListContextProvider';
Expand Down Expand Up @@ -51,6 +52,8 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
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 [currentUserAccountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: accountIDSelector});
const [currentUserEmail] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: emailSelector});
const [selectedOptions, setSelectedOptions] = useState<OptionData[]>([]);
const [searchTerm, setSearchTerm] = useState('');
const cleanSearchTerm = useMemo(() => searchTerm.trim().toLowerCase(), [searchTerm]);
Expand All @@ -72,22 +75,32 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
{
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
includeCurrentUser: true,
currentUserAccountID,
currentUserEmail,
},
countryCode,
);
}, [areOptionsInitialized, options.reports, options.personalDetails, draftComments, nvpDismissedProductTraining, loginList, countryCode]);
}, [areOptionsInitialized, options.reports, options.personalDetails, draftComments, nvpDismissedProductTraining, loginList, countryCode, currentUserAccountID, currentUserEmail]);

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

const chatOptions = useMemo(() => {
const filteredOptions = filterAndOrderOptions(unselectedOptions, cleanSearchTerm, countryCode, loginList, {
selectedOptions,
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
canInviteUser: false,
});
const filteredOptions = filterAndOrderOptions(
unselectedOptions,
cleanSearchTerm,
countryCode,
loginList,
{
selectedOptions,
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
canInviteUser: false,
currentUserEmail,
},
currentUserAccountID,
);

const {currentUserOption} = unselectedOptions;

Expand All @@ -97,7 +110,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
}

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

const {sections, headerMessage} = useMemo(() => {
const newSections: Section[] = [];
Expand All @@ -114,6 +127,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
true,
undefined,
reportAttributesDerived,
currentUserAccountID,
);

const selectedCurrentUser = formattedResults.section.data.find((option) => option.accountID === chatOptions.currentUserOption?.accountID);
Expand Down Expand Up @@ -162,7 +176,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
sections: newSections,
headerMessage: message,
};
}, [areOptionsInitialized, cleanSearchTerm, selectedOptions, chatOptions, personalDetails, reportAttributesDerived, translate, formatPhoneNumber]);
}, [areOptionsInitialized, cleanSearchTerm, selectedOptions, chatOptions, personalDetails, reportAttributesDerived, translate, formatPhoneNumber, currentUserAccountID]);

const resetChanges = useCallback(() => {
setSelectedOptions([]);
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/useContactImport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {emailSelector} from '@selectors/Session';
import {useCallback, useState} from 'react';
import {RESULTS} from 'react-native-permissions';
import type {PermissionStatus} from 'react-native-permissions';
Expand Down Expand Up @@ -33,14 +34,15 @@ function useContactImport(): UseContactImportResult {
const {localeCompare} = useLocalize();
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});
const [currentUserEmail] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: emailSelector});

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

useContactPermissions({
importAndSaveContacts,
Expand Down
17 changes: 17 additions & 0 deletions src/hooks/useSearchSelector.base.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {accountIDSelector, emailSelector} from '@selectors/Session';
import {useCallback, useMemo, useState} from 'react';
import type {PermissionStatus} from 'react-native-permissions';
import {useOptionsList} from '@components/OptionListContextProvider';
Expand Down Expand Up @@ -164,6 +165,8 @@ function useSearchSelectorBase({
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});
const [currentUserAccountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: accountIDSelector});
const [currentUserEmail] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: emailSelector});

const onListEndReached = useDebounce(
useCallback(() => {
Expand Down Expand Up @@ -195,6 +198,8 @@ function useSearchSelectorBase({
includeUserToInvite,
countryCode,
loginList,
currentUserAccountID,
currentUserEmail,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_MEMBER_INVITE:
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, loginList, {
Expand All @@ -207,6 +212,8 @@ function useSearchSelectorBase({
maxRecentReportElements: maxRecentReportsToShow,
searchString: computedSearchTerm,
includeUserToInvite,
currentUserAccountID,
currentUserEmail,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_GENERAL:
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, loginList, {
Expand All @@ -217,6 +224,8 @@ function useSearchSelectorBase({
maxRecentReportElements: maxRecentReportsToShow,
includeUserToInvite,
excludeLogins,
currentUserAccountID,
currentUserEmail,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_SHARE_LOG:
return getValidOptions(
Expand All @@ -236,6 +245,8 @@ function useSearchSelectorBase({
searchString: computedSearchTerm,
maxElements: maxResults,
includeUserToInvite,
currentUserAccountID,
currentUserEmail,
},
countryCode,
);
Expand All @@ -256,6 +267,8 @@ function useSearchSelectorBase({
searchString: computedSearchTerm,
maxElements: maxResults,
includeUserToInvite,
currentUserAccountID,
currentUserEmail,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_ATTENDEES:
return getValidOptions(optionsWithContacts, draftComments, nvpDismissedProductTraining, loginList, {
Expand All @@ -271,6 +284,8 @@ function useSearchSelectorBase({
searchString: computedSearchTerm,
includeUserToInvite,
includeCurrentUser,
currentUserAccountID,
currentUserEmail,
});
default:
return getEmptyOptions();
Expand All @@ -293,6 +308,8 @@ function useSearchSelectorBase({
getValidOptionsConfig,
selectedOptions,
includeCurrentUser,
currentUserAccountID,
currentUserEmail,
]);

const isOptionSelected = useMemo(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/libs/ContactUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const getContacts = (
localeCompare: LocaleContextProps['localeCompare'],
countryCode: number,
loginList: OnyxEntry<Login>,
currentUserEmail?: string,
): Array<SearchOption<PersonalDetails>> => {
return deviceContacts
.map((contact) => {
Expand All @@ -55,6 +56,7 @@ const getContacts = (
avatar: avatarSource,
countryCode,
loginList,
currentUserEmail,
});
})
.filter((contact): contact is SearchOption<PersonalDetails> => contact !== null);
Expand Down
Loading
Loading