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 @@ -105,10 +105,11 @@ function UserSelectPopup({value, closeOverlay, onChange, isSearchable}: UserSele
{
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
includeCurrentUser: true,
personalDetails,
},
countryCode,
);
}, [options.reports, options.personalDetails, allPolicies, draftComments, nvpDismissedProductTraining, loginList, countryCode]);
}, [options.reports, options.personalDetails, allPolicies, draftComments, nvpDismissedProductTraining, loginList, countryCode, personalDetails]);

const filteredOptions = useMemo(() => {
return filterAndOrderOptions(optionsList, cleanSearchTerm, countryCode, loginList, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
{
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
includeCurrentUser: true,
personalDetails,
},
countryCode,
);
}, [areOptionsInitialized, options.reports, options.personalDetails, allPolicies, draftComments, nvpDismissedProductTraining, loginList, countryCode]);
}, [areOptionsInitialized, options.reports, options.personalDetails, allPolicies, draftComments, nvpDismissedProductTraining, loginList, countryCode, personalDetails]);

const unselectedOptions = useMemo(() => {
return filterSelectedOptions(defaultOptions, new Set(selectedOptions.map((option) => option.accountID)));
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/useSearchSelector.base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {useCallback, useMemo, useState} from 'react';
import type {PermissionStatus} from 'react-native-permissions';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import {useOptionsList} from '@components/OptionListContextProvider';
import type {GetOptionsConfig, Options, SearchOption} from '@libs/OptionsListUtils';
import {getEmptyOptions, getSearchOptions, getSearchValueForPhoneOrEmail, getValidOptions} from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -165,6 +166,7 @@ function useSearchSelectorBase({
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true});
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {canBeMissing: true});
const personalDetails = usePersonalDetails();

const onListEndReached = useDebounce(
useCallback(() => {
Expand Down Expand Up @@ -208,6 +210,7 @@ function useSearchSelectorBase({
maxRecentReportElements: maxRecentReportsToShow,
searchString: computedSearchTerm,
includeUserToInvite,
personalDetails,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_GENERAL:
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, {
Expand All @@ -218,6 +221,7 @@ function useSearchSelectorBase({
maxRecentReportElements: maxRecentReportsToShow,
includeUserToInvite,
excludeLogins,
personalDetails,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_SHARE_LOG:
return getValidOptions(
Expand All @@ -238,6 +242,7 @@ function useSearchSelectorBase({
searchString: computedSearchTerm,
maxElements: maxResults,
includeUserToInvite,
personalDetails,
},
countryCode,
);
Expand All @@ -258,6 +263,7 @@ function useSearchSelectorBase({
searchString: computedSearchTerm,
maxElements: maxResults,
includeUserToInvite,
personalDetails,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_ATTENDEES:
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, {
Expand All @@ -274,6 +280,7 @@ function useSearchSelectorBase({
includeUserToInvite,
includeCurrentUser,
shouldAcceptName: true,
personalDetails,
});
default:
return getEmptyOptions();
Expand All @@ -296,6 +303,7 @@ function useSearchSelectorBase({
getValidOptionsConfig,
selectedOptions,
includeCurrentUser,
personalDetails,
]);

const isOptionSelected = useMemo(() => {
Expand Down
8 changes: 7 additions & 1 deletion src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
*/
let currentUserLogin: string | undefined;
let currentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 199 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserLogin = value?.email;
Expand All @@ -205,13 +205,13 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 208 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => (allPersonalDetails = isEmptyObject(value) ? {} : value),
});

const policies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 214 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
callback: (policy, key) => {
if (!policy || !key || !policy.name) {
Expand All @@ -223,14 +223,14 @@
});

let allPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 226 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (val) => (allPolicies = val),
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 233 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -239,7 +239,7 @@
});

let allReportNameValuePairsOnyxConnect: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({

Check warning on line 242 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -251,7 +251,7 @@
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
const lastVisibleReportActions: ReportActions = {};
Onyx.connect({

Check warning on line 254 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -313,7 +313,7 @@
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 316 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});
Expand Down Expand Up @@ -2014,6 +2014,7 @@
showRBR = true,
shouldShowGBR = false,
shouldUnreadBeBold = false,
personalDetails,
} = config;

const validOptions: Array<SearchOption<Report>> = [];
Expand Down Expand Up @@ -2084,7 +2085,7 @@
if (report?.policyID) {
const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
const submitToAccountID = getSubmitToAccountID(policy, report);
const submitsToAccountDetails = allPersonalDetails?.[submitToAccountID];
const submitsToAccountDetails = (personalDetails ?? allPersonalDetails)?.[submitToAccountID];
const subtitle = submitsToAccountDetails?.displayName ?? submitsToAccountDetails?.login;

if (subtitle) {
Expand Down Expand Up @@ -2163,6 +2164,7 @@
includeUserToInvite = false,
maxRecentReportElements = undefined,
shouldAcceptName = false,
personalDetails,
...config
}: GetOptionsConfig = {},
countryCode: number = CONST.DEFAULT_COUNTRY_CODE,
Expand Down Expand Up @@ -2245,6 +2247,7 @@
shouldSeparateSelfDMChat,
shouldSeparateWorkspaceChat,
shouldShowGBR,
personalDetails,
}).at(0);
}

Expand All @@ -2258,6 +2261,7 @@
shouldSeparateSelfDMChat,
shouldSeparateWorkspaceChat,
shouldShowGBR,
personalDetails,
});

workspaceChats = prepareReportOptionsForDisplay(workspaceChats, policiesCollection, {
Expand All @@ -2267,6 +2271,7 @@
shouldSeparateSelfDMChat,
shouldSeparateWorkspaceChat,
shouldShowGBR,
personalDetails,
});
} else if (recentAttendees && recentAttendees?.length > 0) {
recentAttendees.filter((attendee) => {
Expand Down Expand Up @@ -2382,6 +2387,7 @@
shouldShowGBR?: boolean;
shouldUnreadBeBold?: boolean;
loginList: OnyxEntry<Login>;
personalDetails?: OnyxEntry<PersonalDetailsList>;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/libs/OptionsListUtils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {OptionData} from '@libs/ReportUtils';
import type {AvatarSource} from '@libs/UserAvatarUtils';
import type {IOUAction} from '@src/CONST';
import type {Beta, Login, PersonalDetails, Report, ReportActions, TransactionViolation} from '@src/types/onyx';
import type {Beta, Login, PersonalDetails, PersonalDetailsList, Report, ReportActions, TransactionViolation} from '@src/types/onyx';
import type {Icon, PendingAction} from '@src/types/onyx/OnyxCommon';

/**
Expand Down Expand Up @@ -157,6 +157,7 @@ type GetValidReportsConfig = {
preferredPolicyID?: string;
shouldUnreadBeBold?: boolean;
shouldAlwaysIncludeDM?: boolean;
personalDetails?: OnyxEntry<PersonalDetailsList>;
} & GetValidOptionsSharedConfig;

type IsValidReportsConfig = Pick<
Expand Down
2 changes: 2 additions & 0 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function useOptions() {
const [didScreenTransitionEnd, setDidScreenTransitionEnd] = useState(false);
const {contacts} = useContactImport();
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true});
const allPersonalDetails = usePersonalDetails();

const {
options: listOptions,
Expand Down Expand Up @@ -104,6 +105,7 @@ function useOptions() {
betas: betas ?? [],
includeSelfDM: true,
shouldAlwaysIncludeDM: true,
personalDetails: allPersonalDetails,
},
countryCode,
);
Expand Down
2 changes: 2 additions & 0 deletions src/pages/iou/request/MoneyRequestAccountantSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
betas,
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
action,
personalDetails,
},
countryCode,
);
Expand All @@ -112,6 +113,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
betas,
action,
countryCode,
personalDetails,
]);

const chatOptions = useMemo(() => {
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/OptionsListUtilsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,32 @@ describe('OptionsListUtils', () => {
expect(results.recentReports.at(0)?.isBold).toBe(true);
expect(results.recentReports.at(0)?.isUnread).toBe(true);
});

it('should use personalDetails parameter when passed to getValidOptions', () => {
// Given a personalDetails object to pass explicitly
const customPersonalDetails = {
2: {
accountID: 2,
displayName: 'Custom Iron Man',
login: 'tonystark@expensify.com',
},
3: {
accountID: 3,
displayName: 'Custom Spider-Man',
login: 'peterparker@expensify.com',
},
};

// When we call getValidOptions with personalDetails parameter
const results = getValidOptions({reports: OPTIONS.reports, personalDetails: OPTIONS.personalDetails}, {}, {}, nvpDismissedProductTraining, loginList, {
personalDetails: customPersonalDetails,
});

// Then the function should complete without errors and return valid results
// The personalDetails param is used internally by prepareReportOptionsForDisplay for workspace chats
expect(results.recentReports.length).toBeGreaterThan(0);
expect(results.personalDetails.length).toBeGreaterThan(0);
});
});

describe('getValidOptions() for chat room', () => {
Expand Down
Loading