From 32bee5712939d8f0970352af5e71b3a44314867c Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 10 Mar 2026 16:47:47 +0700 Subject: [PATCH 01/10] refactor createOption to use policy from useOnyx --- src/components/OptionListContextProvider.tsx | 19 +- .../Search/SearchFiltersChatsSelector.tsx | 4 +- .../SearchFiltersParticipantsSelector.tsx | 1 + .../Search/SearchRouter/SearchRouter.tsx | 3 +- src/hooks/useFilteredOptions.ts | 3 +- src/libs/OptionsListUtils/index.ts | 66 +++++- src/pages/NewChatPage.tsx | 1 + src/pages/Share/ShareDetailsPage.tsx | 5 +- src/pages/iou/SplitBillDetailsPage.tsx | 2 + .../MoneyRequestAccountantSelector.tsx | 4 + .../request/MoneyRequestAttendeeSelector.tsx | 2 + .../MoneyRequestParticipantsSelector.tsx | 2 + tests/perf-test/OptionsListUtils.perf-test.ts | 5 +- tests/perf-test/SearchRouter.perf-test.tsx | 2 +- tests/unit/OptionListContextProviderTest.tsx | 8 +- tests/unit/OptionsListUtilsTest.tsx | 218 ++++++++++++------ 16 files changed, 250 insertions(+), 95 deletions(-) diff --git a/src/components/OptionListContextProvider.tsx b/src/components/OptionListContextProvider.tsx index 1aa1cb33ca95..17a0108cf07d 100644 --- a/src/components/OptionListContextProvider.tsx +++ b/src/components/OptionListContextProvider.tsx @@ -62,6 +62,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { const [reports, {sourceValue: changedReports}] = useOnyx(ONYXKEYS.COLLECTION.REPORT); const prevReports = usePrevious(reports); const [, {sourceValue: changedReportActions}] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS); + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const personalDetails = usePersonalDetails(); const prevPersonalDetails = usePrevious(personalDetails); const privateIsArchivedMap = usePrivateIsArchivedMap(); @@ -70,12 +71,12 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { const hasInitialData = useMemo(() => Object.keys(personalDetails ?? {}).length > 0, [personalDetails]); const loadOptions = useCallback(() => { - const optionLists = createOptionList(personalDetails, currentUserAccountID, privateIsArchivedMap, reports, reportAttributes?.reports); + const optionLists = createOptionList(personalDetails, currentUserAccountID, privateIsArchivedMap, reports, allPolicies, reportAttributes?.reports); setOptions({ reports: optionLists.reports, personalDetails: optionLists.personalDetails, }); - }, [personalDetails, currentUserAccountID, privateIsArchivedMap, reports, reportAttributes?.reports]); + }, [personalDetails, currentUserAccountID, privateIsArchivedMap, reports, allPolicies, reportAttributes?.reports]); /** * This effect is responsible for generating the options list when their data is not yet initialized @@ -133,7 +134,8 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { const reportID = reportKey.replace(ONYXKEYS.COLLECTION.REPORT, ''); const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`]; const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; - const {reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, chatReport, reportAttributes?.reports); + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; + const {reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, chatReport, policy, reportAttributes?.reports); if (reportOption) { updatedReportsMap.set(reportID, reportOption); @@ -147,7 +149,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { reports: Array.from(updatedReportsMap.values()), }; }); - }, [changedReportsEntries, personalDetails, currentUserAccountID, reports, reportAttributes?.reports, privateIsArchivedMap]); + }, [changedReportsEntries, personalDetails, currentUserAccountID, reports, allPolicies, reportAttributes?.reports, privateIsArchivedMap]); useEffect(() => { if (!changedReportActions || !areOptionsInitialized.current) { @@ -170,7 +172,8 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { const reportItem = updatedReportsMap.get(reportID)?.item; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`]; const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportItem?.chatReportID}`]; - const {reportOption} = processReport(reportItem, personalDetails, privateIsArchived, currentUserAccountID, chatReport, reportAttributes?.reports); + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportItem?.policyID}`]; + const {reportOption} = processReport(reportItem, personalDetails, privateIsArchived, currentUserAccountID, chatReport, policy, reportAttributes?.reports); if (reportOption) { updatedReportsMap.set(reportID, reportOption); @@ -205,6 +208,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { currentUserAccountID, privateIsArchivedMap, reports, + allPolicies, reportAttributes?.reports, ); setOptions((prevOptions) => ({ @@ -241,7 +245,8 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]; const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`]; - const newReportOption = createOptionFromReport(report, personalDetails, currentUserAccountID, chatReport, privateIsArchived, reportAttributes?.reports, { + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; + const newReportOption = createOptionFromReport(report, personalDetails, currentUserAccountID, chatReport, privateIsArchived, policy, reportAttributes?.reports, { showPersonalDetails: true, }); const replaceIndex = options.reports.findIndex((option) => option.reportID === report.reportID); @@ -253,7 +258,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { } // since personal details are not a collection, we need to recreate the whole list from scratch - const newPersonalDetailsOptions = createOptionList(personalDetails, currentUserAccountID, privateIsArchivedMap, reports, reportAttributes?.reports).personalDetails; + const newPersonalDetailsOptions = createOptionList(personalDetails, currentUserAccountID, privateIsArchivedMap, reports, allPolicies, reportAttributes?.reports).personalDetails; setOptions((prevOptions) => { const newOptions = {...prevOptions}; diff --git a/src/components/Search/SearchFiltersChatsSelector.tsx b/src/components/Search/SearchFiltersChatsSelector.tsx index f10b57172334..8c01e44f4395 100644 --- a/src/components/Search/SearchFiltersChatsSelector.tsx +++ b/src/components/Search/SearchFiltersChatsSelector.tsx @@ -69,8 +69,9 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${id}`]; const reportData = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`]; const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportData?.chatReportID}`]; + const reportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`]; const report = getSelectedOptionData( - createOptionFromReport({...reportData, reportID: id}, personalDetails, currentUserAccountID, chatReport, privateIsArchived, reportAttributesDerived), + createOptionFromReport({...reportData, reportID: id}, personalDetails, currentUserAccountID, chatReport, privateIsArchived, reportPolicy, reportAttributesDerived), ); const isReportArchived = !!privateIsArchived; const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`]; @@ -110,6 +111,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen chatOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, + undefined, personalDetails, false, undefined, diff --git a/src/components/Search/SearchFiltersParticipantsSelector.tsx b/src/components/Search/SearchFiltersParticipantsSelector.tsx index 9458f6b0cede..abe96786388b 100644 --- a/src/components/Search/SearchFiltersParticipantsSelector.tsx +++ b/src/components/Search/SearchFiltersParticipantsSelector.tsx @@ -207,6 +207,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate, chatOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, + undefined, personalDetails, true, undefined, diff --git a/src/components/Search/SearchRouter/SearchRouter.tsx b/src/components/Search/SearchRouter/SearchRouter.tsx index 8214f5eef2d2..904caf1e586e 100644 --- a/src/components/Search/SearchRouter/SearchRouter.tsx +++ b/src/components/Search/SearchRouter/SearchRouter.tsx @@ -109,7 +109,8 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${contextualReportID}`]; const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`]; - const option = createOptionFromReport(report, personalDetails, currentUserAccountID, chatReport, privateIsArchived, undefined, {showPersonalDetails: true}); + const reportPolicy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; + const option = createOptionFromReport(report, personalDetails, currentUserAccountID, chatReport, privateIsArchived, reportPolicy, undefined, {showPersonalDetails: true}); reportForContextualSearch = option; } diff --git a/src/hooks/useFilteredOptions.ts b/src/hooks/useFilteredOptions.ts index bfc705ee1a69..cbf3a85fdbd2 100644 --- a/src/hooks/useFilteredOptions.ts +++ b/src/hooks/useFilteredOptions.ts @@ -73,6 +73,7 @@ function useFilteredOptions(config: UseFilteredOptionsConfig = {}): UseFilteredO const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); const [allPersonalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const reportAttributesDerived = useReportAttributes(); const privateIsArchivedMap = usePrivateIsArchivedMap(); @@ -82,7 +83,7 @@ function useFilteredOptions(config: UseFilteredOptionsConfig = {}): UseFilteredO const options: OptionList | null = enabled && allReports && allPersonalDetails - ? createFilteredOptionList(allPersonalDetails, allReports, currentUserPersonalDetails.accountID, reportAttributesDerived, privateIsArchivedMap, { + ? createFilteredOptionList(allPersonalDetails, allReports, currentUserPersonalDetails.accountID, reportAttributesDerived, privateIsArchivedMap, allPolicies, { maxRecentReports: reportsLimit, includeP2P, searchTerm, diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index b83731c459cd..3c90fda77f75 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -948,12 +948,14 @@ function getLastMessageTextForReport({ /** * Creates a report list option - optimized for SearchOption context */ +// eslint-disable-next-line max-params function createOption( accountIDs: number[], personalDetails: OnyxInputOrEntry, report: OnyxInputOrEntry, currentUserAccountID: number, chatReport: OnyxEntry, + policy: OnyxEntry, config?: PreviewConfig, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], privateIsArchived?: string, @@ -1055,8 +1057,7 @@ function createOption( {showChatPreviewLine, forcePolicyNamePreview}, !!result.private_isArchived, currentUserLogin, - // TODO: Remove this in the next PR that will refactor prepareReportOptionsForDisplay. Ref: https://github.com/Expensify/App/issues/66415 - undefined, + policy, lastActorDetails, visibleReportActionsData, translateFn, @@ -1127,6 +1128,7 @@ function getReportOption( !isEmptyObject(report) ? report : undefined, currentUserAccountID, chatReport, + policy, { showChatPreviewLine: false, forcePolicyNamePreview: false, @@ -1177,6 +1179,7 @@ function getReportDisplayOption( personalDetails: OnyxEntry, privateIsArchived: string | undefined, chatReport: OnyxEntry, + policy: OnyxEntry, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], visibleReportActionsData: VisibleReportActionsDerivedValue = {}, ): OptionData { @@ -1188,6 +1191,7 @@ function getReportDisplayOption( !isEmptyObject(report) ? report : undefined, currentUserAccountID, chatReport, + policy, { showChatPreviewLine: false, forcePolicyNamePreview: false, @@ -1230,6 +1234,7 @@ function getPolicyExpenseReportOption( personalDetails: OnyxEntry, expenseReport: OnyxEntry, chatReport: OnyxEntry, + policy: OnyxEntry, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], visibleReportActionsData: VisibleReportActionsDerivedValue = {}, ): SearchOptionData { @@ -1243,6 +1248,7 @@ function getPolicyExpenseReportOption( !isEmptyObject(expenseReport) ? expenseReport : null, currentUserAccountID, chatReport, + policy, { showChatPreviewLine: false, forcePolicyNamePreview: false, @@ -1361,6 +1367,7 @@ function processReport( privateIsArchived: string | undefined, currentUserAccountID: number, chatReport: OnyxEntry, + policy: OnyxEntry, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], visibleReportActionsData: VisibleReportActionsDerivedValue = {}, ): { @@ -1386,7 +1393,7 @@ function processReport( reportMapEntry, reportOption: { item: report, - ...createOption(accountIDs, personalDetails, report, currentUserAccountID, chatReport, undefined, reportAttributesDerived, privateIsArchived, visibleReportActionsData), + ...createOption(accountIDs, personalDetails, report, currentUserAccountID, chatReport, policy, undefined, reportAttributesDerived, privateIsArchived, visibleReportActionsData), }, }; } @@ -1396,6 +1403,7 @@ function createOptionList( currentUserAccountID: number, privateIsArchivedMap: PrivateIsArchivedMap, reports: OnyxCollection, + policiesCollection: OnyxCollection, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], visibleReportActionsData: VisibleReportActionsDerivedValue = {}, ) { @@ -1408,12 +1416,14 @@ function createOptionList( for (const report of Object.values(reports)) { const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; + const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const {reportMapEntry, reportOption} = processReport( report, personalDetails, privateIsArchived, currentUserAccountID, chatReport, + policy, reportAttributesDerived, visibleReportActionsData, ); @@ -1433,7 +1443,7 @@ function createOptionList( const report = reportMapForAccountIDs[personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID]; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; - + const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; return { item: personalDetail, ...createOption( @@ -1442,6 +1452,7 @@ function createOptionList( report, currentUserAccountID, chatReport, + policy, { showPersonalDetails: true, }, @@ -1483,6 +1494,7 @@ function createFilteredOptionList( currentUserAccountID: number, reportAttributesDerived: ReportAttributesDerivedValue['reports'] | undefined, privateIsArchivedMap: PrivateIsArchivedMap, + policiesCollection: OnyxCollection, options: { maxRecentReports?: number; includeP2P?: boolean; @@ -1541,7 +1553,17 @@ function createFilteredOptionList( for (const report of limitedReports) { const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]; const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; - const {reportMapEntry, reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, chatReport, reportAttributesDerived, visibleReportActionsData); + const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; + const {reportMapEntry, reportOption} = processReport( + report, + personalDetails, + privateIsArchived, + currentUserAccountID, + chatReport, + policy, + reportAttributesDerived, + visibleReportActionsData, + ); if (reportMapEntry) { const [accountID, reportValue] = reportMapEntry; @@ -1572,6 +1594,7 @@ function createFilteredOptionList( const report = reportMapForAccountIDs[accountID]; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; + const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; return { item: personalDetail, ...createOption( @@ -1580,6 +1603,7 @@ function createFilteredOptionList( reportMapForAccountIDs[accountID], currentUserAccountID, chatReport, + policy, {showPersonalDetails: true}, reportAttributesDerived, privateIsArchived, @@ -1601,6 +1625,7 @@ function createOptionFromReport( currentUserAccountID: number, chatReport: OnyxEntry, privateIsArchived: string | undefined, + policy: OnyxEntry, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], config?: PreviewConfig, visibleReportActionsData: VisibleReportActionsDerivedValue = {}, @@ -1609,7 +1634,7 @@ function createOptionFromReport( return { item: report, - ...createOption(accountIDs, personalDetails, report, currentUserAccountID, chatReport, config, reportAttributesDerived, privateIsArchived, visibleReportActionsData), + ...createOption(accountIDs, personalDetails, report, currentUserAccountID, chatReport, policy, config, reportAttributesDerived, privateIsArchived, visibleReportActionsData), }; } @@ -1939,6 +1964,7 @@ function getUserToInviteOption({ null, currentUserAccountID, undefined, + undefined, {showChatPreviewLine}, undefined, undefined, @@ -2247,6 +2273,7 @@ function prepareReportOptionsForDisplay( continue; } const report = option.item; + const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; /** * By default, generated options does not have the chat preview line enabled. * If showChatPreviewLine or forcePolicyNamePreview are true, let's generate and overwrite the alternate text. @@ -2256,8 +2283,7 @@ function prepareReportOptionsForDisplay( {showChatPreviewLine, forcePolicyNamePreview}, !!option.private_isArchived, currentUserLogin, - // TODO: Remove this in the next PR that will refactor prepareReportOptionsForDisplay. Ref: https://github.com/Expensify/App/issues/66415 - undefined, + policy, null, visibleReportActionsData, undefined, @@ -2313,7 +2339,6 @@ function prepareReportOptionsForDisplay( newReportOption.alternateText = translateLocal('workspace.common.workspace'); if (report?.policyID) { - const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; const submitToAccountID = getSubmitToAccountID(policy, report); const submitsToAccountDetails = personalDetails?.[submitToAccountID]; const subtitle = submitsToAccountDetails?.displayName ?? submitsToAccountDetails?.login; @@ -2915,6 +2940,7 @@ function formatSectionsFromSearchTerm( filteredPersonalDetails: SearchOptionData[], privateIsArchivedMap: Record, currentUserAccountID: number, + policy: OnyxEntry, personalDetails: OnyxEntry = {}, shouldGetOptionDetails = false, filteredWorkspaceChats: SearchOptionData[] = [], @@ -2936,7 +2962,16 @@ function formatSectionsFromSearchTerm( const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`]; const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.chatReportID}`]; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport?.reportID}`]; - return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, chatReport, reportAttributesDerived); + return getPolicyExpenseReportOption( + participant, + privateIsArchived, + currentUserAccountID, + personalDetails, + expenseReport, + chatReport, + policy, + reportAttributesDerived, + ); } return getParticipantsOption(participant, personalDetails); }) @@ -2969,7 +3004,16 @@ function formatSectionsFromSearchTerm( const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`]; const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.chatReportID}`]; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport?.reportID}`]; - return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, chatReport, reportAttributesDerived); + return getPolicyExpenseReportOption( + participant, + privateIsArchived, + currentUserAccountID, + personalDetails, + expenseReport, + chatReport, + policy, + reportAttributesDerived, + ); } return getParticipantsOption(participant, personalDetails); }) diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index bd66a42cf757..3024b55c2793 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -277,6 +277,7 @@ function NewChatPage({ref}: NewChatPageProps) { personalDetails, privateIsArchivedMap, currentUserAccountID, + undefined, allPersonalDetails, undefined, undefined, diff --git a/src/pages/Share/ShareDetailsPage.tsx b/src/pages/Share/ShareDetailsPage.tsx index 2849da43ed55..db220d4ae961 100644 --- a/src/pages/Share/ShareDetailsPage.tsx +++ b/src/pages/Share/ShareDetailsPage.tsx @@ -69,9 +69,10 @@ function ShareDetailsPage({route}: ShareDetailsPageProps) { const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; const ancestors = useAncestors(report); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`); const displayReport = useMemo( - () => getReportDisplayOption(report, unknownUserDetails, personalDetail.accountID, personalDetails, privateIsArchived, chatReport, reportAttributesDerived), - [report, unknownUserDetails, personalDetails, privateIsArchived, reportAttributesDerived, personalDetail.accountID, chatReport], + () => getReportDisplayOption(report, unknownUserDetails, personalDetail.accountID, personalDetails, privateIsArchived, chatReport, policy, reportAttributesDerived), + [report, unknownUserDetails, personalDetails, privateIsArchived, reportAttributesDerived, personalDetail.accountID, chatReport, policy], ); const shouldShowAttachment = !isTextShared; diff --git a/src/pages/iou/SplitBillDetailsPage.tsx b/src/pages/iou/SplitBillDetailsPage.tsx index b50806995f02..31bf1df28cf1 100644 --- a/src/pages/iou/SplitBillDetailsPage.tsx +++ b/src/pages/iou/SplitBillDetailsPage.tsx @@ -68,6 +68,7 @@ function SplitBillDetailsPage({route, report, reportAction}: SplitBillDetailsPag const reportAttributesDerived = useReportAttributes(); const [betas] = useOnyx(ONYXKEYS.BETAS); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.chatReportID)}`); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`); const [privateIsArchived] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`, {selector: privateIsArchivedSelector}); // In case this is workspace split expense, we manually add the workspace as the second participant of the split expense @@ -83,6 +84,7 @@ function SplitBillDetailsPage({route, report, reportAction}: SplitBillDetailsPag personalDetails, report, chatReport, + policy, reportAttributesDerived, ), ]; diff --git a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx index 56d66f9d5389..49dc7738e9e6 100644 --- a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx @@ -72,6 +72,8 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType const currentUserEmail = currentUserPersonalDetails.email ?? ''; const currentUserAccountID = currentUserPersonalDetails.accountID; const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); + const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`]; const privateIsArchivedMap = usePrivateIsArchivedMap(); useEffect(() => { @@ -164,6 +166,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType chatOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, + policy, personalDetails, true, undefined, @@ -203,6 +206,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType personalDetails, userToInviteExpenseReport, userToInviteChatReport, + policy, reportAttributesDerived, ) : getParticipantsOption(participant, personalDetails); diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index 750f1419b2dd..e338097474ea 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -211,6 +211,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde orderedAvailableOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, + policy, personalDetails, true, undefined, @@ -264,6 +265,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde personalDetails, userToInviteExpenseReport, userToInviteChatReport, + policy, reportAttributesDerived, ) : getParticipantsOption(participant, personalDetails); diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index da97594ae6c6..d0a8b970f09a 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -297,6 +297,7 @@ function MoneyRequestParticipantsSelector({ [], privateIsArchivedMap, currentUserAccountID, + policy, personalDetails, true, undefined, @@ -367,6 +368,7 @@ function MoneyRequestParticipantsSelector({ personalDetails, userToInviteExpenseReport, userToInviteChatReport, + policy, reportAttributesDerived, ) : getParticipantsOption(participant, personalDetails); diff --git a/tests/perf-test/OptionsListUtils.perf-test.ts b/tests/perf-test/OptionsListUtils.perf-test.ts index bbbc05e24636..e2ca3dc0182d 100644 --- a/tests/perf-test/OptionsListUtils.perf-test.ts +++ b/tests/perf-test/OptionsListUtils.perf-test.ts @@ -95,7 +95,7 @@ jest.mock('@react-navigation/native', () => { }); const EMPTY_PRIVATE_IS_ARCHIVED_MAP: PrivateIsArchivedMap = {}; -const options = createOptionList(personalDetails, MOCK_CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, reports); +const options = createOptionList(personalDetails, MOCK_CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, reports, undefined); const ValidOptionsConfig = { betas: mockedBetas, @@ -272,6 +272,7 @@ describe('OptionsListUtils', () => { Object.values(filteredPersonalDetails), {}, MOCK_CURRENT_USER_ACCOUNT_ID, + undefined, mockedPersonalDetails, true, ), @@ -284,6 +285,6 @@ describe('OptionsListUtils', () => { const mockedPersonalDetails = getMockedPersonalDetails(PERSONAL_DETAILS_COUNT); await waitForBatchedUpdates(); - await measureFunction(() => formatSectionsFromSearchTerm('', Object.values(selectedOptions), [], [], {}, MOCK_CURRENT_USER_ACCOUNT_ID, mockedPersonalDetails, true)); + await measureFunction(() => formatSectionsFromSearchTerm('', Object.values(selectedOptions), [], [], {}, MOCK_CURRENT_USER_ACCOUNT_ID, undefined, mockedPersonalDetails, true)); }); }); diff --git a/tests/perf-test/SearchRouter.perf-test.tsx b/tests/perf-test/SearchRouter.perf-test.tsx index b9320a1087ed..7babdd0bb4b3 100644 --- a/tests/perf-test/SearchRouter.perf-test.tsx +++ b/tests/perf-test/SearchRouter.perf-test.tsx @@ -107,7 +107,7 @@ const mockedReports = getMockedReports(600); const mockedBetas = Object.values(CONST.BETAS); const mockedPersonalDetails = getMockedPersonalDetails(100); const EMPTY_PRIVATE_IS_ARCHIVED_MAP: PrivateIsArchivedMap = {}; -const mockedOptions = createOptionList(mockedPersonalDetails, MOCK_CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, mockedReports); +const mockedOptions = createOptionList(mockedPersonalDetails, MOCK_CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, mockedReports, undefined); beforeAll(() => Onyx.init({ diff --git a/tests/unit/OptionListContextProviderTest.tsx b/tests/unit/OptionListContextProviderTest.tsx index 3d4274e624b9..516baf573616 100644 --- a/tests/unit/OptionListContextProviderTest.tsx +++ b/tests/unit/OptionListContextProviderTest.tsx @@ -223,7 +223,7 @@ describe('OptionListContextProvider', () => { mockUsePersonalDetails.mockReturnValue(updatedPersonalDetails); rerender({shouldInitialize: false}); - expect(mockCreateOptionFromReport).toHaveBeenCalledWith(report, updatedPersonalDetails, expect.any(Number), undefined, 'true', undefined, {showPersonalDetails: true}); + expect(mockCreateOptionFromReport).toHaveBeenCalledWith(report, updatedPersonalDetails, expect.any(Number), undefined, 'true', undefined, undefined, {showPersonalDetails: true}); }); it('passes resolved chatReport to processReport when changed reports have chatReportID', () => { @@ -262,7 +262,7 @@ describe('OptionListContextProvider', () => { rerender({shouldInitialize: false}); - expect(mockProcessReport).toHaveBeenCalledWith(report, {}, undefined, expect.any(Number), chatReport, undefined); + expect(mockProcessReport).toHaveBeenCalledWith(report, {}, undefined, expect.any(Number), chatReport, undefined, undefined); }); it('passes resolved chatReport to processReport when report actions change', () => { @@ -315,7 +315,7 @@ describe('OptionListContextProvider', () => { rerender({shouldInitialize: false}); - expect(mockProcessReport).toHaveBeenCalledWith(report, {}, undefined, expect.any(Number), chatReport, undefined); + expect(mockProcessReport).toHaveBeenCalledWith(report, {}, undefined, expect.any(Number), chatReport, undefined, undefined); }); it('passes resolved chatReport to createOptionFromReport when personal details change and report has chatReportID', () => { @@ -371,6 +371,6 @@ describe('OptionListContextProvider', () => { mockUsePersonalDetails.mockReturnValue(updatedPersonalDetails); rerender({shouldInitialize: false}); - expect(mockCreateOptionFromReport).toHaveBeenCalledWith(report, updatedPersonalDetails, expect.any(Number), chatReport, undefined, undefined, {showPersonalDetails: true}); + expect(mockCreateOptionFromReport).toHaveBeenCalledWith(report, updatedPersonalDetails, expect.any(Number), chatReport, undefined, undefined, undefined, {showPersonalDetails: true}); }); }); diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index 95b38894382d..27911e30a9c1 100644 --- a/tests/unit/OptionsListUtilsTest.tsx +++ b/tests/unit/OptionsListUtilsTest.tsx @@ -761,12 +761,13 @@ describe('OptionsListUtils', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}10`, reportNameValuePairs); await waitForBatchedUpdates(); - OPTIONS = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS, MOCK_REPORT_ATTRIBUTES_DERIVED); + OPTIONS = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS, undefined, MOCK_REPORT_ATTRIBUTES_DERIVED); OPTIONS_WITH_CONCIERGE = createOptionList( PERSONAL_DETAILS_WITH_CONCIERGE, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_CONCIERGE, + undefined, MOCK_REPORT_ATTRIBUTES_DERIVED_WITH_CONCIERGE, ); OPTIONS_WITH_CHRONOS = createOptionList( @@ -774,6 +775,7 @@ describe('OptionsListUtils', () => { CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_CHRONOS, + undefined, MOCK_REPORT_ATTRIBUTES_DERIVED_WITH_CHRONOS, ); OPTIONS_WITH_RECEIPTS = createOptionList( @@ -781,6 +783,7 @@ describe('OptionsListUtils', () => { CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_RECEIPTS, + undefined, MOCK_REPORT_ATTRIBUTES_DERIVED_WITH_RECEIPTS, ); OPTIONS_WITH_WORKSPACE_ROOM = createOptionList( @@ -788,6 +791,7 @@ describe('OptionsListUtils', () => { CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_WORKSPACE_ROOMS, + undefined, MOCK_REPORT_ATTRIBUTES_DERIVED_WITH_WORKSPACE_ROOM, ); OPTIONS_WITH_MANAGER_MCTEST = createOptionList( @@ -795,6 +799,7 @@ describe('OptionsListUtils', () => { CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_MANAGER_MCTEST, + undefined, MOCK_REPORT_ATTRIBUTES_DERIVED_WITH_MANAGER_MCTEST, ); }); @@ -2411,7 +2416,7 @@ describe('OptionsListUtils', () => { // cspell:disable-next-line const searchText = 'barryallen'; // Given a set of options created from PERSONAL_DETAILS_WITH_PERIODS - const OPTIONS_WITH_PERIODS = createOptionList(PERSONAL_DETAILS_WITH_PERIODS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS); + const OPTIONS_WITH_PERIODS = createOptionList(PERSONAL_DETAILS_WITH_PERIODS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS, undefined); // When we call getSearchOptions with all betas const options = getSearchOptions({ options: OPTIONS_WITH_PERIODS, @@ -2492,6 +2497,7 @@ describe('OptionsListUtils', () => { CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_CHAT_ROOM, + undefined, MOCK_REPORT_ATTRIBUTES_DERIVED_WITH_CHAT_ROOM, ); // When we call getSearchOptions with all betas @@ -2874,7 +2880,7 @@ describe('OptionsListUtils', () => { }, }; - const OPTIONS_WITH_GROUP_CHAT = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_GROUP_CHAT); + const OPTIONS_WITH_GROUP_CHAT = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_GROUP_CHAT, undefined); // When we call getSearchOptions with a search query that matches a participant display name const options = getSearchOptions({ @@ -2915,7 +2921,7 @@ describe('OptionsListUtils', () => { }, }; - const OPTIONS_WITH_GROUP_CHAT = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_GROUP_CHAT); + const OPTIONS_WITH_GROUP_CHAT = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_GROUP_CHAT, undefined); // When we call getSearchOptions with a search query that matches a participant login const options = getSearchOptions({ @@ -2956,7 +2962,7 @@ describe('OptionsListUtils', () => { }, }; - const OPTIONS_WITH_GROUP_CHAT = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_GROUP_CHAT); + const OPTIONS_WITH_GROUP_CHAT = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_GROUP_CHAT, undefined); // When we call getSearchOptions with a search query that matches a participant name const options = getSearchOptions({ @@ -2997,7 +3003,7 @@ describe('OptionsListUtils', () => { }, }; - const OPTIONS_WITH_GROUP_CHAT = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_GROUP_CHAT); + const OPTIONS_WITH_GROUP_CHAT = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_GROUP_CHAT, undefined); // When we call getSearchOptions with a search query that does not match any participant const options = getSearchOptions({ @@ -3040,6 +3046,7 @@ describe('OptionsListUtils', () => { CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_GROUP_CHAT_NO_PARTICIPANTS, + undefined, ); // When we call getSearchOptions with all betas @@ -3399,7 +3406,7 @@ describe('OptionsListUtils', () => { .then(() => Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, PERSONAL_DETAILS_WITH_PERIODS)) .then(() => { // Given a set of options with periods - const OPTIONS_WITH_PERIODS = createOptionList(PERSONAL_DETAILS_WITH_PERIODS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS); + const OPTIONS_WITH_PERIODS = createOptionList(PERSONAL_DETAILS_WITH_PERIODS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS, undefined); // When we call getSearchOptions const results = getSearchOptions({ options: OPTIONS_WITH_PERIODS, @@ -3463,7 +3470,7 @@ describe('OptionsListUtils', () => { it('should order self dm always on top if the search matches with the self dm login', () => { const searchTerm = 'tonystark@expensify.com'; - const OPTIONS_WITH_SELF_DM = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_SELF_DM); + const OPTIONS_WITH_SELF_DM = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS_WITH_SELF_DM, undefined); // Given a set of options with self dm and all betas const options = getSearchOptions({ @@ -3525,7 +3532,7 @@ describe('OptionsListUtils', () => { renderLocaleContextProvider(); // Given a set of reports and personal details // When we call createOptionList and extract the reports - const reports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS).reports; + const reports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS, undefined).reports; // Then the returned reports should match the expected values expect(reports.at(10)?.subtitle).toBe(`Submits to Mister Fantastic`); @@ -3536,7 +3543,7 @@ describe('OptionsListUtils', () => { .then(() => Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES)) .then(() => { // When we call createOptionList again - const newReports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS).reports; + const newReports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS, undefined).reports; // Then the returned reports should change to Spanish // cspell:disable-next-line expect(newReports.at(10)?.subtitle).toBe('Se envía a Mister Fantastic'); @@ -3616,7 +3623,7 @@ describe('OptionsListUtils', () => { }, }); // When we call createOptionList - const reports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS).reports; + const reports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS, undefined).reports; const archivedReport = reports.find((report) => report.reportID === '10'); // Then the returned report should contain default archived reason @@ -3632,7 +3639,7 @@ describe('OptionsListUtils', () => { }; // When we call createOptionList with this privateIsArchivedMap - const result = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, privateIsArchivedMap, REPORTS); + const result = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, privateIsArchivedMap, REPORTS, undefined); // Then the personal detail option for account 1 (Mister Fantastic) should have private_isArchived set const misterFantasticOption = result.personalDetails.find((pd) => pd.item?.accountID === 1); @@ -3645,7 +3652,7 @@ describe('OptionsListUtils', () => { const emptyMap: PrivateIsArchivedMap = {}; // When we call createOptionList with an empty privateIsArchivedMap - const result = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, emptyMap, REPORTS); + const result = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, emptyMap, REPORTS, undefined); // Then no personal details options should have private_isArchived set const optionsWithArchived = result.personalDetails.filter((pd) => pd.private_isArchived); @@ -3661,7 +3668,7 @@ describe('OptionsListUtils', () => { }; // When we call createOptionList with this privateIsArchivedMap - const result = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, privateIsArchivedMap, REPORTS); + const result = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, privateIsArchivedMap, REPORTS, undefined); // Then the personal detail options should have the correct private_isArchived values const misterFantasticOption = result.personalDetails.find((pd) => pd.item?.accountID === 1); @@ -3680,7 +3687,7 @@ describe('OptionsListUtils', () => { }; // When we call createOptionList with this privateIsArchivedMap - const result = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, privateIsArchivedMap, REPORTS); + const result = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, privateIsArchivedMap, REPORTS, undefined); // Then the report options should have the correct private_isArchived values const report3Option = result.reports.find((r) => r.item?.reportID === '3'); @@ -3704,7 +3711,7 @@ describe('OptionsListUtils', () => { }; // When we call createFilteredOptionList with this privateIsArchivedMap - const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchivedMap); + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchivedMap, undefined); // Then the report options should have the correct private_isArchived values const report3Option = result.reports.find((r) => r.item?.reportID === '3'); @@ -3723,7 +3730,7 @@ describe('OptionsListUtils', () => { const emptyMap: PrivateIsArchivedMap = {}; // When we call createFilteredOptionList with an empty privateIsArchivedMap - const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, emptyMap); + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, emptyMap, undefined); // Then reports NOT in Onyx (like report 3, 5) should not have private_isArchived set // Note: Report 10 gets private_isArchived from Onyx (set in beforeAll) @@ -3744,7 +3751,7 @@ describe('OptionsListUtils', () => { }; // When we call createFilteredOptionList with this privateIsArchivedMap - const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchivedMap); + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchivedMap, undefined); // Then the report options should have the correct private_isArchived values const report1Option = result.reports.find((r) => r.item?.reportID === '1'); @@ -3769,7 +3776,7 @@ describe('OptionsListUtils', () => { }; // When we call createFilteredOptionList with maxRecentReports limit - const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchivedMap, { + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchivedMap, undefined, { maxRecentReports: 5, }); @@ -4186,7 +4193,7 @@ describe('OptionsListUtils', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); await waitForBatchedUpdates(); - const result = createOption([1, 2], PERSONAL_DETAILS, report, CURRENT_USER_ACCOUNT_ID, undefined, {showChatPreviewLine: true}); + const result = createOption([1, 2], PERSONAL_DETAILS, report, CURRENT_USER_ACCOUNT_ID, undefined, undefined, {showChatPreviewLine: true}); expect(result.alternateText).toBe('Iron Man owes ₫34'); }); @@ -4214,7 +4221,7 @@ describe('OptionsListUtils', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, chatReport); await waitForBatchedUpdates(); - const result = createOption([1, 2], PERSONAL_DETAILS, report, 1, chatReport); + const result = createOption([1, 2], PERSONAL_DETAILS, report, 1, chatReport, undefined); expect(result.reportID).toBe(reportID); expect(typeof result.text).toBe('string'); @@ -5143,7 +5150,7 @@ describe('OptionsListUtils', () => { const personalDetails: PersonalDetailsList = PERSONAL_DETAILS; // When we call getReportDisplayOption - const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, personalDetails, undefined, undefined); + const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, personalDetails, undefined, undefined, undefined); // Then it should return an option with isSelfDM and alternateText set expect(result.isSelfDM).toBe(true); @@ -5163,7 +5170,7 @@ describe('OptionsListUtils', () => { const personalDetails: PersonalDetailsList = PERSONAL_DETAILS; // When we call getReportDisplayOption - const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, personalDetails, undefined, undefined); + const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, personalDetails, undefined, undefined, undefined); // Then it should return an option with invoice room text and alternateText expect(result.isInvoiceRoom).toBe(true); @@ -5185,7 +5192,7 @@ describe('OptionsListUtils', () => { const personalDetails: PersonalDetailsList = PERSONAL_DETAILS; // When we call getReportDisplayOption - const result = getReportDisplayOption(report, unknownUserDetails, CURRENT_USER_ACCOUNT_ID, personalDetails, undefined, undefined); + const result = getReportDisplayOption(report, unknownUserDetails, CURRENT_USER_ACCOUNT_ID, personalDetails, undefined, undefined, undefined); // Then it should return an option with unknownUserDetails data expect(result.text).toBe('Unknown User'); @@ -5206,7 +5213,7 @@ describe('OptionsListUtils', () => { const personalDetails: PersonalDetailsList = PERSONAL_DETAILS; // When we call getReportDisplayOption - const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, personalDetails, undefined, undefined); + const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, personalDetails, undefined, undefined, undefined); // Then it should return an option with workspace name expect(result.text).toBe(POLICY.name); @@ -5233,7 +5240,7 @@ describe('OptionsListUtils', () => { }; // When we call getReportDisplayOption with custom personalDetails - const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, customPersonalDetails, undefined, undefined); + const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, customPersonalDetails, undefined, undefined, undefined); // Then it should use the custom personalDetails parameter expect(result).toBeDefined(); @@ -5250,7 +5257,7 @@ describe('OptionsListUtils', () => { const emptyPersonalDetails: PersonalDetailsList = {}; // When we call getReportDisplayOption - const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, emptyPersonalDetails, undefined, undefined); + const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, emptyPersonalDetails, undefined, undefined, undefined); // Then it should not throw and return a valid option expect(result).toBeDefined(); @@ -5262,7 +5269,7 @@ describe('OptionsListUtils', () => { const personalDetails: PersonalDetailsList = PERSONAL_DETAILS; // When we call getReportDisplayOption with undefined report - const result = getReportDisplayOption(undefined, undefined, CURRENT_USER_ACCOUNT_ID, personalDetails, undefined, undefined); + const result = getReportDisplayOption(undefined, undefined, CURRENT_USER_ACCOUNT_ID, personalDetails, undefined, undefined, undefined); // Then it should return a valid option (createOption handles undefined) expect(result).toBeDefined(); @@ -5643,7 +5650,7 @@ describe('OptionsListUtils', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, report); await waitForBatchedUpdates(); - const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, reportNameValuePair?.private_isArchived, undefined); + const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, reportNameValuePair?.private_isArchived, undefined, undefined); expect(option).toBeDefined(); expect(option.reportID).toBe(reportID); @@ -5666,7 +5673,7 @@ describe('OptionsListUtils', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, report); await waitForBatchedUpdates(); - const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, reportNameValuePair?.private_isArchived, undefined); + const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, reportNameValuePair?.private_isArchived, undefined, undefined); expect(option).toBeDefined(); expect(option.reportID).toBe(reportID); @@ -5686,7 +5693,7 @@ describe('OptionsListUtils', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, report); await waitForBatchedUpdates(); - const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, undefined, undefined); + const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, undefined, undefined, undefined); expect(option).toBeDefined(); expect(option.reportID).toBe(reportID); @@ -5710,7 +5717,7 @@ describe('OptionsListUtils', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, report); await waitForBatchedUpdates(); - const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, reportNameValuePair?.private_isArchived, undefined); + const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, reportNameValuePair?.private_isArchived, undefined, undefined); expect(option).toBeDefined(); expect(option.reportID).toBe(reportID); @@ -5734,7 +5741,7 @@ describe('OptionsListUtils', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, report); await waitForBatchedUpdates(); - const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, reportNameValuePair?.private_isArchived, undefined); + const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, reportNameValuePair?.private_isArchived, undefined, undefined); expect(option).toBeDefined(); expect(option.reportID).toBe(reportID); @@ -6045,7 +6052,7 @@ describe('OptionsListUtils', () => { selected: true, }; - const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, testPersonalDetails, report, undefined); + const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, testPersonalDetails, report, undefined, undefined); expect(option).toBeDefined(); expect(option.text).toBe('Test Workspace Policy'); @@ -6106,7 +6113,7 @@ describe('OptionsListUtils', () => { isPolicyExpenseChat: true, }; - const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, testPersonalDetails, report, undefined); + const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, testPersonalDetails, report, undefined, undefined); expect(option).toBeDefined(); expect(option.text).toBe('Team Workspace'); @@ -6150,7 +6157,7 @@ describe('OptionsListUtils', () => { }; // Should not throw when personalDetails is empty - const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, {}, report, undefined); + const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, {}, report, undefined, undefined); expect(option).toBeDefined(); expect(option.text).toBe('Workspace Without Details'); @@ -6194,7 +6201,7 @@ describe('OptionsListUtils', () => { }; // Should not throw when personalDetails is undefined - const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, undefined, report, undefined); + const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, undefined, report, undefined, undefined); expect(option).toBeDefined(); expect(option.text).toBe('Workspace Undefined Details'); @@ -6246,10 +6253,10 @@ describe('OptionsListUtils', () => { selected: false, }; - const optionSelected = getPolicyExpenseReportOption(participantSelected, undefined, CURRENT_USER_ACCOUNT_ID, {}, report, undefined); + const optionSelected = getPolicyExpenseReportOption(participantSelected, undefined, CURRENT_USER_ACCOUNT_ID, {}, report, undefined, undefined); // eslint-disable-next-line rulesdir/no-negated-variables - const optionNotSelected = getPolicyExpenseReportOption(participantNotSelected, undefined, CURRENT_USER_ACCOUNT_ID, {}, report, undefined); + const optionNotSelected = getPolicyExpenseReportOption(participantNotSelected, undefined, CURRENT_USER_ACCOUNT_ID, {}, report, undefined, undefined); expect(optionSelected.isSelected).toBe(true); expect(optionSelected.selected).toBe(true); @@ -6307,7 +6314,7 @@ describe('OptionsListUtils', () => { selected: false, }; - const option = getPolicyExpenseReportOption(participant, archivedTimestamp, CURRENT_USER_ACCOUNT_ID, testPersonalDetails, report, undefined); + const option = getPolicyExpenseReportOption(participant, archivedTimestamp, CURRENT_USER_ACCOUNT_ID, testPersonalDetails, report, undefined, undefined); expect(option).toBeDefined(); expect(option.private_isArchived).toBe(archivedTimestamp); @@ -6351,7 +6358,7 @@ describe('OptionsListUtils', () => { isPolicyExpenseChat: true, }; - const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, {}, report, undefined); + const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, {}, report, undefined, undefined); expect(option).toBeDefined(); expect(option.private_isArchived).toBeUndefined(); @@ -6437,7 +6444,7 @@ describe('OptionsListUtils', () => { } as SearchOptionData, ]; - const result = formatSectionsFromSearchTerm('', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, formatPersonalDetails, true); + const result = formatSectionsFromSearchTerm('', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, undefined, formatPersonalDetails, true); expect(result.section.data).toHaveLength(1); @@ -6459,7 +6466,7 @@ describe('OptionsListUtils', () => { } as SearchOptionData, ]; - const result = formatSectionsFromSearchTerm('', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, formatPersonalDetails, true); + const result = formatSectionsFromSearchTerm('', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, undefined, formatPersonalDetails, true); expect(result.section.data).toHaveLength(1); @@ -6492,7 +6499,7 @@ describe('OptionsListUtils', () => { } as SearchOptionData, ]; - const result = formatSectionsFromSearchTerm('', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, formatPersonalDetails, true); + const result = formatSectionsFromSearchTerm('', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, undefined, formatPersonalDetails, true); expect(result.section.data).toHaveLength(2); @@ -6519,7 +6526,7 @@ describe('OptionsListUtils', () => { } as SearchOptionData, ]; - const result = formatSectionsFromSearchTerm('', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, formatPersonalDetails, false); + const result = formatSectionsFromSearchTerm('', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, undefined, formatPersonalDetails, false); expect(result.section.data).toHaveLength(1); // When shouldGetOptionDetails is false, the original selectedOptions are returned unchanged @@ -6547,7 +6554,7 @@ describe('OptionsListUtils', () => { ]; // Pass empty filtered lists so the selected option is not deduplicated - const result = formatSectionsFromSearchTerm('format', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, formatPersonalDetails, true); + const result = formatSectionsFromSearchTerm('format', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, undefined, formatPersonalDetails, true); expect(result.section.data).toHaveLength(1); @@ -6575,7 +6582,7 @@ describe('OptionsListUtils', () => { } as SearchOptionData, ]; - const result = formatSectionsFromSearchTerm('', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, formatPersonalDetails, true); + const result = formatSectionsFromSearchTerm('', selectedOptions, [], [], privateIsArchivedMap, CURRENT_USER_ACCOUNT_ID, undefined, formatPersonalDetails, true); expect(result.section.data).toHaveLength(1); @@ -6587,7 +6594,7 @@ describe('OptionsListUtils', () => { }); it('should return empty section when no selectedOptions are provided', () => { - const result = formatSectionsFromSearchTerm('', [], [], [], {}, CURRENT_USER_ACCOUNT_ID, formatPersonalDetails, true); + const result = formatSectionsFromSearchTerm('', [], [], [], {}, CURRENT_USER_ACCOUNT_ID, undefined, formatPersonalDetails, true); expect(result.section.data).toHaveLength(0); }); @@ -6828,7 +6835,7 @@ describe('OptionsListUtils', () => { await waitForBatchedUpdates(); // When we call createOption with the linked chat report - const result = createOption([1, 2], PERSONAL_DETAILS, expenseReport, CURRENT_USER_ACCOUNT_ID, linkedChatReport); + const result = createOption([1, 2], PERSONAL_DETAILS, expenseReport, CURRENT_USER_ACCOUNT_ID, linkedChatReport, undefined); // Then the option should be created successfully expect(result).toBeDefined(); @@ -6858,7 +6865,7 @@ describe('OptionsListUtils', () => { await waitForBatchedUpdates(); // When we call getReportDisplayOption with chat report - const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, undefined, chatReport); + const option = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, undefined, chatReport, undefined); // Then the option should be created successfully using the reports collection expect(option).toBeDefined(); @@ -6899,7 +6906,7 @@ describe('OptionsListUtils', () => { }; // When we call getPolicyExpenseReportOption with report passed directly - const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, report, undefined); + const option = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, report, undefined, undefined); // Then the option should be created successfully expect(option).toBeDefined(); @@ -6919,7 +6926,7 @@ describe('OptionsListUtils', () => { }, }; - const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined); + const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined, undefined); expect(result).toBeDefined(); expect(result.reportID).toBe('1'); @@ -6938,7 +6945,7 @@ describe('OptionsListUtils', () => { }; const privateIsArchived = DateUtils.getDBTime(); - const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchived); + const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchived, undefined); expect(result).toBeDefined(); expect(result.private_isArchived).toBe(privateIsArchived); @@ -6955,7 +6962,7 @@ describe('OptionsListUtils', () => { }, }; - const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined); + const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined, undefined); expect(result).toBeDefined(); expect(result.private_isArchived).toBeUndefined(); @@ -6973,7 +6980,7 @@ describe('OptionsListUtils', () => { }; // Pass undefined for reportAttributesDerived - the function should handle it gracefully - const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined, undefined); + const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined, undefined, undefined); expect(result).toBeDefined(); expect(result.reportID).toBe('1'); @@ -6991,7 +6998,7 @@ describe('OptionsListUtils', () => { }; const config = {showPersonalDetails: true}; - const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined, undefined, config); + const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined, undefined, undefined, config); expect(result).toBeDefined(); expect(result.reportID).toBe('1'); @@ -7000,7 +7007,7 @@ describe('OptionsListUtils', () => { describe('createFilteredOptionList', () => { it('should return report options limited by maxRecentReports', () => { - const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, {}, {maxRecentReports: 5}); + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, {}, undefined, {maxRecentReports: 5}); expect(result).toBeDefined(); expect(result.reports.length).toBeLessThanOrEqual(5); @@ -7040,13 +7047,13 @@ describe('OptionsListUtils', () => { }, }; - const result = createFilteredOptionList(PERSONAL_DETAILS, reportsWithDates, CURRENT_USER_ACCOUNT_ID, undefined, {}, {maxRecentReports: 3}); + const result = createFilteredOptionList(PERSONAL_DETAILS, reportsWithDates, CURRENT_USER_ACCOUNT_ID, undefined, {}, undefined, {maxRecentReports: 3}); expect(result.reports.length).toBeGreaterThan(0); }); it('should include personal details when includeP2P is true', () => { - const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, {}, {includeP2P: true}); + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, {}, undefined, {includeP2P: true}); expect(result).toBeDefined(); expect(result.personalDetails).toBeDefined(); @@ -7054,21 +7061,21 @@ describe('OptionsListUtils', () => { }); it('should exclude personal details when includeP2P is false', () => { - const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, {}, {includeP2P: false}); + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, {}, undefined, {includeP2P: false}); expect(result).toBeDefined(); expect(result.personalDetails.length).toBe(0); }); it('should handle empty reports collection', () => { - const result = createFilteredOptionList(PERSONAL_DETAILS, {}, CURRENT_USER_ACCOUNT_ID, undefined, {}); + const result = createFilteredOptionList(PERSONAL_DETAILS, {}, CURRENT_USER_ACCOUNT_ID, undefined, {}, undefined); expect(result).toBeDefined(); expect(result.reports.length).toBe(0); }); it('should handle undefined reports collection', () => { - const result = createFilteredOptionList(PERSONAL_DETAILS, undefined, CURRENT_USER_ACCOUNT_ID, undefined, {}); + const result = createFilteredOptionList(PERSONAL_DETAILS, undefined, CURRENT_USER_ACCOUNT_ID, undefined, {}, undefined); expect(result).toBeDefined(); expect(result.reports.length).toBe(0); @@ -7094,19 +7101,19 @@ describe('OptionsListUtils', () => { [`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}999`]: DateUtils.getDBTime(), }; - const result = createFilteredOptionList(PERSONAL_DETAILS, reportsCollection, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchivedMap, {maxRecentReports: 10}); + const result = createFilteredOptionList(PERSONAL_DETAILS, reportsCollection, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchivedMap, undefined, {maxRecentReports: 10}); expect(result).toBeDefined(); }); it('should handle searchTerm filtering', () => { - const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, {}, {searchTerm: 'Spider'}); + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, {}, undefined, {searchTerm: 'Spider'}); expect(result).toBeDefined(); }); it('should return both reports and personal details', () => { - const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, {}); + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, {}, undefined); expect(result).toBeDefined(); expect(result).toHaveProperty('reports'); @@ -7160,4 +7167,85 @@ describe('OptionsListUtils', () => { expect(johnSmith).toBeDefined(); }); }); + + describe('policy parameter passing', () => { + it('createOptionList should accept policiesCollection parameter', () => { + const result = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS, allPolicies, MOCK_REPORT_ATTRIBUTES_DERIVED); + expect(result).toBeDefined(); + expect(result.reports).toBeDefined(); + expect(result.personalDetails).toBeDefined(); + }); + + it('createFilteredOptionList should accept policiesCollection parameter', () => { + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, allPolicies); + expect(result).toBeDefined(); + expect(result.reports).toBeDefined(); + expect(result.personalDetails).toBeDefined(); + }); + + it('createOptionFromReport should accept policy parameter', () => { + const report: Report = { + reportID: '10', + reportName: 'Policy Report', + type: CONST.REPORT.TYPE.CHAT, + policyID, + participants: { + [CURRENT_USER_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + 1: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + }, + }; + + const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined, POLICY); + expect(result).toBeDefined(); + expect(result.policyID).toBe(policyID); + }); + + it('getReportDisplayOption should accept policy parameter', () => { + const report: Report = { + reportID: '10', + reportName: 'Display Option Policy Report', + type: CONST.REPORT.TYPE.CHAT, + policyID, + participants: { + [CURRENT_USER_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + 1: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + }, + }; + + const result = getReportDisplayOption(report, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, undefined, undefined, POLICY); + expect(result).toBeDefined(); + expect(result.policyID).toBe(policyID); + }); + + it('getPolicyExpenseReportOption should accept policy parameter', () => { + const report: Report = { + reportID: '10', + reportName: "SHIELD's workspace", + type: CONST.REPORT.TYPE.EXPENSE, + policyID, + ownerAccountID: 1, + participants: { + [CURRENT_USER_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + 1: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + }, + }; + + const participant = { + accountID: CURRENT_USER_ACCOUNT_ID, + reportID: '10', + isPolicyExpenseChat: true, + selected: true, + }; + + const result = getPolicyExpenseReportOption(participant, undefined, CURRENT_USER_ACCOUNT_ID, PERSONAL_DETAILS, report, undefined, POLICY); + expect(result).toBeDefined(); + expect(result.policyID).toBe(policyID); + }); + + it('formatSectionsFromSearchTerm should accept policy parameter', () => { + const result = formatSectionsFromSearchTerm('', [], [], [], {}, CURRENT_USER_ACCOUNT_ID, POLICY, PERSONAL_DETAILS, true); + expect(result).toBeDefined(); + expect(result.section).toBeDefined(); + }); + }); }); From 351935d2b4eecea7268c806fabf94f0bc8abe81a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 10 Mar 2026 16:54:56 +0700 Subject: [PATCH 02/10] disable max params error --- src/libs/OptionsListUtils/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 3c90fda77f75..8f11e6c180d5 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -948,7 +948,7 @@ function getLastMessageTextForReport({ /** * Creates a report list option - optimized for SearchOption context */ -// eslint-disable-next-line max-params +// eslint-disable-next-line @typescript-eslint/max-params function createOption( accountIDs: number[], personalDetails: OnyxInputOrEntry, @@ -2933,6 +2933,7 @@ function shouldOptionShowTooltip(option: SearchOptionData): boolean { /** * Handles the logic for displaying selected participants from the search term */ +// eslint-disable-next-line @typescript-eslint/max-params function formatSectionsFromSearchTerm( searchTerm: string, selectedOptions: SearchOptionData[], From dbef844e6fc4f3389ddcd8e1915639af6b4a3b85 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 11 Mar 2026 14:14:34 +0700 Subject: [PATCH 03/10] lint fix --- src/components/Search/SearchRouter/SearchRouter.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Search/SearchRouter/SearchRouter.tsx b/src/components/Search/SearchRouter/SearchRouter.tsx index 904caf1e586e..426d4453afb8 100644 --- a/src/components/Search/SearchRouter/SearchRouter.tsx +++ b/src/components/Search/SearchRouter/SearchRouter.tsx @@ -174,6 +174,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla personalDetails, currentUserAccountID, privateIsArchivedMap, + policies, ], ); From 05c27d4c9f6b4447796fd67eb20433fd90246f3c Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 12 Mar 2026 23:31:54 +0700 Subject: [PATCH 04/10] lint fix --- src/pages/iou/request/MoneyRequestAccountantSelector.tsx | 1 + src/pages/iou/request/MoneyRequestParticipantsSelector.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx index 49dc7738e9e6..95b86f2ae9db 100644 --- a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx @@ -241,6 +241,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType privateIsArchivedMap, currentUserAccountID, currentUserEmail, + policy, ]); const selectAccountant = useCallback( diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index d0a8b970f09a..719f2c1c0836 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -406,6 +406,7 @@ function MoneyRequestParticipantsSelector({ privateIsArchivedMap, currentUserAccountID, currentUserEmail, + policy, ]); /** From a408f2f10037d719c3dfa37d10c1ae75bd804f3b Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 19 Mar 2026 10:20:31 +0700 Subject: [PATCH 05/10] update comments --- .../Search/SearchFiltersChatsSelector.tsx | 2 +- .../SearchFiltersParticipantsSelector.tsx | 3 ++- src/libs/OptionsListUtils/index.ts | 24 ++++++++++++++++--- src/pages/NewChatPage.tsx | 3 ++- .../MoneyRequestAccountantSelector.tsx | 15 +++++++++--- .../request/MoneyRequestAttendeeSelector.tsx | 14 +++++++++-- .../MoneyRequestParticipantsSelector.tsx | 15 +++++++++--- 7 files changed, 62 insertions(+), 14 deletions(-) diff --git a/src/components/Search/SearchFiltersChatsSelector.tsx b/src/components/Search/SearchFiltersChatsSelector.tsx index 883ef8bccdb5..ecddfa0e045f 100644 --- a/src/components/Search/SearchFiltersChatsSelector.tsx +++ b/src/components/Search/SearchFiltersChatsSelector.tsx @@ -113,7 +113,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen chatOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, - undefined, + allPolicies, personalDetails, false, undefined, diff --git a/src/components/Search/SearchFiltersParticipantsSelector.tsx b/src/components/Search/SearchFiltersParticipantsSelector.tsx index abe96786388b..6fc193699c28 100644 --- a/src/components/Search/SearchFiltersParticipantsSelector.tsx +++ b/src/components/Search/SearchFiltersParticipantsSelector.tsx @@ -207,7 +207,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate, chatOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, - undefined, + allPolicies, personalDetails, true, undefined, @@ -270,6 +270,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate, selectedOptions, chatOptions, personalDetails, + allPolicies, reportAttributesDerived, translate, formatPhoneNumber, diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index bcb5de4f8626..8552359e0d8b 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -2935,7 +2935,7 @@ function formatSectionsFromSearchTerm( filteredPersonalDetails: SearchOptionData[], privateIsArchivedMap: Record, currentUserAccountID: number, - policy: OnyxEntry, + allPolicies: OnyxCollection, personalDetails: OnyxEntry = {}, shouldGetOptionDetails = false, filteredWorkspaceChats: SearchOptionData[] = [], @@ -2956,7 +2956,16 @@ function formatSectionsFromSearchTerm( // TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378) const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`]; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport?.reportID}`]; - return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, policy, reportAttributesDerived); + const expenseReportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${expenseReport?.policyID}`]; + return getPolicyExpenseReportOption( + participant, + privateIsArchived, + currentUserAccountID, + personalDetails, + expenseReport, + expenseReportPolicy, + reportAttributesDerived, + ); } return getParticipantsOption(participant, personalDetails); }) @@ -2988,7 +2997,16 @@ function formatSectionsFromSearchTerm( // TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378) const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`]; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport?.reportID}`]; - return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, policy, reportAttributesDerived); + const expenseReportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${expenseReport?.policyID}`]; + return getPolicyExpenseReportOption( + participant, + privateIsArchived, + currentUserAccountID, + personalDetails, + expenseReport, + expenseReportPolicy, + reportAttributesDerived, + ); } return getParticipantsOption(participant, personalDetails); }) diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index d53ceec62406..d7ed50473a16 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -241,6 +241,7 @@ function NewChatPage({ref}: NewChatPageProps) { const personalData = useCurrentUserPersonalDetails(); const currentUserAccountID = personalData.accountID; const {top} = useSafeAreaInsets(); + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false}); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); @@ -281,7 +282,7 @@ function NewChatPage({ref}: NewChatPageProps) { personalDetails, privateIsArchivedMap, currentUserAccountID, - undefined, + allPolicies, allPersonalDetails, undefined, undefined, diff --git a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx index 3c82cd6bd878..5d31a99d3c85 100644 --- a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx @@ -146,6 +146,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType }, [areOptionsInitialized, defaultOptions, debouncedSearchTerm, countryCode, loginList, currentUserAccountID, currentUserEmail, personalDetails]); const {userToInviteExpenseReport} = useUserToInviteReports(chatOptions?.userToInvite); + const userToInviteExpenseReportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${userToInviteExpenseReport?.policyID}`]; /** * Returns the sections needed for the OptionsSelector @@ -166,7 +167,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType chatOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, - policy, + allPolicies, personalDetails, true, undefined, @@ -199,7 +200,15 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType const isPolicyExpenseChat = participant?.isPolicyExpenseChat ?? false; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${userToInviteExpenseReport?.reportID}`]; return isPolicyExpenseChat - ? getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, userToInviteExpenseReport, policy, reportAttributesDerived) + ? getPolicyExpenseReportOption( + participant, + privateIsArchived, + currentUserAccountID, + personalDetails, + userToInviteExpenseReport, + userToInviteExpenseReportPolicy, + reportAttributesDerived, + ) : getParticipantsOption(participant, personalDetails); }), sectionIndex: 3, @@ -231,7 +240,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType privateIsArchivedMap, currentUserAccountID, currentUserEmail, - policy, + allPolicies, ]); const selectAccountant = useCallback( diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index e8d2408511dd..795a30babe77 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -66,6 +66,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde const {didScreenTransitionEnd} = useScreenWrapperTransitionStatus(); const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE); const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [recentAttendees] = useOnyx(ONYXKEYS.NVP_RECENT_ATTENDEES); const policy = usePolicy(activePolicyID); const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false}); @@ -155,6 +156,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde } const {userToInviteExpenseReport} = useUserToInviteReports(orderedAvailableOptions?.userToInvite); + const userToInviteExpenseReportPolicy = usePolicy(userToInviteExpenseReport?.policyID); const shouldShowErrorMessage = selectedOptions.length < 1; @@ -211,7 +213,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde orderedAvailableOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, - policy, + allPolicies, personalDetails, true, undefined, @@ -258,7 +260,15 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde const isPolicyExpenseChat = participant?.isPolicyExpenseChat ?? false; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${userToInviteExpenseReport?.reportID}`]; return isPolicyExpenseChat - ? getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, userToInviteExpenseReport, policy, reportAttributesDerived) + ? getPolicyExpenseReportOption( + participant, + privateIsArchived, + currentUserAccountID, + personalDetails, + userToInviteExpenseReport, + userToInviteExpenseReportPolicy, + reportAttributesDerived, + ) : getParticipantsOption(participant, personalDetails); }) as OptionData[], sectionIndex: 3, diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index 9d26ac39cbf8..fd76d97d6df3 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -250,6 +250,7 @@ function MoneyRequestParticipantsSelector({ const cleanSearchTerm = useMemo(() => debouncedSearchTerm.trim().toLowerCase(), [debouncedSearchTerm]); const {userToInviteExpenseReport} = useUserToInviteReports(availableOptions?.userToInvite); + const userToInviteExpenseReportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${userToInviteExpenseReport?.policyID}`]; useEffect(() => { searchUserInServer(debouncedSearchTerm.trim()); @@ -303,7 +304,7 @@ function MoneyRequestParticipantsSelector({ [], privateIsArchivedMap, currentUserAccountID, - policy, + allPolicies, personalDetails, true, undefined, @@ -369,7 +370,15 @@ function MoneyRequestParticipantsSelector({ const isPolicyExpenseChat = participant?.isPolicyExpenseChat ?? false; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${userToInviteExpenseReport?.reportID}`]; return isPolicyExpenseChat - ? getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, userToInviteExpenseReport, policy, reportAttributesDerived) + ? getPolicyExpenseReportOption( + participant, + privateIsArchived, + currentUserAccountID, + personalDetails, + userToInviteExpenseReport, + userToInviteExpenseReportPolicy, + reportAttributesDerived, + ) : getParticipantsOption(participant, personalDetails); }), sectionIndex: 5, @@ -405,7 +414,7 @@ function MoneyRequestParticipantsSelector({ privateIsArchivedMap, currentUserAccountID, currentUserEmail, - policy, + allPolicies, ]); /** From 6c8c7a663bcab8b0338086437fd4bb6cb13b842e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 19 Mar 2026 10:35:10 +0700 Subject: [PATCH 06/10] update test --- tests/perf-test/OptionsListUtils.perf-test.ts | 9 ++++++--- tests/unit/OptionsListUtilsTest.tsx | 2 +- tests/unit/SearchAutocompleteListTest.tsx | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/perf-test/OptionsListUtils.perf-test.ts b/tests/perf-test/OptionsListUtils.perf-test.ts index 5cf128713122..f1b61a8fe9c8 100644 --- a/tests/perf-test/OptionsListUtils.perf-test.ts +++ b/tests/perf-test/OptionsListUtils.perf-test.ts @@ -272,14 +272,17 @@ describe('OptionsListUtils', () => { test('[OptionsListUtils] createFilteredOptionList', async () => { await waitForBatchedUpdates(); await measureFunction(() => - createFilteredOptionList(personalDetails, mockedReportsMap, MOCK_CURRENT_USER_ACCOUNT_ID, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, {maxRecentReports: 500, searchTerm: ''}), + createFilteredOptionList(personalDetails, mockedReportsMap, MOCK_CURRENT_USER_ACCOUNT_ID, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, undefined, { + maxRecentReports: 500, + searchTerm: '', + }), ); }); test('[OptionsListUtils] createFilteredOptionList with searchTerm', async () => { await waitForBatchedUpdates(); await measureFunction(() => - createFilteredOptionList(personalDetails, mockedReportsMap, MOCK_CURRENT_USER_ACCOUNT_ID, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, { + createFilteredOptionList(personalDetails, mockedReportsMap, MOCK_CURRENT_USER_ACCOUNT_ID, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, undefined, { maxRecentReports: 500, searchTerm: SEARCH_VALUE, }), @@ -288,7 +291,7 @@ describe('OptionsListUtils', () => { test('[OptionsListUtils] getSearchOptions with searchTerm', async () => { await waitForBatchedUpdates(); - const optionLists = createFilteredOptionList(personalDetails, mockedReportsMap, MOCK_CURRENT_USER_ACCOUNT_ID, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, { + const optionLists = createFilteredOptionList(personalDetails, mockedReportsMap, MOCK_CURRENT_USER_ACCOUNT_ID, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, undefined, { maxRecentReports: 500, searchTerm: SEARCH_VALUE, }); diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index e64e55ec492a..60ab983db3db 100644 --- a/tests/unit/OptionsListUtilsTest.tsx +++ b/tests/unit/OptionsListUtilsTest.tsx @@ -6966,7 +6966,7 @@ describe('OptionsListUtils', () => { }); it('formatSectionsFromSearchTerm should accept policy parameter', () => { - const result = formatSectionsFromSearchTerm('', [], [], [], {}, CURRENT_USER_ACCOUNT_ID, POLICY, PERSONAL_DETAILS, true); + const result = formatSectionsFromSearchTerm('', [], [], [], {}, CURRENT_USER_ACCOUNT_ID, allPolicies, PERSONAL_DETAILS, true); expect(result).toBeDefined(); expect(result.section).toBeDefined(); }); diff --git a/tests/unit/SearchAutocompleteListTest.tsx b/tests/unit/SearchAutocompleteListTest.tsx index 8889accc30be..15b938cb5537 100644 --- a/tests/unit/SearchAutocompleteListTest.tsx +++ b/tests/unit/SearchAutocompleteListTest.tsx @@ -119,7 +119,7 @@ const mockedReports = getMockedReports(10); const mockedBetas = Object.values(CONST.BETAS); const mockedPersonalDetails = getMockedPersonalDetails(10); const EMPTY_PRIVATE_IS_ARCHIVED_MAP: PrivateIsArchivedMap = {}; -const mockedOptions = createOptionList(mockedPersonalDetails, MOCK_CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, mockedReports); +const mockedOptions = createOptionList(mockedPersonalDetails, MOCK_CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, mockedReports, undefined); const mockOnClose = jest.fn(); From cb79ad8bf7ce42f0ffa8a79c4d4cf8e6b5b5ee47 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 19 Mar 2026 10:47:49 +0700 Subject: [PATCH 07/10] lint fix --- src/components/OptionListContextProvider.tsx | 2 +- src/pages/iou/request/MoneyRequestAccountantSelector.tsx | 3 +-- src/pages/iou/request/MoneyRequestParticipantsSelector.tsx | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/OptionListContextProvider.tsx b/src/components/OptionListContextProvider.tsx index a7c1387fc649..aa8eb937d4a7 100644 --- a/src/components/OptionListContextProvider.tsx +++ b/src/components/OptionListContextProvider.tsx @@ -183,7 +183,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { reports: Array.from(updatedReportsMap.values()), }; }); - }, [changedReportActions, personalDetails, currentUserAccountID, reports, reportAttributes?.reports, privateIsArchivedMap]); + }, [changedReportActions, personalDetails, currentUserAccountID, reports, allPolicies, reportAttributes?.reports, privateIsArchivedMap]); /** * This effect is used to update the options list when personal details change. diff --git a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx index 5d31a99d3c85..4936cdff5357 100644 --- a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx @@ -72,8 +72,6 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType const currentUserEmail = currentUserPersonalDetails.email ?? ''; const currentUserAccountID = currentUserPersonalDetails.accountID; const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); - const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); - const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`]; const privateIsArchivedMap = usePrivateIsArchivedMap(); useEffect(() => { @@ -233,6 +231,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType debouncedSearchTerm, personalDetails, userToInviteExpenseReport, + userToInviteExpenseReportPolicy, reportAttributesDerived, translate, loginList, diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index fd76d97d6df3..e5e5e4b051f7 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -405,6 +405,7 @@ function MoneyRequestParticipantsSelector({ availableOptions.recentReports, availableOptions.personalDetails, userToInviteExpenseReport, + userToInviteExpenseReportPolicy, isWorkspacesOnly, loginList, isPerDiemRequest, From 6c1846c7d66e7b5a8540dad52213eb7e20c079ec Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 23 Mar 2026 18:22:05 +0700 Subject: [PATCH 08/10] add comments --- src/libs/OptionsListUtils/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index e291088a78e9..728319f0f2ba 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -2913,6 +2913,7 @@ function shouldOptionShowTooltip(option: SearchOptionData): boolean { /** * Handles the logic for displaying selected participants from the search term */ +// We'll refactor this function to have less parameters in the future (https://github.com/Expensify/App/issues/66415) // eslint-disable-next-line @typescript-eslint/max-params function formatSectionsFromSearchTerm( searchTerm: string, From 4130a4468d247dee63940745d115f923ceaa79d7 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 23 Mar 2026 18:40:44 +0700 Subject: [PATCH 09/10] merge main --- src/components/Search/SearchFiltersParticipantsSelector.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Search/SearchFiltersParticipantsSelector.tsx b/src/components/Search/SearchFiltersParticipantsSelector.tsx index c31ec0cab3df..3a587403a22e 100644 --- a/src/components/Search/SearchFiltersParticipantsSelector.tsx +++ b/src/components/Search/SearchFiltersParticipantsSelector.tsx @@ -68,7 +68,8 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate, const currentUserAccountID = currentUserPersonalDetails.accountID; const currentUserEmail = currentUserPersonalDetails.email ?? ''; const [recentAttendees] = useOnyx(ONYXKEYS.NVP_RECENT_ATTENDEES); - + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); + // Transform raw recentAttendees into Option[] format for use with getValidOptions (only for attendee filter) const recentAttendeeLists = useMemo( () => (shouldAllowNameOnlyOptions ? getFilteredRecentAttendees(personalDetails, [], recentAttendees ?? [], currentUserEmail, currentUserAccountID) : []), From eda35d8473aa2e7e36cac67c77147af58b1137aa Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 23 Mar 2026 21:35:37 +0700 Subject: [PATCH 10/10] prettier --- src/components/Search/SearchFiltersParticipantsSelector.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Search/SearchFiltersParticipantsSelector.tsx b/src/components/Search/SearchFiltersParticipantsSelector.tsx index 3a587403a22e..080598466b0a 100644 --- a/src/components/Search/SearchFiltersParticipantsSelector.tsx +++ b/src/components/Search/SearchFiltersParticipantsSelector.tsx @@ -69,7 +69,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate, const currentUserEmail = currentUserPersonalDetails.email ?? ''; const [recentAttendees] = useOnyx(ONYXKEYS.NVP_RECENT_ATTENDEES); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); - + // Transform raw recentAttendees into Option[] format for use with getValidOptions (only for attendee filter) const recentAttendeeLists = useMemo( () => (shouldAllowNameOnlyOptions ? getFilteredRecentAttendees(personalDetails, [], recentAttendees ?? [], currentUserEmail, currentUserAccountID) : []),