diff --git a/src/components/OptionListContextProvider.tsx b/src/components/OptionListContextProvider.tsx index d0668569e104..aa8eb937d4a7 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 @@ -132,7 +133,8 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { const report = changedReportsEntries[reportKey]; const reportID = reportKey.replace(ONYXKEYS.COLLECTION.REPORT, ''); const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`]; - const {reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, reportAttributes?.reports); + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; + const {reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, policy, reportAttributes?.reports); if (reportOption) { updatedReportsMap.set(reportID, reportOption); @@ -146,7 +148,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) { @@ -168,7 +170,8 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { const reportID = key.replace(ONYXKEYS.COLLECTION.REPORT_ACTIONS, ''); const reportItem = updatedReportsMap.get(reportID)?.item; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`]; - const {reportOption} = processReport(reportItem, personalDetails, privateIsArchived, currentUserAccountID, reportAttributes?.reports); + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportItem?.policyID}`]; + const {reportOption} = processReport(reportItem, personalDetails, privateIsArchived, currentUserAccountID, policy, reportAttributes?.reports); if (reportOption) { updatedReportsMap.set(reportID, reportOption); @@ -180,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. @@ -203,6 +206,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { currentUserAccountID, privateIsArchivedMap, reports, + allPolicies, reportAttributes?.reports, ); setOptions((prevOptions) => ({ @@ -238,7 +242,8 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) { } const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]; - const newReportOption = createOptionFromReport(report, personalDetails, currentUserAccountID, privateIsArchived, reportAttributes?.reports, { + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; + const newReportOption = createOptionFromReport(report, personalDetails, currentUserAccountID, privateIsArchived, policy, reportAttributes?.reports, { showPersonalDetails: true, }); const replaceIndex = options.reports.findIndex((option) => option.reportID === report.reportID); @@ -250,7 +255,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 1daa8f660556..80a96d3bdb86 100644 --- a/src/components/Search/SearchFiltersChatsSelector.tsx +++ b/src/components/Search/SearchFiltersChatsSelector.tsx @@ -70,7 +70,10 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen const selectedOptions: OptionData[] = selectedReportIDs.map((id) => { const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${id}`]; const reportData = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`]; - const report = getSelectedOptionData(createOptionFromReport({...reportData, reportID: id}, personalDetails, currentUserAccountID, privateIsArchived, reportAttributesDerived)); + const reportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`]; + const report = getSelectedOptionData( + createOptionFromReport({...reportData, reportID: id}, personalDetails, currentUserAccountID, privateIsArchived, reportPolicy, reportAttributesDerived), + ); const isReportArchived = !!privateIsArchived; const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`]; const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`]; @@ -110,6 +113,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen chatOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, + allPolicies, personalDetails, false, undefined, diff --git a/src/components/Search/SearchFiltersParticipantsSelector.tsx b/src/components/Search/SearchFiltersParticipantsSelector.tsx index ffee0069987d..080598466b0a 100644 --- a/src/components/Search/SearchFiltersParticipantsSelector.tsx +++ b/src/components/Search/SearchFiltersParticipantsSelector.tsx @@ -68,6 +68,7 @@ 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( @@ -109,6 +110,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate, chatOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, + allPolicies, personalDetails, true, undefined, @@ -178,6 +180,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate, privateIsArchivedMap, currentUserAccountID, personalDetails, + allPolicies, reportAttributesDerived, translate, formatPhoneNumber, diff --git a/src/components/Search/SearchRouter/SearchRouter.tsx b/src/components/Search/SearchRouter/SearchRouter.tsx index b86d9b01a5e7..dfb03e9f4a21 100644 --- a/src/components/Search/SearchRouter/SearchRouter.tsx +++ b/src/components/Search/SearchRouter/SearchRouter.tsx @@ -111,7 +111,8 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla } const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${contextualReportID}`]; - const option = createOptionFromReport(report, personalDetails, currentUserAccountID, privateIsArchived, undefined, {showPersonalDetails: true}); + const reportPolicy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; + const option = createOptionFromReport(report, personalDetails, currentUserAccountID, privateIsArchived, reportPolicy, undefined, {showPersonalDetails: true}); reportForContextualSearch = option; } @@ -175,6 +176,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla personalDetails, currentUserAccountID, privateIsArchivedMap, + policies, ], ); diff --git a/src/hooks/useFilteredOptions.ts b/src/hooks/useFilteredOptions.ts index 8d3e91675060..fd1e04781d89 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(); @@ -84,14 +85,26 @@ function useFilteredOptions(config: UseFilteredOptionsConfig = {}): UseFilteredO const options: OptionList | null = useMemo( () => enabled && allReports && allPersonalDetails - ? createFilteredOptionList(allPersonalDetails, allReports, currentUserPersonalDetails.accountID, reportAttributesDerived, privateIsArchivedMap, { + ? createFilteredOptionList(allPersonalDetails, allReports, currentUserPersonalDetails.accountID, reportAttributesDerived, privateIsArchivedMap, allPolicies, { maxRecentReports: reportsLimit, includeP2P, searchTerm, betas, }) : null, - [enabled, allReports, allPersonalDetails, currentUserPersonalDetails.accountID, reportAttributesDerived, privateIsArchivedMap, reportsLimit, includeP2P, searchTerm, betas], + [ + enabled, + allReports, + allPersonalDetails, + currentUserPersonalDetails.accountID, + reportAttributesDerived, + privateIsArchivedMap, + allPolicies, + reportsLimit, + includeP2P, + searchTerm, + betas, + ], ); const hasMore = options ? reportsLimit < totalReports : false; diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 3afbecbef2f8..c39b796571c4 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -942,6 +942,7 @@ function createOption( personalDetails: OnyxInputOrEntry, report: OnyxInputOrEntry, currentUserAccountID: number, + policy: OnyxEntry, privateIsArchived: string | undefined, config?: PreviewConfig, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], @@ -1039,8 +1040,7 @@ function createOption( {showChatPreviewLine, forcePolicyNamePreview}, !!result.private_isArchived, currentUserAccountID, - // TODO: Remove this in the next PR that will refactor prepareReportOptionsForDisplay. Ref: https://github.com/Expensify/App/issues/66415 - undefined, + policy, lastActorDetails, visibleReportActionsData, translateFn, @@ -1111,6 +1111,7 @@ function getReportOption( personalDetails ?? {}, !isEmptyObject(report) ? report : undefined, currentUserAccountID, + policy, privateIsArchived, { showChatPreviewLine: false, @@ -1161,6 +1162,7 @@ function getReportDisplayOption( currentUserAccountID: number, personalDetails: OnyxEntry, privateIsArchived: string | undefined, + policy: OnyxEntry, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], policyTags?: OnyxEntry, visibleReportActionsData: VisibleReportActionsDerivedValue = {}, @@ -1172,6 +1174,7 @@ function getReportDisplayOption( personalDetails ?? {}, !isEmptyObject(report) ? report : undefined, currentUserAccountID, + policy, privateIsArchived, { showChatPreviewLine: false, @@ -1214,6 +1217,7 @@ function getPolicyExpenseReportOption( currentUserAccountID: number, personalDetails: OnyxEntry, expenseReport: OnyxEntry, + policy: OnyxEntry, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], policyTags?: OnyxEntry, visibleReportActionsData: VisibleReportActionsDerivedValue = {}, @@ -1227,6 +1231,7 @@ function getPolicyExpenseReportOption( personalDetails ?? {}, !isEmptyObject(expenseReport) ? expenseReport : null, currentUserAccountID, + policy, privateIsArchived, { showChatPreviewLine: false, @@ -1345,6 +1350,7 @@ function processReport( personalDetails: OnyxEntry, privateIsArchived: string | undefined, currentUserAccountID: number, + policy: OnyxEntry, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], policyTags?: OnyxEntry, visibleReportActionsData: VisibleReportActionsDerivedValue = {}, @@ -1371,7 +1377,7 @@ function processReport( reportMapEntry, reportOption: { item: report, - ...createOption(accountIDs, personalDetails, report, currentUserAccountID, privateIsArchived, undefined, reportAttributesDerived, policyTags, visibleReportActionsData), + ...createOption(accountIDs, personalDetails, report, currentUserAccountID, policy, privateIsArchived, undefined, reportAttributesDerived, policyTags, visibleReportActionsData), }, }; } @@ -1381,6 +1387,7 @@ function createOptionList( currentUserAccountID: number, privateIsArchivedMap: PrivateIsArchivedMap, reports: OnyxCollection, + policiesCollection: OnyxCollection, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], policyTags?: OnyxCollection, visibleReportActionsData: VisibleReportActionsDerivedValue = {}, @@ -1393,12 +1400,14 @@ function createOptionList( if (reports) { for (const report of Object.values(reports)) { const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; + const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`]; const {reportMapEntry, reportOption} = processReport( report, personalDetails, privateIsArchived, currentUserAccountID, + policy, reportAttributesDerived, reportPolicyTags, visibleReportActionsData, @@ -1418,8 +1427,8 @@ function createOptionList( const allPersonalDetailsOptions = Object.values(personalDetails ?? {}).map((personalDetail) => { const report = reportMapForAccountIDs[personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID]; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; + const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`]; - return { item: personalDetail, ...createOption( @@ -1427,6 +1436,7 @@ function createOptionList( personalDetails, report, currentUserAccountID, + policy, privateIsArchived, { showPersonalDetails: true, @@ -1478,6 +1488,7 @@ function createFilteredOptionList( currentUserAccountID: number, reportAttributesDerived: ReportAttributesDerivedValue['reports'] | undefined, privateIsArchivedMap: PrivateIsArchivedMap, + policiesCollection: OnyxCollection, options: { maxRecentReports?: number; includeP2P?: boolean; @@ -1531,12 +1542,14 @@ function createFilteredOptionList( const reportOptions: Array> = []; for (const report of sortedReports) { const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]; + const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`]; const {reportMapEntry, reportOption} = processReport( report, personalDetails, privateIsArchived, currentUserAccountID, + policy, reportAttributesDerived, reportPolicyTags, visibleReportActionsData, @@ -1569,6 +1582,7 @@ function createFilteredOptionList( const report = reportMapForAccountIDs[accountID]; const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; + const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`]; return { item: personalDetail, @@ -1577,6 +1591,7 @@ function createFilteredOptionList( personalDetails, reportMapForAccountIDs[accountID], currentUserAccountID, + policy, privateIsArchived, {showPersonalDetails: true}, reportAttributesDerived, @@ -1598,6 +1613,7 @@ function createOptionFromReport( personalDetails: OnyxEntry, currentUserAccountID: number, privateIsArchived: string | undefined, + policy: OnyxEntry, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], config?: PreviewConfig, policyTags?: OnyxEntry, @@ -1607,7 +1623,7 @@ function createOptionFromReport( return { item: report, - ...createOption(accountIDs, personalDetails, report, currentUserAccountID, privateIsArchived, config, reportAttributesDerived, policyTags, visibleReportActionsData), + ...createOption(accountIDs, personalDetails, report, currentUserAccountID, policy, privateIsArchived, config, reportAttributesDerived, policyTags, visibleReportActionsData), }; } @@ -1937,6 +1953,7 @@ function getUserToInviteOption({ null, currentUserAccountID, undefined, + undefined, {showChatPreviewLine}, undefined, undefined, @@ -2253,8 +2270,8 @@ function prepareReportOptionsForDisplay( continue; } const report = option.item; + const policy = policiesCollection?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(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. @@ -2264,8 +2281,7 @@ function prepareReportOptionsForDisplay( {showChatPreviewLine, forcePolicyNamePreview}, !!option.private_isArchived, currentUserAccountID, - // TODO: Remove this in the next PR that will refactor prepareReportOptionsForDisplay. Ref: https://github.com/Expensify/App/issues/66415 - undefined, + policy, null, visibleReportActionsData, undefined, @@ -2322,7 +2338,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; @@ -2899,6 +2914,8 @@ 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, selectedOptions: SearchOptionData[], @@ -2906,6 +2923,7 @@ function formatSectionsFromSearchTerm( filteredPersonalDetails: SearchOptionData[], privateIsArchivedMap: Record, currentUserAccountID: number, + allPolicies: OnyxCollection, personalDetails: OnyxEntry = {}, shouldGetOptionDetails = false, filteredWorkspaceChats: SearchOptionData[] = [], @@ -2926,7 +2944,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, reportAttributesDerived); + const expenseReportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${expenseReport?.policyID}`]; + return getPolicyExpenseReportOption( + participant, + privateIsArchived, + currentUserAccountID, + personalDetails, + expenseReport, + expenseReportPolicy, + reportAttributesDerived, + ); } return getParticipantsOption(participant, personalDetails); }) @@ -2958,7 +2985,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, 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 bec70bc370da..bdd15985dd47 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -242,6 +242,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 [betas] = useOnyx(ONYXKEYS.BETAS); @@ -283,6 +284,7 @@ function NewChatPage({ref}: NewChatPageProps) { personalDetails, privateIsArchivedMap, currentUserAccountID, + allPolicies, allPersonalDetails, undefined, undefined, diff --git a/src/pages/Share/ShareDetailsPage.tsx b/src/pages/Share/ShareDetailsPage.tsx index fd11ae357ad2..5d5da4577118 100644 --- a/src/pages/Share/ShareDetailsPage.tsx +++ b/src/pages/Share/ShareDetailsPage.tsx @@ -69,9 +69,10 @@ function ShareDetailsPage({route}: ShareDetailsPageProps) { const privateIsArchivedMap = usePrivateIsArchivedMap(); const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; const ancestors = useAncestors(report); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`); const displayReport = useMemo( - () => getReportDisplayOption(report, unknownUserDetails, personalDetail.accountID, personalDetails, privateIsArchived, reportAttributesDerived), - [report, unknownUserDetails, personalDetails, privateIsArchived, reportAttributesDerived, personalDetail.accountID], + () => getReportDisplayOption(report, unknownUserDetails, personalDetail.accountID, personalDetails, privateIsArchived, policy, reportAttributesDerived), + [report, unknownUserDetails, personalDetails, privateIsArchived, reportAttributesDerived, personalDetail.accountID, policy], ); const shouldShowAttachment = !isTextShared; diff --git a/src/pages/iou/SplitBillDetailsPage.tsx b/src/pages/iou/SplitBillDetailsPage.tsx index 34fb9295ddc3..0c51793f2729 100644 --- a/src/pages/iou/SplitBillDetailsPage.tsx +++ b/src/pages/iou/SplitBillDetailsPage.tsx @@ -67,6 +67,7 @@ function SplitBillDetailsPage({route, report, reportAction}: SplitBillDetailsPag const [session] = useOnyx(ONYXKEYS.SESSION); const reportAttributesDerived = useReportAttributes(); const [betas] = useOnyx(ONYXKEYS.BETAS); + 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 @@ -75,7 +76,15 @@ function SplitBillDetailsPage({route, report, reportAction}: SplitBillDetailsPag if (isPolicyExpenseChat(report)) { participants = [ getParticipantsOption({accountID: participantAccountIDs.at(0), selected: true, reportID: ''}, personalDetails), - getPolicyExpenseReportOption({...report, selected: true, reportID}, privateIsArchived, currentUserPersonalDetails.accountID, personalDetails, report, reportAttributesDerived), + getPolicyExpenseReportOption( + {...report, selected: true, reportID}, + privateIsArchived, + currentUserPersonalDetails.accountID, + personalDetails, + report, + policy, + reportAttributesDerived, + ), ]; } else { participants = participantAccountIDs.map((accountID) => getParticipantsOption({accountID, selected: true, reportID: ''}, personalDetails)); diff --git a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx index 84b66d40a921..4936cdff5357 100644 --- a/src/pages/iou/request/MoneyRequestAccountantSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAccountantSelector.tsx @@ -144,6 +144,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 @@ -164,6 +165,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType chatOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, + allPolicies, personalDetails, true, undefined, @@ -196,7 +198,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, reportAttributesDerived) + ? getPolicyExpenseReportOption( + participant, + privateIsArchived, + currentUserAccountID, + personalDetails, + userToInviteExpenseReport, + userToInviteExpenseReportPolicy, + reportAttributesDerived, + ) : getParticipantsOption(participant, personalDetails); }), sectionIndex: 3, @@ -221,6 +231,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType debouncedSearchTerm, personalDetails, userToInviteExpenseReport, + userToInviteExpenseReportPolicy, reportAttributesDerived, translate, loginList, @@ -228,6 +239,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType privateIsArchivedMap, currentUserAccountID, currentUserEmail, + allPolicies, ]); const selectAccountant = useCallback( diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index 460225f0f055..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,6 +213,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde orderedAvailableOptions.personalDetails, privateIsArchivedMap, currentUserAccountID, + allPolicies, personalDetails, true, undefined, @@ -257,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, 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 f10165931a13..e5e5e4b051f7 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,6 +304,7 @@ function MoneyRequestParticipantsSelector({ [], privateIsArchivedMap, currentUserAccountID, + allPolicies, personalDetails, true, undefined, @@ -368,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, reportAttributesDerived) + ? getPolicyExpenseReportOption( + participant, + privateIsArchived, + currentUserAccountID, + personalDetails, + userToInviteExpenseReport, + userToInviteExpenseReportPolicy, + reportAttributesDerived, + ) : getParticipantsOption(participant, personalDetails); }), sectionIndex: 5, @@ -395,6 +405,7 @@ function MoneyRequestParticipantsSelector({ availableOptions.recentReports, availableOptions.personalDetails, userToInviteExpenseReport, + userToInviteExpenseReportPolicy, isWorkspacesOnly, loginList, isPerDiemRequest, @@ -404,6 +415,7 @@ function MoneyRequestParticipantsSelector({ privateIsArchivedMap, currentUserAccountID, currentUserEmail, + allPolicies, ]); /** diff --git a/tests/perf-test/OptionsListUtils.perf-test.ts b/tests/perf-test/OptionsListUtils.perf-test.ts index 19a835e70a86..f1b61a8fe9c8 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, @@ -253,6 +253,7 @@ describe('OptionsListUtils', () => { Object.values(filteredPersonalDetails), {}, MOCK_CURRENT_USER_ACCOUNT_ID, + undefined, mockedPersonalDetails, true, ), @@ -265,20 +266,23 @@ 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)); }); 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, }), @@ -287,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/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 1239397dcc63..76650bb527dd 100644 --- a/tests/unit/OptionListContextProviderTest.tsx +++ b/tests/unit/OptionListContextProviderTest.tsx @@ -223,6 +223,6 @@ describe('OptionListContextProvider', () => { mockUsePersonalDetails.mockReturnValue(updatedPersonalDetails); rerender({shouldInitialize: false}); - expect(mockCreateOptionFromReport).toHaveBeenCalledWith(report, updatedPersonalDetails, expect.any(Number), 'true', undefined, {showPersonalDetails: true}); + expect(mockCreateOptionFromReport).toHaveBeenCalledWith(report, updatedPersonalDetails, expect.any(Number), 'true', undefined, undefined, {showPersonalDetails: true}); }); }); diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index 0e09921d573d..085822d40ea5 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, ); }); @@ -2180,7 +2185,7 @@ describe('OptionsListUtils', () => { const archivedMap: PrivateIsArchivedMap = { [`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}10`]: reportNameValuePairs.private_isArchived, }; - const OPTIONS_WITH_ARCHIVED = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, archivedMap, REPORTS, MOCK_REPORT_ATTRIBUTES_DERIVED); + const OPTIONS_WITH_ARCHIVED = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, archivedMap, REPORTS, undefined, MOCK_REPORT_ATTRIBUTES_DERIVED); // When we call getSearchOptions with all betas const options = getSearchOptions({ options: OPTIONS_WITH_ARCHIVED, @@ -2207,7 +2212,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, @@ -2288,6 +2293,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 @@ -2626,7 +2632,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({ @@ -2667,7 +2673,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({ @@ -2708,7 +2714,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({ @@ -2749,7 +2755,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({ @@ -2792,6 +2798,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 @@ -3151,7 +3158,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, @@ -3215,7 +3222,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({ @@ -3277,7 +3284,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`); @@ -3288,7 +3295,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'); @@ -3371,7 +3378,7 @@ describe('OptionsListUtils', () => { const archivedMap: PrivateIsArchivedMap = { [`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}10`]: reportNameValuePairs.private_isArchived, }; - const reports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, archivedMap, REPORTS).reports; + const reports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, archivedMap, REPORTS, undefined).reports; const archivedReport = reports.find((report) => report.reportID === '10'); // Then the returned report should contain default archived reason @@ -3387,7 +3394,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); @@ -3400,7 +3407,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); @@ -3416,7 +3423,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); @@ -3435,7 +3442,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'); @@ -3459,7 +3466,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'); @@ -3478,7 +3485,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) @@ -3499,7 +3506,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'); @@ -3515,6 +3522,25 @@ describe('OptionsListUtils', () => { // Report 2 should not have private_isArchived since it's not in the map expect(report2Option?.private_isArchived).toBeUndefined(); }); + + it('should respect maxRecentReports option while preserving archived status', () => { + renderLocaleContextProvider(); + // Given a privateIsArchivedMap and a maxRecentReports limit larger than the total reports count + // Note: Report 7 has largest lastVisibleActionCreated but is archived, so it sorts last + // (archived reports use "0_" prefix vs "1_" for non-archived in the sort comparator) + const privateIsArchivedMap: PrivateIsArchivedMap = { + [`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}7`]: '2023-12-31 23:59:59', + }; + + // When we call createFilteredOptionList with a maxRecentReports limit that includes all reports + const result = createFilteredOptionList(PERSONAL_DETAILS, REPORTS, CURRENT_USER_ACCOUNT_ID, undefined, privateIsArchivedMap, undefined, { + maxRecentReports: 20, + }); + + // Then the report 7 (most recent) should still have private_isArchived set + const report7Option = result.reports.find((r) => r.item?.reportID === '7'); + expect(report7Option?.private_isArchived).toBe('2023-12-31 23:59:59'); + }); }); describe('filterSelfDMChat()', () => { @@ -3924,7 +3950,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'); }); @@ -6196,7 +6222,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); @@ -6218,7 +6244,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); @@ -6251,7 +6277,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); @@ -6278,7 +6304,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 @@ -6306,7 +6332,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); @@ -6334,7 +6360,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); @@ -6346,7 +6372,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); }); @@ -6626,7 +6652,7 @@ describe('OptionsListUtils', () => { }; const privateIsArchived = DateUtils.getDBTime(); - const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, privateIsArchived); + const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, privateIsArchived, undefined); expect(result).toBeDefined(); expect(result.private_isArchived).toBe(privateIsArchived); @@ -6661,7 +6687,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); expect(result).toBeDefined(); expect(result.reportID).toBe('1'); @@ -6679,7 +6705,7 @@ describe('OptionsListUtils', () => { }; const config = {showPersonalDetails: true}; - const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined, config); + const result = createOptionFromReport(report, PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, undefined, undefined, undefined, config); expect(result).toBeDefined(); expect(result.reportID).toBe('1'); @@ -6688,7 +6714,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); @@ -6728,13 +6754,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(); @@ -6742,21 +6768,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); @@ -6782,9 +6808,16 @@ 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, {}, undefined, {searchTerm: 'Spider'}); expect(result).toBeDefined(); + expect(result.reports.length).toBe(Object.keys(REPORTS).length); }); it('should return all reports when searchTerm is provided (isSearching is true)', () => { @@ -6794,6 +6827,7 @@ describe('OptionsListUtils', () => { CURRENT_USER_ACCOUNT_ID, undefined, {}, + {}, { searchTerm: 'Report', maxRecentReports: 2, @@ -6805,7 +6839,7 @@ describe('OptionsListUtils', () => { }); 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'); @@ -6860,6 +6894,87 @@ describe('OptionsListUtils', () => { }); }); + 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, 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, 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, POLICY); + expect(result).toBeDefined(); + expect(result.policyID).toBe(policyID); + }); + + it('formatSectionsFromSearchTerm should accept policy parameter', () => { + const result = formatSectionsFromSearchTerm('', [], [], [], {}, CURRENT_USER_ACCOUNT_ID, allPolicies, PERSONAL_DETAILS, true); + expect(result).toBeDefined(); + expect(result.section).toBeDefined(); + }); + }); + describe('getIOUReportIDOfLastAction', () => { it('should return undefined when report is undefined', () => { const result = getIOUReportIDOfLastAction(undefined, undefined); 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();