From ef083270971242280f7dfed5396c9b0f0a687026 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 18 Dec 2024 09:22:36 +0100 Subject: [PATCH 01/18] Minor update to trigger errors --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d2ec8fb3ac62..4a2a69751f64 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3065,7 +3065,7 @@ function getAvailableReportFields(report: Report, policyReportFields: PolicyRepo * Get the title for an IOU or expense chat which will be showing the payer and the amount */ function getMoneyRequestReportName(report: OnyxEntry, policy?: OnyxEntry, invoiceReceiverPolicy?: OnyxEntry): string { - const isReportSettled = isSettled(report?.reportID ?? '-1'); + const isReportSettled = isSettled(report?.reportID); const reportFields = isReportSettled ? report?.fieldList : getReportFieldsByPolicyID(report?.policyID ?? '-1'); const titleReportField = Object.values(reportFields ?? {}).find((reportField) => reportField?.fieldID === CONST.REPORT_FIELD_TITLE_FIELD_ID); From 9fc5a78971877e6ffcf95cc38a59588570e31185 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 18 Dec 2024 12:21:30 +0100 Subject: [PATCH 02/18] Remove default ids in ReportUtils file pt1 --- .eslintrc.changed.js | 2 +- src/libs/PolicyUtils.ts | 4 +- src/libs/ReportActionsUtils.ts | 23 ++-- src/libs/ReportUtils.ts | 188 +++++++++++++++++++-------------- 4 files changed, 126 insertions(+), 91 deletions(-) diff --git a/.eslintrc.changed.js b/.eslintrc.changed.js index a72dd6a9250a..20b82de39bf7 100644 --- a/.eslintrc.changed.js +++ b/.eslintrc.changed.js @@ -10,7 +10,7 @@ module.exports = { }, overrides: [ { - files: ['src/libs/ReportUtils.ts', 'src/libs/actions/IOU.ts', 'src/libs/actions/Report.ts', 'src/libs/actions/Task.ts'], + files: ['src/libs/actions/IOU.ts', 'src/libs/actions/Report.ts', 'src/libs/actions/Task.ts'], rules: { 'rulesdir/no-default-id-values': 'off', }, diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 9bf68b2c5432..bb229547f6ed 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -243,7 +243,7 @@ const isPolicyEmployee = (policyID: string, policies: OnyxCollection): b /** * Checks if the current user is an owner (creator) of the policy. */ -const isPolicyOwner = (policy: OnyxInputOrEntry, currentUserAccountID: number): boolean => policy?.ownerAccountID === currentUserAccountID; +const isPolicyOwner = (policy: OnyxInputOrEntry, currentUserAccountID: number | undefined): boolean => !!currentUserAccountID && policy?.ownerAccountID === currentUserAccountID; /** * Create an object mapping member emails to their accountIDs. Filter for members without errors if includeMemberWithErrors is false, and get the login email from the personalDetail object using the accountID. @@ -391,7 +391,7 @@ function isPaidGroupPolicy(policy: OnyxEntry | SearchPolicy): boolean { } function getOwnedPaidPolicies(policies: OnyxCollection | null, currentUserAccountID: number): Policy[] { - return Object.values(policies ?? {}).filter((policy): policy is Policy => isPolicyOwner(policy, currentUserAccountID ?? -1) && isPaidGroupPolicy(policy)); + return Object.values(policies ?? {}).filter((policy): policy is Policy => isPolicyOwner(policy, currentUserAccountID) && isPaidGroupPolicy(policy)); } function isControlPolicy(policy: OnyxEntry): boolean { diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index dd17adbda338..76726596cbc5 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -348,7 +348,7 @@ function isInviteOrRemovedAction( /** * Returns whether the comment is a thread parent message/the first message in a thread */ -function isThreadParentMessage(reportAction: OnyxEntry, reportID: string): boolean { +function isThreadParentMessage(reportAction: OnyxEntry, reportID: string | undefined): boolean { const {childType, childVisibleActionCount = 0, childReportID} = reportAction ?? {}; return childType === CONST.REPORT.TYPE.CHAT && (childVisibleActionCount > 0 || String(childReportID) === reportID); } @@ -772,7 +772,11 @@ function replaceBaseURLInPolicyChangeLogAction(reportAction: ReportAction): Repo return updatedReportAction; } -function getLastVisibleAction(reportID: string, canUserPerformWriteAction?: boolean, actionsToMerge: Record | null> = {}): OnyxEntry { +function getLastVisibleAction( + reportID: string | undefined, + canUserPerformWriteAction?: boolean, + actionsToMerge: Record | null> = {}, +): OnyxEntry { let reportActions: Array = []; if (!isEmpty(actionsToMerge)) { reportActions = Object.values(fastMerge(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {}, actionsToMerge ?? {}, true)) as Array< @@ -802,7 +806,7 @@ function formatLastMessageText(lastMessageText: string) { } function getLastVisibleMessage( - reportID: string, + reportID: string | undefined, canUserPerformWriteAction?: boolean, actionsToMerge: Record | null> = {}, reportAction: OnyxInputOrEntry | undefined = undefined, @@ -929,7 +933,10 @@ function getLinkedTransactionID(reportActionOrID: string | OnyxEntry>([ * Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions. * Returns a reportID if there is exactly one transaction thread for the report, and null otherwise. */ -function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry | ReportAction[], isOffline: boolean | undefined = undefined): string | undefined { +function getOneTransactionThreadReportID( + reportID: string | undefined, + reportActions: OnyxEntry | ReportAction[], + isOffline: boolean | undefined = undefined, +): string | undefined { // If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report. const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE && report?.type !== CONST.REPORT.TYPE.INVOICE) { @@ -1120,7 +1131,7 @@ function doesReportHaveVisibleActions(reportID: string, canUserPerformWriteActio return visibleReportActionsWithoutTaskSystemMessage.length > 0; } -function getAllReportActions(reportID: string): ReportActions { +function getAllReportActions(reportID: string | undefined): ReportActions { return allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {}; } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 4a2a69751f64..5f572d1778a4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -611,7 +611,9 @@ let currentUserPersonalDetails: OnyxEntry; Onyx.connect({ key: ONYXKEYS.PERSONAL_DETAILS_LIST, callback: (value) => { - currentUserPersonalDetails = value?.[currentUserAccountID ?? -1] ?? undefined; + if (currentUserAccountID) { + currentUserPersonalDetails = value?.[currentUserAccountID] ?? undefined; + } allPersonalDetails = value ?? {}; allPersonalDetailLogins = Object.values(allPersonalDetails).map((personalDetail) => personalDetail?.login ?? ''); }, @@ -788,7 +790,7 @@ function isDraftReport(reportID: string | undefined): boolean { /** * Returns the report */ -function getReport(reportID: string): OnyxEntry { +function getReport(reportID: string | undefined): OnyxEntry { return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; } @@ -796,7 +798,7 @@ function getReport(reportID: string): OnyxEntry { * Returns the report */ function getReportNameValuePairs(reportID?: string): OnyxEntry { - return allReportNameValuePair?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID ?? -1}`]; + return allReportNameValuePair?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`]; } /** @@ -1618,7 +1620,11 @@ function isPolicyExpenseChatAdmin(report: OnyxEntry, policies: OnyxColle /** * Checks if the current user is the admin of the policy. */ -function isPolicyAdmin(policyID: string, policies: OnyxCollection): boolean { +function isPolicyAdmin(policyID: string | undefined, policies: OnyxCollection): boolean { + if (!policyID) { + return false; + } + const policyRole = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.role; return policyRole === CONST.POLICY.ROLE.ADMIN; @@ -1628,7 +1634,11 @@ function isPolicyAdmin(policyID: string, policies: OnyxCollection): bool * Checks whether all the transactions linked to the IOU report are of the Distance Request type with pending routes */ function hasOnlyTransactionsWithPendingRoutes(iouReportID: string | undefined): boolean { - const transactions = reportsTransactions[iouReportID ?? ''] ?? []; + if (!iouReportID) { + return false; + } + + const transactions = reportsTransactions[iouReportID] ?? []; // Early return false in case not having any transaction if (!transactions || transactions.length === 0) { @@ -1716,7 +1726,7 @@ function hasOnlyNonReimbursableTransactions(iouReportID: string | undefined): bo return false; } - const transactions = reportsTransactions[iouReportID ?? ''] ?? []; + const transactions = reportsTransactions[iouReportID] ?? []; if (!transactions || transactions.length === 0) { return false; } @@ -1727,7 +1737,7 @@ function hasOnlyNonReimbursableTransactions(iouReportID: string | undefined): bo /** * Checks if a report has only one transaction associated with it */ -function isOneTransactionReport(reportID: string): boolean { +function isOneTransactionReport(reportID: string | undefined): boolean { const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? ([] as ReportAction[]); return ReportActionsUtils.getOneTransactionThreadReportID(reportID, reportActions) !== null; } @@ -1746,7 +1756,7 @@ function isPayAtEndExpenseReport(reportID: string, transactions: Transaction[] | /** * Checks if a report is a transaction thread associated with a report that has only one transaction */ -function isOneTransactionThread(reportID: string, parentReportID: string, threadParentReportAction: OnyxEntry): boolean { +function isOneTransactionThread(reportID: string, parentReportID: string | undefined, threadParentReportAction: OnyxEntry): boolean { const parentReportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`] ?? ([] as ReportAction[]); const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(parentReportID, parentReportActions); return reportID === transactionThreadReportID && !ReportActionsUtils.isSentMoneyReportAction(threadParentReportAction); @@ -1757,8 +1767,8 @@ function isOneTransactionThread(reportID: string, parentReportID: string, thread */ function getDisplayedReportID(reportID: string): string { const report = getReport(reportID); - const parentReportID = report?.parentReportID ?? ''; - const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, report?.parentReportActionID ?? ''); + const parentReportID = report?.parentReportID; + const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, report?.parentReportActionID); return isOneTransactionThread(reportID, parentReportID, parentReportAction) ? parentReportID : reportID; } @@ -2349,6 +2359,8 @@ function getIcons( policy?: OnyxInputOrEntry, invoiceReceiverPolicy?: OnyxInputOrEntry, ): Icon[] { + const ownerDetails = report?.ownerAccountID ? personalDetails?.[report.ownerAccountID] : undefined; + if (isEmptyObject(report)) { const fallbackIcon: Icon = { source: defaultIcon ?? FallbackAvatar, @@ -2361,12 +2373,13 @@ function getIcons( if (isExpenseRequest(report)) { const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]; const workspaceIcon = getWorkspaceIcon(report, policy); + const actorAccountDetails = parentReportAction?.actorAccountID ? personalDetails?.[parentReportAction.actorAccountID] : undefined; const memberIcon = { - source: personalDetails?.[parentReportAction?.actorAccountID ?? -1]?.avatar ?? FallbackAvatar, + source: actorAccountDetails?.avatar ?? FallbackAvatar, id: parentReportAction?.actorAccountID, type: CONST.ICON_TYPE_AVATAR, - name: personalDetails?.[parentReportAction?.actorAccountID ?? -1]?.displayName ?? '', - fallbackIcon: personalDetails?.[parentReportAction?.actorAccountID ?? -1]?.fallbackIcon, + name: actorAccountDetails?.displayName ?? '', + fallbackIcon: actorAccountDetails?.fallbackIcon, }; return [memberIcon, workspaceIcon]; @@ -2375,10 +2388,11 @@ function getIcons( const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]; const actorAccountID = getReportActionActorAccountID(parentReportAction, report, report); + const actorDetails = actorAccountID ? personalDetails?.[actorAccountID] : undefined; const actorDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[actorAccountID ?? -1], '', false); const actorIcon = { id: actorAccountID, - source: personalDetails?.[actorAccountID ?? -1]?.avatar ?? FallbackAvatar, + source: actorDetails?.avatar ?? FallbackAvatar, name: LocalePhoneNumber.formatPhoneNumber(actorDisplayName), type: CONST.ICON_TYPE_AVATAR, fallbackIcon: personalDetails?.[parentReportAction?.actorAccountID ?? -1]?.fallbackIcon, @@ -2393,10 +2407,10 @@ function getIcons( if (isTaskReport(report)) { const ownerIcon = { id: report?.ownerAccountID, - source: personalDetails?.[report?.ownerAccountID ?? -1]?.avatar ?? FallbackAvatar, + source: ownerDetails?.avatar ?? FallbackAvatar, type: CONST.ICON_TYPE_AVATAR, - name: personalDetails?.[report?.ownerAccountID ?? -1]?.displayName ?? '', - fallbackIcon: personalDetails?.[report?.ownerAccountID ?? -1]?.fallbackIcon, + name: ownerDetails?.displayName ?? '', + fallbackIcon: ownerDetails?.fallbackIcon, }; if (isWorkspaceTaskReport(report)) { @@ -2443,33 +2457,34 @@ function getIcons( if (isPolicyExpenseChat(report) || isExpenseReport(report)) { const workspaceIcon = getWorkspaceIcon(report, policy); const memberIcon = { - source: personalDetails?.[report?.ownerAccountID ?? -1]?.avatar ?? FallbackAvatar, + source: ownerDetails?.avatar ?? FallbackAvatar, id: report?.ownerAccountID, type: CONST.ICON_TYPE_AVATAR, - name: personalDetails?.[report?.ownerAccountID ?? -1]?.displayName ?? '', - fallbackIcon: personalDetails?.[report?.ownerAccountID ?? -1]?.fallbackIcon, + name: ownerDetails?.displayName ?? '', + fallbackIcon: ownerDetails?.fallbackIcon, }; return isExpenseReport(report) ? [memberIcon, workspaceIcon] : [workspaceIcon, memberIcon]; } if (isIOUReport(report)) { + const managerDetails = report?.managerID ? personalDetails?.[report.managerID] : undefined; const managerIcon = { - source: personalDetails?.[report?.managerID ?? -1]?.avatar ?? FallbackAvatar, + source: managerDetails?.avatar ?? FallbackAvatar, id: report?.managerID, type: CONST.ICON_TYPE_AVATAR, - name: personalDetails?.[report?.managerID ?? -1]?.displayName ?? '', - fallbackIcon: personalDetails?.[report?.managerID ?? -1]?.fallbackIcon, + name: managerDetails?.displayName ?? '', + fallbackIcon: managerDetails?.fallbackIcon, }; const ownerIcon = { id: report?.ownerAccountID, - source: personalDetails?.[report?.ownerAccountID ?? -1]?.avatar ?? FallbackAvatar, + source: ownerDetails?.avatar ?? FallbackAvatar, type: CONST.ICON_TYPE_AVATAR, - name: personalDetails?.[report?.ownerAccountID ?? -1]?.displayName ?? '', - fallbackIcon: personalDetails?.[report?.ownerAccountID ?? -1]?.fallbackIcon, + name: ownerDetails?.displayName ?? '', + fallbackIcon: ownerDetails?.fallbackIcon, }; const isManager = currentUserAccountID === report?.managerID; // For one transaction IOUs, display a simplified report icon - if (isOneTransactionReport(report?.reportID ?? '-1')) { + if (isOneTransactionReport(report?.reportID)) { return [ownerIcon]; } @@ -2735,7 +2750,7 @@ function buildOptimisticCancelPaymentReportAction(expenseReportID: string, amoun */ function getLastVisibleMessage(reportID: string | undefined, actionsToMerge: ReportActions = {}): LastVisibleMessage { const report = getReportOrDraftReport(reportID); - const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID ?? '-1', canUserPerformWriteAction(report), actionsToMerge); + const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID, canUserPerformWriteAction(report), actionsToMerge); // For Chat Report with deleted parent actions, let us fetch the correct message if (ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && !isEmptyObject(report) && isChatReport(report)) { @@ -2746,7 +2761,7 @@ function getLastVisibleMessage(reportID: string | undefined, actionsToMerge: Rep } // Fetch the last visible message for report represented by reportID and based on actions to merge. - return ReportActionsUtils.getLastVisibleMessage(reportID ?? '-1', canUserPerformWriteAction(report), actionsToMerge); + return ReportActionsUtils.getLastVisibleMessage(reportID, canUserPerformWriteAction(report), actionsToMerge); } /** @@ -2939,7 +2954,7 @@ function getPolicyExpenseChatName(report: OnyxEntry, policy?: OnyxEntry< // If this user is not admin and this policy expense chat has been archived because of account merging, this must be an old workspace chat // of the account which was merged into the current user's account. Use the name of the policy as the name of the report. if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { - const lastAction = ReportActionsUtils.getLastVisibleAction(report?.reportID ?? '-1'); + const lastAction = ReportActionsUtils.getLastVisibleAction(report?.reportID); const archiveReason = ReportActionsUtils.isClosedAction(lastAction) ? ReportActionsUtils.getOriginalMessage(lastAction)?.reason : CONST.REPORT.ARCHIVE_REASON.DEFAULT; if (archiveReason === CONST.REPORT.ARCHIVE_REASON.ACCOUNT_MERGED && policyExpenseChatRole !== CONST.POLICY.ROLE.ADMIN) { return getPolicyName(report, false, policy); @@ -2970,7 +2985,7 @@ function isReportFieldOfTypeTitle(reportField: OnyxEntry): bo /** * Check if Report has any held expenses */ -function isHoldCreator(transaction: OnyxEntry, reportID: string): boolean { +function isHoldCreator(transaction: OnyxEntry, reportID: string | undefined): boolean { const holdReportAction = ReportActionsUtils.getReportAction(reportID, `${transaction?.comment?.hold ?? ''}`); return isActionCreator(holdReportAction); } @@ -2986,7 +3001,7 @@ function isReportFieldDisabled(report: OnyxEntry, reportField: OnyxEntry const isReportSettled = isSettled(report?.reportID); const isReportClosed = isClosedReport(report); const isTitleField = isReportFieldOfTypeTitle(reportField); - const isAdmin = isPolicyAdmin(report?.policyID ?? '-1', {[`${ONYXKEYS.COLLECTION.POLICY}${policy?.id ?? '-1'}`]: policy}); + const isAdmin = isPolicyAdmin(report?.policyID, {[`${ONYXKEYS.COLLECTION.POLICY}${policy?.id}`]: policy}); return isTitleField ? !reportField?.deletable : !isAdmin && (isReportSettled || isReportClosed); } @@ -3013,7 +3028,7 @@ function getReportFieldKey(reportFieldId: string) { /** * Get the report fields attached to the policy given policyID */ -function getReportFieldsByPolicyID(policyID: string): Record { +function getReportFieldsByPolicyID(policyID: string | undefined): Record { const policyReportFields = Object.entries(allPolicies ?? {}).find(([key]) => key.replace(ONYXKEYS.COLLECTION.POLICY, '') === policyID); const fieldList = policyReportFields?.[1]?.fieldList; @@ -3066,7 +3081,7 @@ function getAvailableReportFields(report: Report, policyReportFields: PolicyRepo */ function getMoneyRequestReportName(report: OnyxEntry, policy?: OnyxEntry, invoiceReceiverPolicy?: OnyxEntry): string { const isReportSettled = isSettled(report?.reportID); - const reportFields = isReportSettled ? report?.fieldList : getReportFieldsByPolicyID(report?.policyID ?? '-1'); + const reportFields = isReportSettled ? report?.fieldList : getReportFieldsByPolicyID(report?.policyID); const titleReportField = Object.values(reportFields ?? {}).find((reportField) => reportField?.fieldID === CONST.REPORT_FIELD_TITLE_FIELD_ID); if (titleReportField && report?.reportName && isPaidGroupPolicyExpenseReport(report)) { @@ -3203,7 +3218,7 @@ function canEditMoneyRequest(reportAction: OnyxInputOrEntry) : undefined; const isRequestIOU = isIOUReport(moneyRequestReport); - const isHoldActionCreator = isHoldCreator(transaction, reportAction.childReportID ?? '-1'); + const isHoldActionCreator = isHoldCreator(transaction, reportAction.childReportID); const isTrackExpenseMoneyReport = isTrackExpenseReport(moneyRequestReport); const isActionOwner = @@ -3351,7 +3366,7 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry) typeof currentUserPersonalDetails?.accountID === 'number' && parentReportAction.actorAccountID === currentUserPersonalDetails?.accountID; const isApprover = isMoneyRequestReport(moneyRequestReport) && moneyRequestReport?.managerID !== null && currentUserPersonalDetails?.accountID === moneyRequestReport?.managerID; - const isAdmin = isPolicyAdmin(moneyRequestReport.policyID ?? '-1', allPolicies); + const isAdmin = isPolicyAdmin(moneyRequestReport.policyID, allPolicies); const isOnHold = TransactionUtils.isOnHold(transaction); const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); const isClosed = isClosedReport(moneyRequestReport); @@ -3430,7 +3445,7 @@ function getLinkedTransaction(reportAction: OnyxEntry { if (!ReportActionsUtils.isMoneyRequestAction(action)) { @@ -3468,7 +3483,7 @@ function getReportActionWithMissingSmartscanFields(iouReportID: string): ReportA /** * Check if iouReportID has required missing fields */ -function shouldShowRBRForMissingSmartscanFields(iouReportID: string): boolean { +function shouldShowRBRForMissingSmartscanFields(iouReportID: string | undefined): boolean { return !!getReportActionWithMissingSmartscanFields(iouReportID); } @@ -3643,7 +3658,7 @@ function getReportPreviewMessage( } if (report.isWaitingOnBankAccount) { - const submitterDisplayName = getDisplayNameForParticipant(report.ownerAccountID ?? -1, true) ?? ''; + const submitterDisplayName = getDisplayNameForParticipant(report.ownerAccountID, true) ?? ''; return Localize.translateLocal('iou.waitingOnBankAccount', {submitterDisplayName}); } @@ -4018,7 +4033,7 @@ function getReportName( } const isAttachment = ReportActionsUtils.isReportActionAttachment(!isEmptyObject(parentReportAction) ? parentReportAction : undefined); - const reportActionMessage = getReportActionMessage(parentReportAction, report?.parentReportID, report?.reportID ?? '').replace(/(\n+|\r\n|\n|\r)/gm, ' '); + const reportActionMessage = getReportActionMessage(parentReportAction, report?.parentReportID, report?.reportID).replace(/(\n+|\r\n|\n|\r)/gm, ' '); if (isAttachment && reportActionMessage) { return `[${Localize.translateLocal('common.attachment')}]`; } @@ -4235,7 +4250,9 @@ function goBackToDetailsPage(report: OnyxEntry, backTo?: string) { return; } - Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report?.reportID ?? '-1', backTo)); + if (report?.reportID) { + Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report.reportID, backTo)); + } } function navigateBackOnDeleteTransaction(backRoute: Route | undefined, isFromRHP?: boolean) { @@ -4582,7 +4599,7 @@ function buildOptimisticIOUReport( const formattedTotal = CurrencyUtils.convertToDisplayString(total, currency); const personalDetails = getPersonalDetailsForAccountID(payerAccountID); const payerEmail = 'login' in personalDetails ? personalDetails.login : ''; - const policyID = getReport(chatReportID)?.policyID ?? '-1'; + const policyID = getReport(chatReportID)?.policyID; const policy = getPolicy(policyID); const participants: Participants = { @@ -5218,7 +5235,7 @@ function buildOptimisticReportPreview( childMoneyRequestCount: 1, childLastActorAccountID: currentUserAccountID, childLastMoneyRequestComment: comment, - childRecentReceiptTransactionIDs: hasReceipt && !isEmptyObject(transaction) ? {[transaction?.transactionID ?? '-1']: created} : undefined, + childRecentReceiptTransactionIDs: hasReceipt && !isEmptyObject(transaction) && transaction?.transactionID ? {[transaction.transactionID]: created} : undefined, }; } @@ -6211,7 +6228,7 @@ function buildTransactionThread( participantAccountIDs, getTransactionReportName(reportAction), undefined, - moneyRequestReport?.policyID ?? '-1', + moneyRequestReport?.policyID, CONST.POLICY.OWNER_ACCOUNT_ID_FAKE, false, '', @@ -6444,7 +6461,7 @@ function hasReportViolations(reportID: string) { function shouldAdminsRoomBeVisible(report: OnyxEntry): boolean { const accountIDs = Object.entries(report?.participants ?? {}).map(([accountID]) => Number(accountID)); const adminAccounts = PersonalDetailsUtils.getLoginsByAccountIDs(accountIDs).filter((login) => !PolicyUtils.isExpensifyTeam(login)); - const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(report?.reportID ?? ''); + const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(report?.reportID); if ((lastVisibleAction ? ReportActionsUtils.isCreatedAction(lastVisibleAction) : report?.lastActionType === CONST.REPORT.ACTIONS.TYPE.CREATED) && adminAccounts.length <= 1) { return false; } @@ -6473,7 +6490,7 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(report: O const parentReportAction: OnyxEntry = !report?.parentReportID || !report?.parentReportActionID ? undefined - : allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID ?? '-1'}`]?.[report.parentReportActionID ?? '-1']; + : allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]; if (!isArchivedRoom(report)) { if (ReportActionsUtils.wasActionTakenByCurrentUser(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) { @@ -6484,9 +6501,9 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(report: O reportAction = undefined; } } else if ((isIOUReport(report) || isExpenseReport(report)) && report?.ownerAccountID === currentUserAccountID) { - if (shouldShowRBRForMissingSmartscanFields(report?.reportID ?? '-1') && !isSettled(report?.reportID)) { + if (shouldShowRBRForMissingSmartscanFields(report?.reportID) && !isSettled(report?.reportID)) { reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage'); - reportAction = getReportActionWithMissingSmartscanFields(report?.reportID ?? '-1'); + reportAction = getReportActionWithMissingSmartscanFields(report?.reportID); } } else if (hasSmartscanError(reportActionsArray)) { reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage'); @@ -6606,7 +6623,7 @@ function reasonForReportToBeInOptionList({ } // If this is a transaction thread associated with a report that only has one transaction, omit it - if (isOneTransactionThread(report.reportID, report.parentReportID ?? '-1', parentReportAction)) { + if (isOneTransactionThread(report.reportID, report.parentReportID, parentReportAction)) { return null; } @@ -6689,11 +6706,7 @@ function reasonForReportToBeInOptionList({ } // Hide chat threads where the parent message is pending removal - if ( - !isEmptyObject(parentReportAction) && - ReportActionsUtils.isPendingRemove(parentReportAction) && - ReportActionsUtils.isThreadParentMessage(parentReportAction, report?.reportID ?? '') - ) { + if (!isEmptyObject(parentReportAction) && ReportActionsUtils.isPendingRemove(parentReportAction) && ReportActionsUtils.isThreadParentMessage(parentReportAction, report?.reportID)) { return null; } @@ -6757,7 +6770,11 @@ function getInvoiceChatByParticipants(policyID: string, receiverID: string | num /** * Attempts to find a policy expense report in onyx that is owned by ownerAccountID in a given policy */ -function getPolicyExpenseChat(ownerAccountID: number, policyID: string): OnyxEntry { +function getPolicyExpenseChat(ownerAccountID: number | undefined, policyID: string | undefined): OnyxEntry { + if (!ownerAccountID || !policyID) { + return; + } + return Object.values(allReports ?? {}).find((report: OnyxEntry) => { // If the report has been deleted, then skip it if (!report) { @@ -7037,7 +7054,7 @@ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry, policy: OnyxEntry 0; - const isPolicyOwnedByExpensifyAccounts = report?.policyID ? CONST.EXPENSIFY_ACCOUNT_IDS.includes(getPolicy(report?.policyID ?? '-1')?.ownerAccountID ?? -1) : false; + const policyOwnerAccountID = getPolicy(report?.policyID)?.ownerAccountID; + const isPolicyOwnedByExpensifyAccounts = policyOwnerAccountID ? CONST.EXPENSIFY_ACCOUNT_IDS.includes(policyOwnerAccountID) : false; if (doParticipantsIncludeExpensifyAccounts && !isPolicyOwnedByExpensifyAccounts) { return []; } @@ -7159,7 +7177,7 @@ function canLeaveRoom(report: OnyxEntry, isPolicyEmployee: boolean): boo return false; } - const invoiceReport = getReportOrDraftReport(report?.iouReportID ?? '-1'); + const invoiceReport = getReportOrDraftReport(report?.iouReportID); if (invoiceReport?.ownerAccountID === currentUserAccountID) { return false; @@ -7242,7 +7260,7 @@ function shouldReportShowSubscript(report: OnyxEntry): boolean { return true; } - if (isExpenseReport(report) && isOneTransactionReport(report?.reportID ?? '-1')) { + if (isExpenseReport(report) && isOneTransactionReport(report?.reportID)) { return true; } @@ -7293,7 +7311,7 @@ function isMoneyRequestReportPendingDeletion(reportOrID: OnyxEntry | str return false; } - const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1'); + const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID, report?.parentReportActionID); return parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; } @@ -7359,7 +7377,7 @@ function canCreateRequest(report: OnyxEntry, policy: OnyxEntry, } function getWorkspaceChats(policyID: string, accountIDs: number[], reports: OnyxCollection = allReports): Array> { - return Object.values(reports ?? {}).filter((report) => isPolicyExpenseChat(report) && (report?.policyID ?? '-1') === policyID && accountIDs.includes(report?.ownerAccountID ?? -1)); + return Object.values(reports ?? {}).filter((report) => isPolicyExpenseChat(report) && report?.policyID === policyID && accountIDs.includes(report?.ownerAccountID ?? -1)); } /** @@ -7518,7 +7536,7 @@ function getTaskAssigneeChatOnyxData( { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: {[optimisticAssigneeAddComment.reportAction.reportActionID ?? '-1']: optimisticAssigneeAddComment.reportAction as ReportAction}, + value: {[optimisticAssigneeAddComment.reportAction.reportActionID]: optimisticAssigneeAddComment.reportAction as ReportAction}, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -7529,12 +7547,12 @@ function getTaskAssigneeChatOnyxData( successData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: {[optimisticAssigneeAddComment.reportAction.reportActionID ?? '-1']: {isOptimisticAction: null}}, + value: {[optimisticAssigneeAddComment.reportAction.reportActionID]: {isOptimisticAction: null}}, }); failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, - value: {[optimisticAssigneeAddComment.reportAction.reportActionID ?? '-1']: {pendingAction: null}}, + value: {[optimisticAssigneeAddComment.reportAction.reportActionID]: {pendingAction: null}}, }); } @@ -7719,7 +7737,7 @@ function getReportActionWithSmartscanError(reportActions: ReportAction[]): Repor return true; } - const transactionID = ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID ?? '-1' : '-1'; + const transactionID = ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID : undefined; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? {}; const isSplitBillError = isSplitReportAction && TransactionUtils.hasMissingSmartscanFields(transaction as Transaction); @@ -7770,7 +7788,10 @@ function navigateToPrivateNotes(report: OnyxEntry, session: OnyxEntry TransactionUtils.isOnHold(transaction)); } @@ -7778,7 +7799,8 @@ function getAllHeldTransactions(iouReportID?: string): Transaction[] { * Check if Report has any held expenses */ function hasHeldExpenses(iouReportID?: string, allReportTransactions?: SearchTransaction[]): boolean { - const transactions = allReportTransactions ?? reportsTransactions[iouReportID ?? ''] ?? []; + const iouReportTransactions = iouReportID ? reportsTransactions[iouReportID] : undefined; + const transactions = allReportTransactions ?? iouReportTransactions ?? []; return transactions.some((transaction) => TransactionUtils.isOnHold(transaction)); } @@ -7876,7 +7898,7 @@ function getAllAncestorReportActions(report: Report | null | undefined, currentU while (parentReportID) { const parentReport = currentUpdatedReport && currentUpdatedReport.reportID === parentReportID ? currentUpdatedReport : getReportOrDraftReport(parentReportID); - const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID ?? '-1'); + const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID); if ( !parentReport || @@ -7918,7 +7940,7 @@ function getAllAncestorReportActionIDs(report: Report | null | undefined, includ while (parentReportID) { const parentReport = getReportOrDraftReport(parentReportID); - const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID ?? '-1'); + const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID); if ( !parentReportAction || @@ -7929,8 +7951,10 @@ function getAllAncestorReportActionIDs(report: Report | null | undefined, includ break; } - allAncestorIDs.reportIDs.push(parentReportID ?? '-1'); - allAncestorIDs.reportActionsIDs.push(parentReportActionID ?? '-1'); + allAncestorIDs.reportIDs.push(parentReportID); + if (parentReportActionID) { + allAncestorIDs.reportActionsIDs.push(parentReportActionID); + } if (!parentReport) { break; @@ -7968,7 +7992,7 @@ function getOptimisticDataForParentReportAction(reportID: string, lastVisibleAct const ancestorReportAction = ReportActionsUtils.getReportAction(ancestorReport.reportID, ancestors.reportActionsIDs.at(index) ?? ''); - if (!ancestorReportAction || isEmptyObject(ancestorReportAction)) { + if (!ancestorReportAction?.reportActionID || isEmptyObject(ancestorReportAction)) { return null; } @@ -7976,7 +8000,7 @@ function getOptimisticDataForParentReportAction(reportID: string, lastVisibleAct onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${ancestorReport.reportID}`, value: { - [ancestorReportAction?.reportActionID ?? '-1']: updateOptimisticParentReportAction(ancestorReportAction, lastVisibleActionCreated, type), + [ancestorReportAction.reportActionID]: updateOptimisticParentReportAction(ancestorReportAction, lastVisibleActionCreated, type), }, }; }); @@ -8099,13 +8123,13 @@ function hasActionsWithErrors(reportID: string): boolean { } function isNonAdminOrOwnerOfPolicyExpenseChat(report: OnyxInputOrEntry, policy: OnyxInputOrEntry): boolean { - return isPolicyExpenseChat(report) && !(PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPolicyOwner(policy, currentUserAccountID ?? -1) || isReportOwner(report)); + return isPolicyExpenseChat(report) && !(PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPolicyOwner(policy, currentUserAccountID) || isReportOwner(report)); } function isAdminOwnerApproverOrReportOwner(report: OnyxEntry, policy: OnyxEntry): boolean { const isApprover = isMoneyRequestReport(report) && report?.managerID !== null && currentUserPersonalDetails?.accountID === report?.managerID; - return PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPolicyOwner(policy, currentUserAccountID ?? -1) || isReportOwner(report) || isApprover; + return PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPolicyOwner(policy, currentUserAccountID) || isReportOwner(report) || isApprover; } /** @@ -8252,14 +8276,14 @@ function createDraftTransactionAndNavigateToParticipantSelector(transactionID: s if (actionName === CONST.IOU.ACTION.CATEGORIZE) { const activePolicy = getPolicy(activePolicyID); if (activePolicy && activePolicy?.type !== CONST.POLICY.TYPE.PERSONAL && activePolicy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { - const policyExpenseReportID = getPolicyExpenseChat(currentUserAccountID ?? -1, activePolicyID ?? '-1')?.reportID ?? '-1'; + const policyExpenseReportID = getPolicyExpenseChat(currentUserAccountID, activePolicyID)?.reportID; IOU.setMoneyRequestParticipants(transactionID, [ { selected: true, accountID: 0, isPolicyExpenseChat: true, reportID: policyExpenseReportID, - policyID: activePolicyID ?? '-1', + policyID: activePolicyID, searchText: activePolicy?.name, }, ]); @@ -8272,14 +8296,14 @@ function createDraftTransactionAndNavigateToParticipantSelector(transactionID: s } const policyID = filteredPolicies.at(0)?.id; - const policyExpenseReportID = getPolicyExpenseChat(currentUserAccountID ?? -1, policyID ?? '-1')?.reportID ?? '-1'; + const policyExpenseReportID = getPolicyExpenseChat(currentUserAccountID, policyID)?.reportID; IOU.setMoneyRequestParticipants(transactionID, [ { selected: true, accountID: 0, isPolicyExpenseChat: true, reportID: policyExpenseReportID, - policyID: policyID ?? '-1', + policyID, searchText: activePolicy?.name, }, ]); @@ -8491,7 +8515,7 @@ function getApprovalChain(policy: OnyxEntry, expenseReport: OnyxEntry Date: Wed, 18 Dec 2024 14:05:29 +0100 Subject: [PATCH 03/18] Remove default ids in ReportUtils file pt2 --- src/libs/ReportUtils.ts | 64 +++++++++++++++++++++++++---------------- src/libs/actions/IOU.ts | 2 +- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5f572d1778a4..0499231e4e83 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1299,10 +1299,11 @@ function getDefaultNotificationPreferenceForReport(report: OnyxEntry): V * Get the notification preference given a report */ function getReportNotificationPreference(report: OnyxEntry, shouldDefaltToHidden = true): ValueOf { + const participant = currentUserAccountID ? report?.participants?.[currentUserAccountID] : undefined; if (!shouldDefaltToHidden) { - return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report); + return participant?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report); } - return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; + return participant?.notificationPreference ?? CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; } const CONCIERGE_ACCOUNT_ID_STRING = CONST.ACCOUNT_ID.CONCIERGE.toString(); @@ -1769,7 +1770,7 @@ function getDisplayedReportID(reportID: string): string { const report = getReport(reportID); const parentReportID = report?.parentReportID; const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, report?.parentReportActionID); - return isOneTransactionThread(reportID, parentReportID, parentReportAction) ? parentReportID : reportID; + return parentReportID && isOneTransactionThread(reportID, parentReportID, parentReportAction) ? parentReportID : reportID; } /** @@ -1778,7 +1779,8 @@ function getDisplayedReportID(reportID: string): string { */ function isOneOnOneChat(report: OnyxEntry): boolean { const participants = report?.participants ?? {}; - const isCurrentUserParticipant = participants[currentUserAccountID ?? 0] ? 1 : 0; + const participant = currentUserAccountID ? participants[currentUserAccountID] : undefined; + const isCurrentUserParticipant = participant ? 1 : 0; const participantAmount = Object.keys(participants).length - isCurrentUserParticipant; if (participantAmount !== 1) { return false; @@ -2395,7 +2397,7 @@ function getIcons( source: actorDetails?.avatar ?? FallbackAvatar, name: LocalePhoneNumber.formatPhoneNumber(actorDisplayName), type: CONST.ICON_TYPE_AVATAR, - fallbackIcon: personalDetails?.[parentReportAction?.actorAccountID ?? -1]?.fallbackIcon, + fallbackIcon: actorDetails?.fallbackIcon, }; if (isWorkspaceThread(report)) { @@ -2492,7 +2494,7 @@ function getIcons( } if (isSelfDM(report)) { - return getIconsForParticipants([currentUserAccountID ?? -1], personalDetails); + return getIconsForParticipants(currentUserAccountID ? [currentUserAccountID] : [], personalDetails); } if (isSystemChat(report)) { @@ -2935,7 +2937,7 @@ function getMoneyRequestSpendBreakdown(report: OnyxInputOrEntry, allRepo */ function getPolicyExpenseChatName(report: OnyxEntry, policy?: OnyxEntry): string | undefined { const ownerAccountID = report?.ownerAccountID; - const personalDetails = allPersonalDetails?.[ownerAccountID ?? -1]; + const personalDetails = ownerAccountID ? allPersonalDetails?.[ownerAccountID] : undefined; const login = personalDetails ? personalDetails.login : null; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const reportOwnerDisplayName = getDisplayNameForParticipant(ownerAccountID) || login || report?.reportName; @@ -3388,20 +3390,20 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, bac if (!ReportActionsUtils.isMoneyRequestAction(reportAction)) { return; } - const moneyRequestReportID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUReportID ?? 0; + const moneyRequestReportID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUReportID; const moneyRequestReport = getReportOrDraftReport(String(moneyRequestReportID)); if (!moneyRequestReportID || !moneyRequestReport) { return; } - const transactionID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID ?? ''; + const transactionID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); const isOnHold = TransactionUtils.isOnHold(transaction); const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`] ?? null; if (isOnHold) { - IOU.unholdRequest(transactionID, reportAction.childReportID ?? '', searchHash); + IOU.unholdRequest(transactionID, reportAction.childReportID, searchHash); } else { const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); Navigation.navigate( @@ -3442,7 +3444,7 @@ function areAllRequestsBeingSmartScanned(iouReportID: string, reportPreviewActio * NOTE: This method is only meant to be used inside this action file. Do not export and use it elsewhere. Use withOnyx or Onyx.connect() instead. */ function getLinkedTransaction(reportAction: OnyxEntry): OnyxEntry { - let transactionID = ''; + let transactionID; if (ReportActionsUtils.isMoneyRequestAction(reportAction)) { transactionID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID; @@ -3931,8 +3933,8 @@ function getReportActionMessage(reportAction: OnyxEntry, reportID? function getInvoicesChatName(report: OnyxEntry, receiverPolicy: OnyxEntry): string { const invoiceReceiver = report?.invoiceReceiver; const isIndividual = invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; - const invoiceReceiverAccountID = isIndividual ? invoiceReceiver.accountID : -1; - const invoiceReceiverPolicyID = isIndividual ? '' : invoiceReceiver?.policyID ?? '-1'; + const invoiceReceiverAccountID = isIndividual ? invoiceReceiver.accountID : CONST.DEFAULT_NUMBER_ID; + const invoiceReceiverPolicyID = isIndividual ? undefined : invoiceReceiver?.policyID; const invoiceReceiverPolicy = receiverPolicy ?? getPolicy(invoiceReceiverPolicyID); const isCurrentUserReceiver = (isIndividual && invoiceReceiverAccountID === currentUserAccountID) || (!isIndividual && PolicyUtils.isPolicyAdmin(invoiceReceiverPolicy)); @@ -4089,7 +4091,7 @@ function getReportName( } if (isInvoiceReport(report)) { - if (!isInvoiceRoom(getReport(report?.chatReportID ?? ''))) { + if (!isInvoiceRoom(getReport(report?.chatReportID))) { return report?.reportName ?? getMoneyRequestReportName(report, policy, invoiceReceiverPolicy); } @@ -4439,7 +4441,7 @@ function buildOptimisticAddCommentReportAction( const isAttachmentOnly = file && !text; const isAttachmentWithText = !!text && file !== undefined; - const accountID = actorAccountID ?? currentUserAccountID ?? -1; + const accountID = actorAccountID ?? currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID; const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail); // Remove HTML from text when applying optimistic offline comment @@ -7377,7 +7379,9 @@ function canCreateRequest(report: OnyxEntry, policy: OnyxEntry, } function getWorkspaceChats(policyID: string, accountIDs: number[], reports: OnyxCollection = allReports): Array> { - return Object.values(reports ?? {}).filter((report) => isPolicyExpenseChat(report) && report?.policyID === policyID && accountIDs.includes(report?.ownerAccountID ?? -1)); + return Object.values(reports ?? {}).filter( + (report) => isPolicyExpenseChat(report) && report?.policyID === policyID && report?.ownerAccountID && accountIDs.includes(report?.ownerAccountID), + ); } /** @@ -7386,7 +7390,7 @@ function getWorkspaceChats(policyID: string, accountIDs: number[], reports: Onyx * @param policyID - the workspace ID to get all associated reports */ function getAllWorkspaceReports(policyID: string): Array> { - return Object.values(allReports ?? {}).filter((report) => (report?.policyID ?? '-1') === policyID); + return Object.values(allReports ?? {}).filter((report) => report?.policyID === policyID); } /** @@ -7585,7 +7589,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry, switch (originalMessage.paymentType) { case CONST.IOU.PAYMENT_TYPE.ELSEWHERE: - translationKey = hasMissingInvoiceBankAccount(IOUReportID ?? '-1') ? 'iou.payerSettledWithMissingBankAccount' : 'iou.paidElsewhereWithAmount'; + translationKey = hasMissingInvoiceBankAccount(IOUReportID) ? 'iou.payerSettledWithMissingBankAccount' : 'iou.paidElsewhereWithAmount'; break; case CONST.IOU.PAYMENT_TYPE.EXPENSIFY: case CONST.IOU.PAYMENT_TYPE.VBBA: @@ -7672,7 +7676,7 @@ function isValidReport(report?: OnyxEntry): boolean { /** * Check to see if we are a participant of this report. */ -function isReportParticipant(accountID: number, report: OnyxEntry): boolean { +function isReportParticipant(accountID: number | undefined, report: OnyxEntry): boolean { if (!accountID) { return false; } @@ -7691,7 +7695,7 @@ function isReportParticipant(accountID: number, report: OnyxEntry): bool * Check to see if the current user has access to view the report. */ function canCurrentUserOpenReport(report: OnyxEntry): boolean { - return (isReportParticipant(currentUserAccountID ?? 0, report) || isPublicRoom(report)) && canAccessReport(report, allPolicies, allBetas); + return (isReportParticipant(currentUserAccountID, report) || isPublicRoom(report)) && canAccessReport(report, allPolicies, allBetas); } function shouldUseFullTitleToDisplay(report: OnyxEntry): boolean { @@ -7715,7 +7719,7 @@ function canEditReportDescription(report: OnyxEntry, policy: OnyxEntry

0 && !reportTransactions.some((transaction) => !TransactionUtils.isOnHold(transaction)); } @@ -8105,7 +8110,12 @@ function getTripTransactions(tripRoomReportID: string | undefined, reportFieldTo const tripTransactionReportIDs = Object.values(allReports ?? {}) .filter((report) => report && report?.[reportFieldToCompare] === tripRoomReportID) .map((report) => report?.reportID); - return tripTransactionReportIDs.flatMap((reportID) => reportsTransactions[reportID ?? ''] ?? []); + return tripTransactionReportIDs.flatMap((reportID) => { + if (!reportID) { + return []; + } + return reportsTransactions[reportID] ?? []; + }); } function getTripIDFromTransactionParentReport(transactionParentReport: OnyxEntry | undefined | null): string | undefined { @@ -8287,7 +8297,9 @@ function createDraftTransactionAndNavigateToParticipantSelector(transactionID: s searchText: activePolicy?.name, }, ]); - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, policyExpenseReportID)); + if (policyExpenseReportID) { + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, policyExpenseReportID)); + } return; } if (filteredPolicies.length === 0 || filteredPolicies.length > 1) { @@ -8307,7 +8319,9 @@ function createDraftTransactionAndNavigateToParticipantSelector(transactionID: s searchText: activePolicy?.name, }, ]); - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, policyExpenseReportID)); + if (policyExpenseReportID) { + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, policyExpenseReportID)); + } return; } diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 696853f49fd7..61d87052aee4 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -8320,7 +8320,7 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea /** * Remove expense from HOLD */ -function unholdRequest(transactionID: string, reportID: string, searchHash?: number) { +function unholdRequest(transactionID: string | undefined, reportID: string | undefined, searchHash?: number) { const createdReportAction = ReportUtils.buildOptimisticUnHoldReportAction(); const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; From 1d956b41acfcadc32e3fa2d378b4c4b1d11d5aaa Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 18 Dec 2024 15:33:43 +0100 Subject: [PATCH 04/18] Remove default ids in ReportUtils file pt3 --- src/libs/ReportUtils.ts | 83 +++++++++++++++++++---------------------- src/libs/actions/IOU.ts | 2 +- 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8083cb2d74c1..4fd6694e25f5 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1,7 +1,6 @@ import {format} from 'date-fns'; import {Str} from 'expensify-common'; import lodashEscape from 'lodash/escape'; -import lodashFindLastIndex from 'lodash/findLastIndex'; import lodashIntersection from 'lodash/intersection'; import isEmpty from 'lodash/isEmpty'; import lodashIsEqual from 'lodash/isEqual'; @@ -1043,7 +1042,7 @@ function isSettled(reportOrID: OnyxInputOrEntry | SearchReport | string * Whether the current user is the submitter of the report */ function isCurrentUserSubmitter(reportID: string): boolean { - if (!allReports) { + if (!allReports || !reportID) { return false; } const report = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; @@ -2391,7 +2390,7 @@ function getIcons( const actorAccountID = getReportActionActorAccountID(parentReportAction, report, report); const actorDetails = actorAccountID ? personalDetails?.[actorAccountID] : undefined; - const actorDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[actorAccountID ?? -1], '', false); + const actorDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(actorDetails, '', false); const actorIcon = { id: actorAccountID, source: actorDetails?.avatar ?? FallbackAvatar, @@ -2891,7 +2890,7 @@ function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry | Op * */ function hasNonReimbursableTransactions(iouReportID: string | undefined): boolean { - const transactions = reportsTransactions[iouReportID ?? ''] ?? []; + const transactions = iouReportID ? reportsTransactions[iouReportID] ?? [] : []; return transactions.filter((transaction) => transaction.reimbursable === false).length > 0; } @@ -3206,7 +3205,7 @@ function canEditMoneyRequest(reportAction: OnyxInputOrEntry) return {canHoldRequest: false, canUnholdRequest: false}; } - const moneyRequestReportID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUReportID ?? 0; + const moneyRequestReportID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUReportID; const moneyRequestReport = getReportOrDraftReport(String(moneyRequestReportID)); if (!moneyRequestReportID || !moneyRequestReport) { @@ -3352,7 +3351,7 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry) const isRequestSettled = isSettled(moneyRequestReport?.reportID); const isApproved = isReportApproved(moneyRequestReport); - const transactionID = moneyRequestReport ? ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID : 0; + const transactionID = moneyRequestReport ? ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID : undefined; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); const parentReportAction = isThread(moneyRequestReport) @@ -3398,6 +3397,11 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, bac } const transactionID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID; + + if (!transactionID || !reportAction.childReportID) { + return; + } + const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); const isOnHold = TransactionUtils.isOnHold(transaction); const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`] ?? null; @@ -3408,7 +3412,7 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, bac const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); Navigation.navigate( // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID ?? '', backTo || activeRoute, searchHash), + ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID, backTo || activeRoute, searchHash), ); } }; @@ -3417,7 +3421,10 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, bac * Gets all transactions on an IOU report with a receipt */ function getTransactionsWithReceipts(iouReportID: string | undefined): Transaction[] { - const transactions = reportsTransactions[iouReportID ?? ''] ?? []; + if (!iouReportID) { + return []; + } + const transactions = reportsTransactions[iouReportID] ?? []; return transactions.filter((transaction) => TransactionUtils.hasReceipt(transaction)); } @@ -3860,7 +3867,7 @@ function getInvoicePayerName(report: OnyxEntry, invoiceReceiverPolicy?: /** * Parse html of reportAction into text */ -function parseReportActionHtmlToText(reportAction: OnyxEntry, reportID: string, childReportID?: string): string { +function parseReportActionHtmlToText(reportAction: OnyxEntry, reportID: string | undefined, childReportID?: string): string { if (!reportAction) { return ''; } @@ -3924,7 +3931,7 @@ function getReportActionMessage(reportAction: OnyxEntry, reportID? return getReimbursementQueuedActionMessage(reportAction, getReportOrDraftReport(reportID), false); } - return parseReportActionHtmlToText(reportAction, reportID ?? '', childReportID); + return parseReportActionHtmlToText(reportAction, reportID, childReportID); } /** @@ -4663,8 +4670,7 @@ function populateOptimisticReportFormula(formula: string, report: OptimisticExpe /** Builds an optimistic invoice report with a randomly generated reportID */ function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, receiverAccountID: number, receiverName: string, total: number, currency: string): OptimisticExpenseReport { const formattedTotal = CurrencyUtils.convertToDisplayString(total, currency); - - return { + const invoiceReport = { reportID: generateReportID(), chatReportID, policyID, @@ -4678,9 +4684,6 @@ function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, re statusNum: CONST.REPORT.STATUS_NUM.OPEN, total, participants: { - [currentUserAccountID ?? -1]: { - notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, - }, [receiverAccountID]: { notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, }, @@ -4688,6 +4691,12 @@ function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, re parentReportID: chatReportID, lastVisibleActionCreated: DateUtils.getDBTime(), }; + + if (currentUserAccountID) { + invoiceReport.participants[currentUserAccountID] = {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN}; + } + + return invoiceReport; } /** @@ -5014,8 +5023,8 @@ function buildOptimisticIOUReportAction( originalMessage.participantAccountIDs = currentUserAccountID ? [currentUserAccountID] : []; } else { originalMessage.participantAccountIDs = currentUserAccountID - ? [currentUserAccountID, ...participants.map((participant) => participant.accountID ?? -1)] - : participants.map((participant) => participant.accountID ?? -1); + ? [currentUserAccountID, ...participants.map((participant) => participant.accountID ?? CONST.DEFAULT_NUMBER_ID)] + : participants.map((participant) => participant.accountID ?? CONST.DEFAULT_NUMBER_ID); } } @@ -5226,7 +5235,7 @@ function buildOptimisticReportPreview( }, ], created, - accountID: iouReport?.managerID ?? -1, + accountID: iouReport?.managerID, // The preview is initially whispered if created with a receipt, so the actor is the current user as well actorAccountID: hasReceipt ? currentUserAccountID : reportActorAccountID, childReportID: childReportID ?? iouReport?.reportID, @@ -5411,11 +5420,13 @@ function updateReportPreview( : recentReceiptTransactions, // As soon as we add a transaction without a receipt to the report, it will have ready expenses, // so we remove the whisper - originalMessage: { - ...(originalMessage ?? {}), - whisperedTo: hasReceipt ? originalMessage?.whisperedTo : [], - linkedReportID: originalMessage?.linkedReportID ?? '0', - }, + originalMessage: originalMessage + ? { + ...originalMessage, + whisperedTo: hasReceipt ? originalMessage.whisperedTo : [], + linkedReportID: originalMessage.linkedReportID, + } + : undefined, }; } @@ -6066,7 +6077,7 @@ function buildOptimisticWorkspaceChats(policyID: string, policyName: string, exp const pendingChatMembers = getPendingChatMembers(currentUserAccountID ? [currentUserAccountID] : [], [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); const adminsChatData = { ...buildOptimisticChatReport( - [currentUserAccountID ?? -1], + currentUserAccountID ? [currentUserAccountID] : [], CONST.REPORT.WORKSPACE_CHAT_ROOMS.ADMINS, CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, policyID, @@ -6083,7 +6094,7 @@ function buildOptimisticWorkspaceChats(policyID: string, policyName: string, exp }; const expenseChatData = buildOptimisticChatReport( - [currentUserAccountID ?? -1], + currentUserAccountID ? [currentUserAccountID] : [], '', CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID, @@ -6407,7 +6418,7 @@ function shouldDisplayViolationsRBRInLHN(report: OnyxEntry, transactionV } // We only show the RBR to the submitter - if (!isCurrentUserSubmitter(report.reportID ?? '')) { + if (!isCurrentUserSubmitter(report.reportID)) { return false; } @@ -6854,21 +6865,6 @@ function shouldShowFlagComment(reportAction: OnyxInputOrEntry, rep ); } -/** - * @param sortedAndFilteredReportActions - reportActions for the report, sorted newest to oldest, and filtered for only those that should be visible - */ -function getNewMarkerReportActionID(report: OnyxEntry, sortedAndFilteredReportActions: ReportAction[]): string { - if (!isUnread(report)) { - return ''; - } - - const newMarkerIndex = lodashFindLastIndex(sortedAndFilteredReportActions, (reportAction) => (reportAction.created ?? '') > (report?.lastReadTime ?? '')); - - return newMarkerIndex !== -1 && 'reportActionID' in (sortedAndFilteredReportActions?.at(newMarkerIndex) ?? {}) - ? sortedAndFilteredReportActions.at(newMarkerIndex)?.reportActionID ?? '' - : ''; -} - /** * Performs the markdown conversion, and replaces code points > 127 with C escape sequences * Used for compatibility with the backend auth validator for AddComment, and to account for MD in comments @@ -7330,7 +7326,7 @@ function canUserPerformWriteAction(report: OnyxEntry) { */ function getOriginalReportID(reportID: string, reportAction: OnyxInputOrEntry): string | undefined { const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; - const currentReportAction = reportActions?.[reportAction?.reportActionID ?? '-1'] ?? null; + const currentReportAction = reportAction?.reportActionID ? reportActions?.[reportAction.reportActionID] : undefined; const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(reportID, reportActions ?? ([] as ReportAction[])); const isThreadReportParentAction = reportAction?.childReportID?.toString() === reportID; if (Object.keys(currentReportAction ?? {}).length === 0) { @@ -8654,7 +8650,6 @@ export { getLastVisibleMessage, getMoneyRequestOptions, getMoneyRequestSpendBreakdown, - getNewMarkerReportActionID, getNonHeldAndFullAmount, getOptimisticDataForParentReportAction, getOriginalReportID, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 1a6e2bd37632..1a3f4b501e78 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -8327,7 +8327,7 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea /** * Remove expense from HOLD */ -function unholdRequest(transactionID: string | undefined, reportID: string | undefined, searchHash?: number) { +function unholdRequest(transactionID: string, reportID: string, searchHash?: number) { const createdReportAction = ReportUtils.buildOptimisticUnHoldReportAction(); const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; From fe2e643cd06a7a1526c75d159b321eab439bf209 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 18 Dec 2024 16:24:31 +0100 Subject: [PATCH 05/18] Remove default ids in PolicyUtils file --- src/libs/PolicyUtils.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index bb229547f6ed..90b70a5835ab 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -197,7 +197,10 @@ function getPolicyBrickRoadIndicatorStatus(policy: OnyxEntry, isConnecti } function getPolicyRole(policy: OnyxInputOrEntry | SearchPolicy, currentUserLogin: string | undefined) { - return policy?.role ?? policy?.employeeList?.[currentUserLogin ?? '-1']?.role; + if (policy?.role) { + return policy.role; + } + return currentUserLogin ? policy?.employeeList?.[currentUserLogin]?.role : undefined; } /** @@ -400,9 +403,9 @@ function isControlPolicy(policy: OnyxEntry): boolean { function isTaxTrackingEnabled(isPolicyExpenseChat: boolean, policy: OnyxEntry, isDistanceRequest: boolean): boolean { const distanceUnit = getDistanceRateCustomUnit(policy); - const customUnitID = distanceUnit?.customUnitID ?? 0; + const customUnitID = distanceUnit?.customUnitID; const isPolicyTaxTrackingEnabled = isPolicyExpenseChat && policy?.tax?.trackingEnabled; - const isTaxEnabledForDistance = isPolicyTaxTrackingEnabled && policy?.customUnits?.[customUnitID]?.attributes?.taxEnabled; + const isTaxEnabledForDistance = isPolicyTaxTrackingEnabled && !!customUnitID && policy?.customUnits?.[customUnitID]?.attributes?.taxEnabled; return !!(isDistanceRequest ? isTaxEnabledForDistance : isPolicyTaxTrackingEnabled); } @@ -538,7 +541,7 @@ function getDefaultApprover(policy: OnyxEntry | SearchPolicy): string { * Returns the accountID to whom the given expenseReport submits reports to in the given Policy. */ function getSubmitToAccountID(policy: OnyxEntry | SearchPolicy, expenseReport: OnyxEntry): number { - const employeeAccountID = expenseReport?.ownerAccountID ?? -1; + const employeeAccountID = expenseReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID; const employeeLogin = getLoginsByAccountIDs([employeeAccountID]).at(0) ?? ''; const defaultApprover = getDefaultApprover(policy); @@ -557,8 +560,8 @@ function getSubmitToAccountID(policy: OnyxEntry | SearchPolicy, expenseR return getAccountIDsByLogins([categoryAppover]).at(0) ?? -1; } - if (!tagApprover && getTagApproverRule(policy ?? '-1', tag)?.approver) { - tagApprover = getTagApproverRule(policy ?? '-1', tag)?.approver; + if (!tagApprover && getTagApproverRule(policy, tag)?.approver) { + tagApprover = getTagApproverRule(policy, tag)?.approver; } } @@ -709,7 +712,7 @@ function settingsPendingAction(settings?: string[], pendingFields?: PendingField } const key = Object.keys(pendingFields).find((setting) => settings.includes(setting)); - return pendingFields[key ?? '-1']; + return key ? pendingFields[key] : undefined; } function findSelectedVendorWithDefaultSelect(vendors: NetSuiteVendor[] | undefined, selectedVendorId: string | undefined) { @@ -1078,7 +1081,7 @@ function getWorkspaceAccountID(policyID: string) { if (!policy) { return 0; } - return policy.workspaceAccountID ?? 0; + return policy.workspaceAccountID ?? CONST.DEFAULT_NUMBER_ID; } function hasVBBA(policyID: string) { From 1c2742daf81b5c294f5472944d272347be622935 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 18 Dec 2024 17:26:15 +0100 Subject: [PATCH 06/18] Remove default ids in ReportActionsUtils.ts file --- src/libs/ReportActionsUtils.ts | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 76726596cbc5..5650fb732ca7 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -287,7 +287,7 @@ function isWhisperActionTargetedToOthers(reportAction: OnyxInputOrEntry): reportAction is ReportAction { @@ -899,12 +899,12 @@ function getLastClosedReportAction(reportActions: OnyxEntry): Ony * 4. We will get the second last action from filtered actions because the last * action is always the created action */ -function getFirstVisibleReportActionID(sortedReportActions: ReportAction[] = [], isOffline = false): string { +function getFirstVisibleReportActionID(sortedReportActions: ReportAction[] = [], isOffline = false): string | undefined { if (!Array.isArray(sortedReportActions)) { return ''; } const sortedFilterReportActions = sortedReportActions.filter((action) => !isDeletedAction(action) || (action?.childVisibleActionCount ?? 0) > 0 || isOffline); - return sortedFilterReportActions.length > 1 ? sortedFilterReportActions.at(sortedFilterReportActions.length - 2)?.reportActionID ?? '-1' : ''; + return sortedFilterReportActions.length > 1 ? sortedFilterReportActions.at(sortedFilterReportActions.length - 2)?.reportActionID : undefined; } /** @@ -992,8 +992,8 @@ function getReportPreviewAction(chatReportID: string, iouReportID: string): Onyx /** * Get the iouReportID for a given report action. */ -function getIOUReportIDFromReportActionPreview(reportAction: OnyxEntry): string { - return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW) ? getOriginalMessage(reportAction)?.linkedReportID ?? '-1' : '-1'; +function getIOUReportIDFromReportActionPreview(reportAction: OnyxEntry): string | undefined { + return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW) ? getOriginalMessage(reportAction)?.linkedReportID : undefined; } /** @@ -1505,7 +1505,7 @@ function isReportActionUnread(reportAction: OnyxEntry, lastReadTim */ function isCurrentActionUnread(report: OnyxEntry, reportAction: ReportAction): boolean { const lastReadTime = report?.lastReadTime ?? ''; - const sortedReportActions = getSortedReportActions(Object.values(getAllReportActions(report?.reportID ?? '-1'))); + const sortedReportActions = getSortedReportActions(Object.values(getAllReportActions(report?.reportID))); const currentActionIndex = sortedReportActions.findIndex((action) => action.reportActionID === reportAction.reportActionID); if (currentActionIndex === -1) { return false; @@ -1565,7 +1565,8 @@ function getDismissedViolationMessageText(originalMessage: ReportAction) { @@ -1582,7 +1583,7 @@ function didMessageMentionCurrentUser(reportAction: OnyxInputOrEntry'); + return accountIDsFromMessage.includes(currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID) || emailsFromMessage.includes(currentEmail) || message.includes(''); } /** @@ -1597,9 +1598,9 @@ function wasActionTakenByCurrentUser(reportAction: OnyxInputOrEntry { const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; - const reportActions = getAllReportActions(report?.reportID ?? ''); + const reportActions = getAllReportActions(report?.reportID); const action = Object.values(reportActions ?? {})?.find((reportAction) => { - const IOUTransactionID = isMoneyRequestAction(reportAction) ? getOriginalMessage(reportAction)?.IOUTransactionID : -1; + const IOUTransactionID = isMoneyRequestAction(reportAction) ? getOriginalMessage(reportAction)?.IOUTransactionID : undefined; return IOUTransactionID === transactionID; }); return action; @@ -1642,7 +1643,7 @@ function getExportIntegrationActionFragments(reportAction: OnyxEntry '2022-11-14'; const base62ReportID = getBase62ReportID(Number(reportID)); @@ -1776,7 +1777,7 @@ function getRenamedAction(reportAction: OnyxEntry>) { const originalMessage = getOriginalMessage(reportAction); - const submittersNames = PersonalDetailsUtils.getPersonalDetailsByIDs(originalMessage?.submittersAccountIDs ?? [], currentUserAccountID ?? -1).map( + const submittersNames = PersonalDetailsUtils.getPersonalDetailsByIDs(originalMessage?.submittersAccountIDs ?? [], currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID).map( ({displayName, login}) => displayName ?? login ?? 'Unknown Submitter', ); return Localize.translateLocal('workspaceActions.removedFromApprovalWorkflow', {submittersNames, count: submittersNames.length}); @@ -1803,9 +1804,9 @@ function getCardIssuedMessage(reportAction: OnyxEntry, shouldRende ? getOriginalMessage(reportAction) : undefined; - const assigneeAccountID = cardIssuedActionOriginalMessage?.assigneeAccountID ?? -1; - const cardID = cardIssuedActionOriginalMessage?.cardID ?? -1; - const assigneeDetails = PersonalDetailsUtils.getPersonalDetailsByIDs([assigneeAccountID], currentUserAccountID ?? -1).at(0); + const assigneeAccountID = cardIssuedActionOriginalMessage?.assigneeAccountID ?? CONST.DEFAULT_NUMBER_ID; + const cardID = cardIssuedActionOriginalMessage?.cardID ?? CONST.DEFAULT_NUMBER_ID; + const assigneeDetails = PersonalDetailsUtils.getPersonalDetailsByIDs([assigneeAccountID], currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID).at(0); const isPolicyAdmin = PolicyUtils.isPolicyAdmin(PolicyUtils.getPolicy(policyID)); const assignee = shouldRenderHTML ? `` : assigneeDetails?.firstName ?? assigneeDetails?.login ?? ''; const navigateRoute = isPolicyAdmin ? ROUTES.EXPENSIFY_CARD_DETAILS.getRoute(policyID, String(cardID)) : ROUTES.SETTINGS_DOMAINCARD_DETAIL.getRoute(String(cardID)); From fd1d6c1c1d78e7d6150b225130b258134bc2f5d0 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Thu, 19 Dec 2024 11:31:35 +0100 Subject: [PATCH 07/18] Fix TS errors in OptionsListUtils --- .eslintrc.changed.js | 2 +- src/libs/OptionsListUtils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.changed.js b/.eslintrc.changed.js index 20b82de39bf7..fbe6cfdcce65 100644 --- a/.eslintrc.changed.js +++ b/.eslintrc.changed.js @@ -10,7 +10,7 @@ module.exports = { }, overrides: [ { - files: ['src/libs/actions/IOU.ts', 'src/libs/actions/Report.ts', 'src/libs/actions/Task.ts'], + files: ['src/libs/actions/IOU.ts', 'src/libs/actions/Report.ts', 'src/libs/actions/Task.ts', 'src/libs/OptionsListUtils.ts'], rules: { 'rulesdir/no-default-id-values': 'off', }, diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index a7f738790f92..13f35347dbde 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1269,7 +1269,7 @@ function getValidOptions( if (reportPreviewAction) { const iouReportID = ReportActionUtils.getIOUReportIDFromReportActionPreview(reportPreviewAction); - const iouReportActions = allSortedReportActions[iouReportID] ?? []; + const iouReportActions = iouReportID ? allSortedReportActions[iouReportID] ?? [] : []; const lastIOUAction = iouReportActions.find((iouAction) => iouAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); if (lastIOUAction) { reportOption.lastIOUCreationDate = lastIOUAction.lastModified; From a1027fbd3cdbb60d0e487f3aa4eaa85b55ec4f39 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Thu, 19 Dec 2024 11:48:00 +0100 Subject: [PATCH 08/18] Minor update --- src/pages/home/report/PureReportActionItem.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index 34dd2a9d1350..bb3e04a90b84 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -687,7 +687,8 @@ function PureReportActionItem({ ${translate('parentReportAction.deletedReport')}`} /> ) : ( Date: Thu, 19 Dec 2024 13:55:20 +0100 Subject: [PATCH 09/18] Ignore PureReportActionItem --- .eslintrc.changed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.changed.js b/.eslintrc.changed.js index fbe6cfdcce65..c74765b52972 100644 --- a/.eslintrc.changed.js +++ b/.eslintrc.changed.js @@ -10,7 +10,7 @@ module.exports = { }, overrides: [ { - files: ['src/libs/actions/IOU.ts', 'src/libs/actions/Report.ts', 'src/libs/actions/Task.ts', 'src/libs/OptionsListUtils.ts'], + files: ['src/libs/actions/IOU.ts', 'src/libs/actions/Report.ts', 'src/libs/actions/Task.ts', 'src/libs/OptionsListUtils.ts', 'src/pages/home/report/PureReportActionItem.tsx'], rules: { 'rulesdir/no-default-id-values': 'off', }, From 68cae122ff7e89c0464a68e5b045255210b92cc0 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Thu, 19 Dec 2024 14:04:12 +0100 Subject: [PATCH 10/18] Lint fixes --- src/libs/ReportUtils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index cd194d82fc85..83f5c7c67d63 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1298,8 +1298,8 @@ function getDefaultNotificationPreferenceForReport(report: OnyxEntry): V * Get the notification preference given a report. This should ALWAYS default to 'hidden'. Do not change this! */ function getReportNotificationPreference(report: OnyxEntry): ValueOf { - const participant = currentUserAccountID ? report?.participants?.[currentUserAccountID] : undefined; - return participant?.notificationPreference ?? CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; + const participant = currentUserAccountID ? report?.participants?.[currentUserAccountID] : undefined; + return participant?.notificationPreference ?? CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; } const CONCIERGE_ACCOUNT_ID_STRING = CONST.ACCOUNT_ID.CONCIERGE.toString(); @@ -8522,7 +8522,7 @@ function getApprovalChain(policy: OnyxEntry, expenseReport: OnyxEntry Date: Thu, 19 Dec 2024 17:14:45 +0100 Subject: [PATCH 11/18] Bug fix --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 83f5c7c67d63..741af95d90de 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7822,7 +7822,7 @@ function hasHeldExpenses(iouReportID?: string, allReportTransactions?: SearchTra * Check if all expenses in the Report are on hold */ function hasOnlyHeldExpenses(iouReportID: string, allReportTransactions?: SearchTransaction[]): boolean { - const transactionsByIouReportID = iouReportID ? reportsTransactions[iouReportID] : []; + const transactionsByIouReportID = iouReportID ? reportsTransactions[iouReportID] ?? [] : []; const reportTransactions = allReportTransactions ?? transactionsByIouReportID; return reportTransactions.length > 0 && !reportTransactions.some((transaction) => !TransactionUtils.isOnHold(transaction)); } From 93834a365e41439c98a63572c1135159388c9125 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Tue, 24 Dec 2024 12:47:01 +0100 Subject: [PATCH 12/18] Apply reviewer feedback pt1 --- src/libs/ReportUtils.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index aff2a6c83fb2..c66ff33d76ce 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1040,7 +1040,7 @@ function isSettled(reportOrID: OnyxInputOrEntry | SearchReport | string /** * Whether the current user is the submitter of the report */ -function isCurrentUserSubmitter(reportID: string): boolean { +function isCurrentUserSubmitter(reportID: string | undefined): boolean { if (!allReports || !reportID) { return false; } @@ -2387,13 +2387,13 @@ function getIcons( if (isExpenseRequest(report)) { const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]; const workspaceIcon = getWorkspaceIcon(report, policy); - const actorAccountDetails = parentReportAction?.actorAccountID ? personalDetails?.[parentReportAction.actorAccountID] : undefined; + const actorDetails = parentReportAction?.actorAccountID ? personalDetails?.[parentReportAction.actorAccountID] : undefined; const memberIcon = { - source: actorAccountDetails?.avatar ?? FallbackAvatar, + source: actorDetails?.avatar ?? FallbackAvatar, id: parentReportAction?.actorAccountID, type: CONST.ICON_TYPE_AVATAR, - name: actorAccountDetails?.displayName ?? '', - fallbackIcon: actorAccountDetails?.fallbackIcon, + name: actorDetails?.displayName ?? '', + fallbackIcon: actorDetails?.fallbackIcon, }; return [memberIcon, workspaceIcon]; @@ -2903,11 +2903,14 @@ function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry | Op } /** - * Returns number of transactions that are nonReimbursable - * + * Checks if the report contains at least one Non-Reimbursable transaction */ function hasNonReimbursableTransactions(iouReportID: string | undefined): boolean { - const transactions = iouReportID ? reportsTransactions[iouReportID] ?? [] : []; + if (!iouReportID) { + return false; + } + + const transactions = reportsTransactions[iouReportID] ?? []; return transactions.filter((transaction) => transaction.reimbursable === false).length > 0; } From 964115d3ed4e9e5d55cb068688d65126c8aaad18 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Tue, 24 Dec 2024 13:41:02 +0100 Subject: [PATCH 13/18] Add getReportTransactions function --- src/libs/ReportUtils.ts | 57 +++++++------------ .../EnforceActionExportRestrictions.ts | 5 ++ 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c66ff33d76ce..c7b2ccfa10c3 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -776,6 +776,14 @@ function getReportOrDraftReport(reportID: string | undefined): OnyxEntry return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? allReportsDraft?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportID}`]; } +function getReportTransactions(reportID: string | undefined): Transaction[] { + if (!reportID) { + return []; + } + + return reportsTransactions[reportID] ?? []; +} + /** * Check if a report is a draft report */ @@ -1647,11 +1655,7 @@ function isPolicyAdmin(policyID: string | undefined, policies: OnyxCollection | SearchRepor * Checks if a report contains only Non-Reimbursable transactions */ function hasOnlyNonReimbursableTransactions(iouReportID: string | undefined): boolean { - if (!iouReportID) { - return false; - } - - const transactions = reportsTransactions[iouReportID] ?? []; + const transactions = getReportTransactions(iouReportID); if (!transactions || transactions.length === 0) { return false; } @@ -2906,11 +2906,7 @@ function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry | Op * Checks if the report contains at least one Non-Reimbursable transaction */ function hasNonReimbursableTransactions(iouReportID: string | undefined): boolean { - if (!iouReportID) { - return false; - } - - const transactions = reportsTransactions[iouReportID] ?? []; + const transactions = getReportTransactions(iouReportID); return transactions.filter((transaction) => transaction.reimbursable === false).length > 0; } @@ -3441,10 +3437,7 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, bac * Gets all transactions on an IOU report with a receipt */ function getTransactionsWithReceipts(iouReportID: string | undefined): Transaction[] { - if (!iouReportID) { - return []; - } - const transactions = reportsTransactions[iouReportID] ?? []; + const transactions = getReportTransactions(iouReportID); return transactions.filter((transaction) => TransactionUtils.hasReceipt(transaction)); } @@ -3484,7 +3477,7 @@ function getLinkedTransaction(reportAction: OnyxEntry, transactionV * Checks to see if a report contains a violation */ function hasViolations(reportID: string, transactionViolations: OnyxCollection, shouldShowInReview?: boolean): boolean { - const transactions = reportsTransactions[reportID] ?? []; + const transactions = getReportTransactions(reportID); return transactions.some((transaction) => TransactionUtils.hasViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); } @@ -6465,7 +6458,7 @@ function hasViolations(reportID: string, transactionViolations: OnyxCollection, shouldShowInReview?: boolean): boolean { - const transactions = reportsTransactions[reportID] ?? []; + const transactions = getReportTransactions(reportID); return transactions.some((transaction) => TransactionUtils.hasWarningTypeViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); } @@ -6473,7 +6466,7 @@ function hasWarningTypeViolations(reportID: string, transactionViolations: OnyxC * Checks to see if a report contains a violation of type `notice` */ function hasNoticeTypeViolations(reportID: string, transactionViolations: OnyxCollection, shouldShowInReview?: boolean): boolean { - const transactions = reportsTransactions[reportID] ?? []; + const transactions = getReportTransactions(reportID); return transactions.some((transaction) => TransactionUtils.hasNoticeTypeViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); } @@ -7803,10 +7796,7 @@ function navigateToPrivateNotes(report: OnyxEntry, session: OnyxEntry TransactionUtils.isOnHold(transaction)); } @@ -7814,7 +7804,7 @@ function getAllHeldTransactions(iouReportID?: string): Transaction[] { * Check if Report has any held expenses */ function hasHeldExpenses(iouReportID?: string, allReportTransactions?: SearchTransaction[]): boolean { - const iouReportTransactions = iouReportID ? reportsTransactions[iouReportID] : undefined; + const iouReportTransactions = getReportTransactions(iouReportID); const transactions = allReportTransactions ?? iouReportTransactions ?? []; return transactions.some((transaction) => TransactionUtils.isOnHold(transaction)); } @@ -7823,7 +7813,7 @@ function hasHeldExpenses(iouReportID?: string, allReportTransactions?: SearchTra * Check if all expenses in the Report are on hold */ function hasOnlyHeldExpenses(iouReportID: string, allReportTransactions?: SearchTransaction[]): boolean { - const transactionsByIouReportID = iouReportID ? reportsTransactions[iouReportID] ?? [] : []; + const transactionsByIouReportID = getReportTransactions(iouReportID); const reportTransactions = allReportTransactions ?? transactionsByIouReportID; return reportTransactions.length > 0 && !reportTransactions.some((transaction) => !TransactionUtils.isOnHold(transaction)); } @@ -7844,7 +7834,7 @@ function hasUpdatedTotal(report: OnyxInputOrEntry, policy: OnyxInputOrEn return true; } - const allReportTransactions = reportsTransactions[report.reportID] ?? []; + const allReportTransactions = getReportTransactions(report.reportID); const hasPendingTransaction = allReportTransactions.some((transaction) => !!transaction.pendingAction); const hasTransactionWithDifferentCurrency = allReportTransactions.some((transaction) => transaction.currency !== report.currency); @@ -8121,12 +8111,7 @@ function getTripTransactions(tripRoomReportID: string | undefined, reportFieldTo const tripTransactionReportIDs = Object.values(allReports ?? {}) .filter((report) => report && report?.[reportFieldToCompare] === tripRoomReportID) .map((report) => report?.reportID); - return tripTransactionReportIDs.flatMap((reportID) => { - if (!reportID) { - return []; - } - return reportsTransactions[reportID] ?? []; - }); + return tripTransactionReportIDs.flatMap((reportID) => getReportTransactions(reportID)); } function getTripIDFromTransactionParentReportID(transactionParentReportID: string | undefined): string | undefined { diff --git a/tests/actions/EnforceActionExportRestrictions.ts b/tests/actions/EnforceActionExportRestrictions.ts index bead431d030f..142f1df6f367 100644 --- a/tests/actions/EnforceActionExportRestrictions.ts +++ b/tests/actions/EnforceActionExportRestrictions.ts @@ -19,6 +19,11 @@ describe('ReportUtils', () => { expect(ReportUtils.getReport).toBeUndefined(); }); + it('does not export getReportTransactions', () => { + // @ts-expect-error the test is asserting that it's undefined, so the TS error is normal + expect(ReportUtils.getReportTransactions).toBeUndefined(); + }); + it('does not export isOneTransactionReport', () => { // @ts-expect-error the test is asserting that it's undefined, so the TS error is normal expect(ReportUtils.isOneTransactionReport).toBeUndefined(); From ddcb3efb5b9afe902c97aac9bf92a0fb85e534a5 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Tue, 24 Dec 2024 13:48:12 +0100 Subject: [PATCH 14/18] Minor code clean up --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c7b2ccfa10c3..96c3564993b8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7805,7 +7805,7 @@ function getAllHeldTransactions(iouReportID?: string): Transaction[] { */ function hasHeldExpenses(iouReportID?: string, allReportTransactions?: SearchTransaction[]): boolean { const iouReportTransactions = getReportTransactions(iouReportID); - const transactions = allReportTransactions ?? iouReportTransactions ?? []; + const transactions = allReportTransactions ?? iouReportTransactions; return transactions.some((transaction) => TransactionUtils.isOnHold(transaction)); } From 8f524972cb5cdfe1c51621638459949de0229d7e Mon Sep 17 00:00:00 2001 From: VickyStash Date: Mon, 30 Dec 2024 20:52:03 +0100 Subject: [PATCH 15/18] Remove ReportUtils.ts from ignored files --- .eslintrc.changed.js | 1 - src/libs/ReportUtils.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.eslintrc.changed.js b/.eslintrc.changed.js index f602bc5c368c..078103b46551 100644 --- a/.eslintrc.changed.js +++ b/.eslintrc.changed.js @@ -11,7 +11,6 @@ module.exports = { overrides: [ { files: [ - 'src/libs/ReportUtils.ts', 'src/libs/actions/IOU.ts', 'src/libs/actions/Report.ts', 'src/libs/actions/Task.ts', diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b9750f08dd85..576440a76158 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8593,7 +8593,7 @@ function hasInvoiceReports() { } function getReportMetadata(reportID?: string) { - return allReportMetadataKeyValue[reportID ?? '-1']; + return reportID ? allReportMetadataKeyValue[reportID] : undefined; } export { From 3a7151df262ecef8debbcd9b6cdb004f6084f1d3 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Mon, 30 Dec 2024 21:22:11 +0100 Subject: [PATCH 16/18] Minor type update --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 576440a76158..1ae5413546f2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8592,7 +8592,7 @@ function hasInvoiceReports() { return reports.some((report) => isInvoiceReport(report)); } -function getReportMetadata(reportID?: string) { +function getReportMetadata(reportID: string | undefined) { return reportID ? allReportMetadataKeyValue[reportID] : undefined; } From 5869543408ec3ec4c1a945e2113fac5a90f9ac63 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Tue, 31 Dec 2024 14:09:25 +0100 Subject: [PATCH 17/18] Remove ReportActionsUtils file from ignored list as well --- .eslintrc.changed.js | 1 - 1 file changed, 1 deletion(-) diff --git a/.eslintrc.changed.js b/.eslintrc.changed.js index 078103b46551..55472b10ea86 100644 --- a/.eslintrc.changed.js +++ b/.eslintrc.changed.js @@ -15,7 +15,6 @@ module.exports = { 'src/libs/actions/Report.ts', 'src/libs/actions/Task.ts', 'src/libs/OptionsListUtils.ts', - 'src/libs/ReportActionsUtils.ts', 'src/libs/TransactionUtils/index.ts', 'src/pages/home/ReportScreen.tsx', 'src/pages/workspace/WorkspaceInitialPage.tsx', From a7516f56fc644c1dd7e5a4b9448843e24191a1cc Mon Sep 17 00:00:00 2001 From: VickyStash Date: Thu, 2 Jan 2025 12:42:08 +0100 Subject: [PATCH 18/18] Add warn logs --- src/libs/ReportUtils.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 1ae5413546f2..4b7aaa62cdbf 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3438,6 +3438,7 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, bac const transactionID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID; if (!transactionID || !reportAction.childReportID) { + Log.warn('Missing transactionID and reportAction.childReportID during the change of the money request hold status'); return; } @@ -4293,6 +4294,8 @@ function goBackToDetailsPage(report: OnyxEntry, backTo?: string) { if (report?.reportID) { Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report.reportID, backTo)); + } else { + Log.warn('Missing reportID during navigation back to the details page'); } } @@ -8328,6 +8331,8 @@ function createDraftTransactionAndNavigateToParticipantSelector( ]); if (policyExpenseReportID) { Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, policyExpenseReportID)); + } else { + Log.warn('policyExpenseReportID is not valid during expense categorizing'); } return; } @@ -8350,6 +8355,8 @@ function createDraftTransactionAndNavigateToParticipantSelector( ]); if (policyExpenseReportID) { Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, policyExpenseReportID)); + } else { + Log.warn('policyExpenseReportID is not valid during expense categorizing'); } return; }