diff --git a/src/CONST.ts b/src/CONST.ts index a163c63404a7..0b3ac3fd0566 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1498,8 +1498,6 @@ const CONST = { ALPHABETIC_AND_LATIN_CHARS: /^[\p{Script=Latin} ]*$/u, NON_ALPHABETIC_AND_NON_LATIN_CHARS: /[^\p{Script=Latin}]/gu, ACCENT_LATIN_CHARS: /[\u00C0-\u017F]/g, - INVALID_DISPLAY_NAME_LHN: /[^\p{L}\p{N}\u00C0-\u017F\s-]/gu, - INVALID_DISPLAY_NAME_ONLY_LHN: /^[^\p{L}\p{N}\u00C0-\u017F]$/gu, POSITIVE_INTEGER: /^\d+$/, PO_BOX: /\b[P|p]?(OST|ost)?\.?\s*[O|o|0]?(ffice|FFICE)?\.?\s*[B|b][O|o|0]?[X|x]?\.?\s+[#]?(\d+)\b/, ANY_VALUE: /^.+$/, diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index f5545f402b14..27f424ad1b70 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -32,7 +32,6 @@ function LHNOptionsList({ draftComments = {}, transactionViolations = {}, onFirstItemRendered = () => {}, - reportIDsWithErrors = {}, }: LHNOptionsListProps) { const styles = useThemeStyles(); const {canUseViolations} = usePermissions(); @@ -64,7 +63,6 @@ function LHNOptionsList({ const itemComment = draftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`] ?? ''; const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(itemReportActions); const lastReportAction = sortedReportActions[0]; - const reportErrors = reportIDsWithErrors[reportID] ?? {}; // Get the transaction for the last report action let lastReportActionTransactionID = ''; @@ -93,7 +91,6 @@ function LHNOptionsList({ transactionViolations={transactionViolations} canUseViolations={canUseViolations} onLayout={onLayoutItem} - reportErrors={reportErrors} /> ); }, @@ -112,7 +109,6 @@ function LHNOptionsList({ transactionViolations, canUseViolations, onLayoutItem, - reportIDsWithErrors, ], ); diff --git a/src/components/LHNOptionsList/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHNData.tsx index a3394190d0c1..a18d5a8ec1ec 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHNData.tsx @@ -28,7 +28,6 @@ function OptionRowLHNData({ lastReportActionTransaction = {}, transactionViolations, canUseViolations, - reportErrors, ...propsToForward }: OptionRowLHNDataProps) { const reportID = propsToForward.reportID; @@ -41,11 +40,11 @@ function OptionRowLHNData({ // Note: ideally we'd have this as a dependent selector in onyx! const item = SidebarUtils.getOptionData({ report: fullReport, + reportActions, personalDetails, preferredLocale: preferredLocale ?? CONST.LOCALES.DEFAULT, policy, parentReportAction, - reportErrors, hasViolations: !!hasViolations, }); if (deepEqual(item, optionItemRef.current)) { @@ -70,7 +69,6 @@ function OptionRowLHNData({ transactionViolations, canUseViolations, receiptTransactions, - reportErrors, ]); useEffect(() => { diff --git a/src/components/LHNOptionsList/types.ts b/src/components/LHNOptionsList/types.ts index c122ab018392..58bea97f04c9 100644 --- a/src/components/LHNOptionsList/types.ts +++ b/src/components/LHNOptionsList/types.ts @@ -7,7 +7,6 @@ import type {CurrentReportIDContextValue} from '@components/withCurrentReportID' import type CONST from '@src/CONST'; import type {OptionData} from '@src/libs/ReportUtils'; import type {Locale, PersonalDetailsList, Policy, Report, ReportAction, ReportActions, Transaction, TransactionViolation} from '@src/types/onyx'; -import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; type OptionMode = ValueOf; @@ -59,9 +58,6 @@ type CustomLHNOptionsListProps = { /** Callback to fire when the list is laid out */ onFirstItemRendered: () => void; - - /** Report IDs with errors mapping to their corresponding error objects */ - reportIDsWithErrors: Record; }; type LHNOptionsListProps = CustomLHNOptionsListProps & CurrentReportIDContextValue & LHNOptionsListOnyxProps; @@ -117,9 +113,6 @@ type OptionRowLHNDataProps = { /** Callback to execute when the OptionList lays out */ onLayout?: (event: LayoutChangeEvent) => void; - - /** The report errors */ - reportErrors: OnyxCommon.Errors | undefined; }; type OptionRowLHNProps = { diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 1aa73e752eae..0646f83657e1 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -480,7 +480,7 @@ function getSearchText( /** * Get an object of error messages keyed by microtime by combining all error objects related to the report. */ -function getAllReportErrors(report: OnyxEntry, reportActions: OnyxEntry, transactions: OnyxCollection = allTransactions): OnyxCommon.Errors { +function getAllReportErrors(report: OnyxEntry, reportActions: OnyxEntry): OnyxCommon.Errors { const reportErrors = report?.errors ?? {}; const reportErrorFields = report?.errorFields ?? {}; const reportActionErrors: OnyxCommon.ErrorFields = Object.values(reportActions ?? {}).reduce( @@ -492,7 +492,7 @@ function getAllReportErrors(report: OnyxEntry, reportActions: OnyxEntry< if (parentReportAction?.actorAccountID === currentUserAccountID && ReportActionUtils.isTransactionThread(parentReportAction)) { const transactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction?.originalMessage?.IOUTransactionID : null; - const transaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; + const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; if (TransactionUtils.hasMissingSmartscanFields(transaction ?? null) && !ReportUtils.isSettled(transaction?.reportID)) { reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage'); } diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 40aa4c7247c6..ff1b96601951 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -7,7 +7,6 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetails, PersonalDetailsList, TransactionViolation} from '@src/types/onyx'; import type Beta from '@src/types/onyx/Beta'; -import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import type Policy from '@src/types/onyx/Policy'; import type Report from '@src/types/onyx/Report'; import type {ReportActions} from '@src/types/onyx/ReportAction'; @@ -58,13 +57,6 @@ function compareStringDates(a: string, b: string): 0 | 1 | -1 { return 0; } -function filterDisplayName(displayName: string): string { - if (CONST.REGEX.INVALID_DISPLAY_NAME_ONLY_LHN.test(displayName)) { - return displayName; - } - return displayName.replace(CONST.REGEX.INVALID_DISPLAY_NAME_LHN, '').trim(); -} - /** * @returns An array of reportIDs sorted in the proper order */ @@ -74,27 +66,22 @@ function getOrderedReportIDs( betas: Beta[], policies: Record, priorityMode: ValueOf, - allReportActions: OnyxCollection, + allReportActions: OnyxCollection, transactionViolations: OnyxCollection, currentPolicyID = '', policyMemberAccountIDs: number[] = [], - reportIDsWithErrors: Record = {}, - canUseViolations = false, ): string[] { const isInGSDMode = priorityMode === CONST.PRIORITY_MODE.GSD; const isInDefaultMode = !isInGSDMode; const allReportsDictValues = Object.values(allReports); - const reportIDsWithViolations = new Set(); - // Filter out all the reports that shouldn't be displayed let reportsToDisplay = allReportsDictValues.filter((report) => { const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`; - const parentReportAction = allReportActions?.[parentReportActionsKey]?.[report.parentReportActionID ?? '']; - const doesReportHaveViolations = canUseViolations && !!parentReportAction && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction); - if (doesReportHaveViolations) { - reportIDsWithViolations.add(report.reportID); - } + const parentReportActions = allReportActions?.[parentReportActionsKey]; + const parentReportAction = parentReportActions?.find((action) => action && report && action?.reportActionID === report?.parentReportActionID); + const doesReportHaveViolations = + betas.includes(CONST.BETAS.VIOLATIONS) && !!parentReportAction && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction); return ReportUtils.shouldReportBeInOptionList({ report, currentReportId: currentReportId ?? '', @@ -116,7 +103,7 @@ function getOrderedReportIDs( } // The LHN is split into four distinct groups, and each group is sorted a little differently. The groups will ALWAYS be in this order: - // 1. Pinned/GBR/RBR - Always sorted by reportDisplayName + // 1. Pinned/GBR - Always sorted by reportDisplayName // 2. Drafts - Always sorted by reportDisplayName // 3. Non-archived reports and settled IOUs // - Sorted by lastVisibleActionCreated in default (most recent) view mode @@ -124,7 +111,7 @@ function getOrderedReportIDs( // 4. Archived reports // - Sorted by lastVisibleActionCreated in default (most recent) view mode // - Sorted by reportDisplayName in GSD (focus) view mode - const pinnedAndBrickRoadReports: Report[] = []; + const pinnedAndGBRReports: Report[] = []; const draftReports: Report[] = []; const nonArchivedReports: Report[] = []; const archivedReports: Report[] = []; @@ -140,14 +127,12 @@ function getOrderedReportIDs( // However, this code needs to be very performant to handle thousands of reports, so in the interest of speed, we're just going to disable this lint rule and add // the reportDisplayName property to the report object directly. // eslint-disable-next-line no-param-reassign - report.displayName = filterDisplayName(ReportUtils.getReportName(report)); - - const hasRBR = report.reportID in reportIDsWithErrors || reportIDsWithViolations.has(report.reportID); + report.displayName = ReportUtils.getReportName(report); const isPinned = report.isPinned ?? false; const reportAction = ReportActionsUtils.getReportAction(report.parentReportID ?? '', report.parentReportActionID ?? ''); - if (isPinned || hasRBR || ReportUtils.requiresAttentionFromCurrentUser(report, reportAction)) { - pinnedAndBrickRoadReports.push(report); + if (isPinned || ReportUtils.requiresAttentionFromCurrentUser(report, reportAction)) { + pinnedAndGBRReports.push(report); } else if (report.hasDraft) { draftReports.push(report); } else if (ReportUtils.isArchivedRoom(report)) { @@ -158,7 +143,7 @@ function getOrderedReportIDs( }); // Sort each group of reports accordingly - pinnedAndBrickRoadReports.sort((a, b) => (a?.displayName && b?.displayName ? localeCompare(a.displayName, b.displayName) : 0)); + pinnedAndGBRReports.sort((a, b) => (a?.displayName && b?.displayName ? localeCompare(a.displayName, b.displayName) : 0)); draftReports.sort((a, b) => (a?.displayName && b?.displayName ? localeCompare(a.displayName, b.displayName) : 0)); if (isInDefaultMode) { @@ -179,7 +164,7 @@ function getOrderedReportIDs( // Now that we have all the reports grouped and sorted, they must be flattened into an array and only return the reportID. // The order the arrays are concatenated in matters and will determine the order that the groups are displayed in the sidebar. - const LHNReports = [...pinnedAndBrickRoadReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report.reportID); + const LHNReports = [...pinnedAndGBRReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report.reportID); return LHNReports; } @@ -188,19 +173,19 @@ function getOrderedReportIDs( */ function getOptionData({ report, + reportActions, personalDetails, preferredLocale, policy, parentReportAction, - reportErrors, hasViolations, }: { report: OnyxEntry; + reportActions: OnyxEntry; personalDetails: OnyxEntry; preferredLocale: DeepValueOf; policy: OnyxEntry | undefined; parentReportAction: OnyxEntry | undefined; - reportErrors: OnyxCommon.Errors | undefined; hasViolations: boolean; }): ReportUtils.OptionData | undefined { // When a user signs out, Onyx is cleared. Due to the lazy rendering with a virtual list, it's possible for @@ -213,7 +198,7 @@ function getOptionData({ const result: ReportUtils.OptionData = { text: '', alternateText: null, - allReportErrors: reportErrors, + allReportErrors: OptionsListUtils.getAllReportErrors(report, reportActions), brickRoadIndicator: null, tooltipText: null, subtitle: null, diff --git a/src/pages/home/sidebar/SidebarLinks.js b/src/pages/home/sidebar/SidebarLinks.js index 0a97f00c5002..e872bbad008a 100644 --- a/src/pages/home/sidebar/SidebarLinks.js +++ b/src/pages/home/sidebar/SidebarLinks.js @@ -43,7 +43,7 @@ const propTypes = { isActiveReport: PropTypes.func.isRequired, }; -function SidebarLinks({onLinkClick, insets, optionListItems, isLoading, priorityMode = CONST.PRIORITY_MODE.DEFAULT, isActiveReport, isCreateMenuOpen, activePolicy, reportIDsWithErrors}) { +function SidebarLinks({onLinkClick, insets, optionListItems, isLoading, priorityMode = CONST.PRIORITY_MODE.DEFAULT, isActiveReport, isCreateMenuOpen, activePolicy}) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const modal = useRef({}); @@ -154,7 +154,6 @@ function SidebarLinks({onLinkClick, insets, optionListItems, isLoading, priority shouldDisableFocusOptions={isSmallScreenWidth} optionMode={viewMode} onFirstItemRendered={App.setSidebarLoaded} - reportIDsWithErrors={reportIDsWithErrors} /> {isLoading && optionListItems.length === 0 && ( diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index 3a1b17aa7fbd..c4cc0713c596 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -1,6 +1,6 @@ import {deepEqual} from 'fast-equals'; import lodashGet from 'lodash/get'; -import lodashMapValues from 'lodash/mapValues'; +import lodashMap from 'lodash/map'; import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useMemo, useRef} from 'react'; import {View} from 'react-native'; @@ -13,11 +13,9 @@ import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultPro import withNavigationFocus from '@components/withNavigationFocus'; import useActiveWorkspace from '@hooks/useActiveWorkspace'; import useLocalize from '@hooks/useLocalize'; -import usePermissions from '@hooks/usePermissions'; import usePrevious from '@hooks/usePrevious'; import useThemeStyles from '@hooks/useThemeStyles'; import compose from '@libs/compose'; -import * as OptionsListUtils from '@libs/OptionsListUtils'; import {getPolicyMembersByIdWithoutCurrentUser} from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; import SidebarUtils from '@libs/SidebarUtils'; @@ -37,11 +35,20 @@ const propTypes = { /** All report actions for all reports */ /** Object of report actions for this report */ - // eslint-disable-next-line react/forbid-prop-types - allReportActions: PropTypes.object, - - // eslint-disable-next-line react/forbid-prop-types - allTransactions: PropTypes.object, + allReportActions: PropTypes.objectOf( + PropTypes.arrayOf( + PropTypes.shape({ + error: PropTypes.string, + message: PropTypes.arrayOf( + PropTypes.shape({ + moderationDecision: PropTypes.shape({ + decision: PropTypes.string, + }), + }), + ), + }), + ), + ), /** Whether the reports are loading. When false it means they are ready to be used. */ isLoadingApp: PropTypes.bool, @@ -98,14 +105,12 @@ const defaultProps = { policyMembers: {}, transactionViolations: {}, allReportActions: {}, - allTransactions: {}, ...withCurrentUserPersonalDetailsDefaultProps, }; function SidebarLinksData({ isFocused, allReportActions, - allTransactions, betas, chatReports, currentReportID, @@ -123,30 +128,12 @@ function SidebarLinksData({ const {activeWorkspaceID} = useActiveWorkspace(); const {translate} = useLocalize(); const prevPriorityMode = usePrevious(priorityMode); - const {canUseViolations} = usePermissions(); const policyMemberAccountIDs = getPolicyMembersByIdWithoutCurrentUser(policyMembers, activeWorkspaceID, currentUserPersonalDetails.accountID); // eslint-disable-next-line react-hooks/exhaustive-deps useEffect(() => Policy.openWorkspace(activeWorkspaceID, policyMemberAccountIDs), [activeWorkspaceID]); - const reportIDsWithErrors = useMemo(() => { - const reportKeys = _.keys(chatReports); - return _.reduce( - reportKeys, - (errorsMap, reportKey) => { - const report = chatReports[reportKey]; - const allReportsActions = allReportActions[reportKey.replace(ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.COLLECTION.REPORT_ACTIONS)]; - const errors = OptionsListUtils.getAllReportErrors(report, allReportsActions, allTransactions) || {}; - if (_.size(errors) === 0) { - return errorsMap; - } - return {...errorsMap, [reportKey.replace(ONYXKEYS.COLLECTION.REPORT, '')]: errors}; - }, - {}, - ); - }, [allReportActions, allTransactions, chatReports]); - const reportIDsRef = useRef(null); const isLoading = isLoadingApp; const optionListItems = useMemo(() => { @@ -160,8 +147,6 @@ function SidebarLinksData({ transactionViolations, activeWorkspaceID, policyMemberAccountIDs, - reportIDsWithErrors, - canUseViolations, ); if (deepEqual(reportIDsRef.current, reportIDs)) { @@ -175,21 +160,7 @@ function SidebarLinksData({ reportIDsRef.current = reportIDs; } return reportIDsRef.current || []; - }, [ - chatReports, - betas, - policies, - priorityMode, - allReportActions, - transactionViolations, - activeWorkspaceID, - policyMemberAccountIDs, - reportIDsWithErrors, - canUseViolations, - isLoading, - network.isOffline, - prevPriorityMode, - ]); + }, [chatReports, betas, policies, priorityMode, allReportActions, transactionViolations, activeWorkspaceID, policyMemberAccountIDs, isLoading, network.isOffline, prevPriorityMode]); // We need to make sure the current report is in the list of reports, but we do not want // to have to re-generate the list every time the currentReportID changes. To do that @@ -208,25 +179,10 @@ function SidebarLinksData({ transactionViolations, activeWorkspaceID, policyMemberAccountIDs, - reportIDsWithErrors, - canUseViolations, ); } return optionListItems; - }, [ - currentReportID, - optionListItems, - chatReports, - betas, - policies, - priorityMode, - allReportActions, - transactionViolations, - activeWorkspaceID, - policyMemberAccountIDs, - reportIDsWithErrors, - canUseViolations, - ]); + }, [currentReportID, optionListItems, chatReports, betas, policies, priorityMode, allReportActions, transactionViolations, activeWorkspaceID, policyMemberAccountIDs]); const currentReportIDRef = useRef(currentReportID); currentReportIDRef.current = currentReportID; @@ -248,7 +204,6 @@ function SidebarLinksData({ isLoading={isLoading} optionListItems={optionListItemsWithCurrentReport} activeWorkspaceID={activeWorkspaceID} - reportIDsWithErrors={reportIDsWithErrors} /> ); @@ -272,7 +227,6 @@ const chatReportSelector = (report) => isPinned: report.isPinned, isHidden: report.isHidden, notificationPreference: report.notificationPreference, - errors: report.errors, errorFields: { addWorkspaceRoom: report.errorFields && report.errorFields.addWorkspaceRoom, }, @@ -294,9 +248,6 @@ const chatReportSelector = (report) => reportName: report.reportName, policyName: report.policyName, oldPolicyName: report.oldPolicyName, - isPolicyExpenseChat: report.isPolicyExpenseChat, - isOwnPolicyExpenseChat: report.isOwnPolicyExpenseChat, - isCancelledIOU: report.isCancelledIOU, // Other less obvious properites considered for sorting: ownerAccountID: report.ownerAccountID, currency: report.currency, @@ -314,7 +265,7 @@ const chatReportSelector = (report) => */ const reportActionsSelector = (reportActions) => reportActions && - lodashMapValues(reportActions, (reportAction) => { + lodashMap(reportActions, (reportAction) => { const {reportActionID, parentReportActionID, actionName, errors = [], originalMessage} = reportAction; const decision = lodashGet(reportAction, 'message[0].moderationDecision.decision'); @@ -343,24 +294,6 @@ const policySelector = (policy) => avatar: policy.avatar, }; -/** - * @param {Object} [transaction] - * @returns {Object|undefined} - */ -const transactionSelector = (transaction) => - transaction && { - reportID: transaction.reportID, - iouRequestType: transaction.iouRequestType, - comment: transaction.comment, - receipt: transaction.receipt, - merchant: transaction.merchant, - modifiedMerchant: transaction.modifiedMerchant, - amount: transaction.amount, - modifiedAmount: transaction.modifiedAmount, - created: transaction.created, - modifiedCreated: transaction.modifiedCreated, - }; - export default compose( withCurrentReportID, withCurrentUserPersonalDetails, @@ -388,11 +321,6 @@ export default compose( selector: reportActionsSelector, initialValue: {}, }, - allTransactions: { - key: ONYXKEYS.COLLECTION.TRANSACTION, - selector: transactionSelector, - initialValue: {}, - }, policies: { key: ONYXKEYS.COLLECTION.POLICY, selector: policySelector, diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index a57eaf593cff..8566abb97c7f 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -2,15 +2,13 @@ import {rand} from '@ngneat/falso'; import type {OnyxCollection} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import {measureFunction} from 'reassure'; -import * as OptionsListUtils from '@libs/OptionsListUtils'; import SidebarUtils from '@libs/SidebarUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetails, ReportActions, TransactionViolation} from '@src/types/onyx'; +import type {PersonalDetails, TransactionViolation} from '@src/types/onyx'; import type Policy from '@src/types/onyx/Policy'; import type Report from '@src/types/onyx/Report'; import type ReportAction from '@src/types/onyx/ReportAction'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; import createCollection from '../utils/collections/createCollection'; import createPersonalDetails from '../utils/collections/personalDetails'; import createRandomPolicy from '../utils/collections/policies'; @@ -56,8 +54,8 @@ const mockedBetas = Object.values(CONST.BETAS); const allReportActions = Object.fromEntries( Object.keys(reportActions).map((key) => [ `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${key}`, - { - [reportActions[key].reportActionID]: { + [ + { errors: reportActions[key].errors ?? [], message: [ { @@ -68,24 +66,13 @@ const allReportActions = Object.fromEntries( ], reportActionID: reportActions[key].reportActionID, }, - }, + ], ]), -) as unknown as OnyxCollection; +) as unknown as OnyxCollection; const currentReportId = '1'; const transactionViolations = {} as OnyxCollection; -const reportKeys = Object.keys(allReports); -const reportIDsWithErrors = reportKeys.reduce((errorsMap, reportKey) => { - const report = allReports[reportKey]; - const allReportsActions = allReportActions?.[reportKey.replace('report_', 'reportActions_')] ?? null; - const errors = OptionsListUtils.getAllReportErrors(report, allReportsActions) || {}; - if (isEmptyObject(errors)) { - return errorsMap; - } - return {...errorsMap, [reportKey.replace('report_', '')]: errors}; -}, {}); - describe('SidebarUtils', () => { beforeAll(() => { Onyx.init({ @@ -113,11 +100,11 @@ describe('SidebarUtils', () => { await measureFunction(() => SidebarUtils.getOptionData({ report, + reportActions, personalDetails, preferredLocale, policy, parentReportAction, - reportErrors: undefined, hasViolations: false, }), ); @@ -126,36 +113,12 @@ describe('SidebarUtils', () => { test('[SidebarUtils] getOrderedReportIDs on 15k reports for default priorityMode', async () => { await waitForBatchedUpdates(); await measureFunction(() => - SidebarUtils.getOrderedReportIDs( - currentReportId, - allReports, - mockedBetas, - policies, - CONST.PRIORITY_MODE.DEFAULT, - allReportActions, - transactionViolations, - undefined, - undefined, - reportIDsWithErrors, - ), + SidebarUtils.getOrderedReportIDs(currentReportId, allReports, mockedBetas, policies, CONST.PRIORITY_MODE.DEFAULT, allReportActions, transactionViolations), ); }); test('[SidebarUtils] getOrderedReportIDs on 15k reports for GSD priorityMode', async () => { await waitForBatchedUpdates(); - await measureFunction(() => - SidebarUtils.getOrderedReportIDs( - currentReportId, - allReports, - mockedBetas, - policies, - CONST.PRIORITY_MODE.GSD, - allReportActions, - transactionViolations, - undefined, - undefined, - reportIDsWithErrors, - ), - ); + await measureFunction(() => SidebarUtils.getOrderedReportIDs(currentReportId, allReports, mockedBetas, policies, CONST.PRIORITY_MODE.GSD, allReportActions, transactionViolations)); }); });