From be5bcfa3b7cd047c48e1b542bb5c2abe25126f9c Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Mon, 13 May 2024 10:01:05 +0530 Subject: [PATCH 1/6] feat: [Held requests] option does not show in the preview overflow menu. Signed-off-by: Krishna Gupta --- src/libs/ReportUtils.ts | 86 +++++++++++++++++++ .../report/ContextMenu/ContextMenuActions.tsx | 36 ++++++++ 2 files changed, 122 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 51c797937b1d..cb729b3f7dfd 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -14,6 +14,7 @@ import * as Expensicons from '@components/Icon/Expensicons'; import * as defaultGroupAvatars from '@components/Icon/GroupDefaultAvatars'; import * as defaultWorkspaceAvatars from '@components/Icon/WorkspaceDefaultAvatars'; import type {MoneyRequestAmountInputProps} from '@components/MoneyRequestAmountInput'; +import * as ReportUtils from '@libs/ReportUtils'; import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import type {ParentNavigationSummaryParams, TranslationPaths} from '@src/languages/types'; @@ -2689,6 +2690,89 @@ function canEditReportAction(reportAction: OnyxEntry): boolean { ); } +function getParentReportAction(parentReportActions: ReportActions | null | undefined, parentReportActionID: string | undefined): ReportAction | null { + if (!parentReportActions || !parentReportActionID) { + return null; + } + return parentReportActions[parentReportActionID ?? '0']; +} + +function canHoldUnholdReportAction(reportAction: OnyxEntry): {canHoldRequest: boolean; canUnholdRequest: boolean} { + if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU) { + return {canHoldRequest: false, canUnholdRequest: false}; + } + const moneyRequestReportID = reportAction?.originalMessage?.IOUReportID ?? 0; + + if (!moneyRequestReportID) { + return {canHoldRequest: false, canUnholdRequest: false}; + } + + const moneyRequestReport = getReport(String(moneyRequestReportID)); + + if (!moneyRequestReport) { + return {canHoldRequest: false, canUnholdRequest: false}; + } + + const isSettled = ReportUtils.isSettled(moneyRequestReport?.reportID); + const isApproved = ReportUtils.isReportApproved(moneyRequestReport); + const transactionID = moneyRequestReport ? reportAction?.originalMessage?.IOUTransactionID : 0; + const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); + const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`; + const parentReportActions = allReportActions?.[parentReportActionsKey]; + const parentReport = getReport(String(moneyRequestReport.parentReportID)); + const parentReportAction = getParentReportAction(parentReportActions, moneyRequestReport?.parentReportActionID); + + const isRequestIOU = parentReport?.type === 'iou'; + const isHoldCreator = ReportUtils.isHoldCreator(transaction, moneyRequestReport?.reportID) && isRequestIOU; + const isTrackExpenseReport = ReportUtils.isTrackExpenseReport(moneyRequestReport); + const isActionOwner = + typeof parentReportAction?.actorAccountID === 'number' && + typeof currentUserPersonalDetails?.accountID === 'number' && + parentReportAction.actorAccountID === currentUserPersonalDetails?.accountID; + const isApprover = + ReportUtils.isMoneyRequestReport(moneyRequestReport) && moneyRequestReport?.managerID !== null && currentUserPersonalDetails?.accountID === moneyRequestReport?.managerID; + const isOnHold = TransactionUtils.isOnHold(transaction); + const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); + + const canModifyStatus = !isTrackExpenseReport && (isPolicyAdmin || isActionOwner || isApprover); + const isDeletedParentAction = ReportActionsUtils.isDeletedAction(parentReportAction); + + const canHoldOrUnholdRequest = !isSettled && !isApproved && !isDeletedParentAction; + const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && (isHoldCreator || (!isRequestIOU && canModifyStatus)) && !isScanning; + const canUnholdRequest = Boolean(canHoldOrUnholdRequest && isOnHold && (isHoldCreator || (!isRequestIOU && canModifyStatus))); + + return {canHoldRequest, canUnholdRequest}; +} + +const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry): void => { + if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU) { + return; + } + const moneyRequestReportID = reportAction?.originalMessage?.IOUReportID ?? 0; + + const moneyRequestReport = getReport(String(moneyRequestReportID)); + if (!moneyRequestReportID || !moneyRequestReport) { + return; + } + + const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`; + const parentReportActions = allReportActions?.[parentReportActionsKey]; + const parentReportAction = getParentReportAction(parentReportActions, moneyRequestReport?.parentReportActionID); + const transactionID = moneyRequestReport ? reportAction?.originalMessage?.IOUTransactionID : 0; + const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); + const isOnHold = TransactionUtils.isOnHold(transaction); + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`] ?? null; + + // const iouTransactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage?.IOUTransactionID ?? '' : ''; + + if (isOnHold) { + IOU.unholdRequest(transactionID, reportAction.childReportID); + } else { + const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); + Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID, activeRoute)); + } +}; + /** * Gets all transactions on an IOU report with a receipt */ @@ -6607,6 +6691,7 @@ export { canCreateTaskInReport, canCurrentUserOpenReport, canDeleteReportAction, + canHoldUnholdReportAction, canEditFieldOfMoneyRequest, canEditMoneyRequest, canEditPolicyDescription, @@ -6825,6 +6910,7 @@ export { shouldShowMerchantColumn, isCurrentUserInvoiceReceiver, isDraftReport, + changeMoneyRequestHoldStatus, }; export type { diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 105eadffd436..5d5b6c070eb0 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -255,6 +255,42 @@ const ContextMenuActions: ContextMenuAction[] = [ }, getDescription: () => {}, }, + { + isAnonymousAction: false, + textTranslateKey: 'iou.unholdExpense', + icon: Expensicons.Stopwatch, + shouldShow: (type, reportAction) => + type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canEditReportAction(reportAction) && ReportUtils.canHoldUnholdReportAction(reportAction).canUnholdRequest, + onPress: (closePopover, {reportAction}) => { + // const hold=ReportUtils.changeMoneyRequestHoldStatus(). + if (closePopover) { + hideContextMenu(false, () => ReportUtils.changeMoneyRequestHoldStatus(reportAction)); + return; + } + + // No popover to hide, call changeMoneyRequestHoldStatus immediately + ReportUtils.changeMoneyRequestHoldStatus(reportAction); + }, + getDescription: () => {}, + }, + { + isAnonymousAction: false, + textTranslateKey: 'iou.hold', + icon: Expensicons.Stopwatch, + shouldShow: (type, reportAction) => + type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canEditReportAction(reportAction) && ReportUtils.canHoldUnholdReportAction(reportAction).canHoldRequest, + onPress: (closePopover, {reportAction}) => { + // const hold=ReportUtils.changeMoneyRequestHoldStatus(). + if (closePopover) { + hideContextMenu(false, () => ReportUtils.changeMoneyRequestHoldStatus(reportAction)); + return; + } + + // No popover to hide, call changeMoneyRequestHoldStatus immediately + ReportUtils.changeMoneyRequestHoldStatus(reportAction); + }, + getDescription: () => {}, + }, { isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.joinThread', From d8fc20b3c8056f80f0ff498780b8e2b4cd975881 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Fri, 17 May 2024 14:30:07 +0530 Subject: [PATCH 2/6] minor fixes. Signed-off-by: Krishna Gupta --- src/libs/ReportUtils.ts | 47 ++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e563bbc14500..8454ea5b918c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -14,7 +14,6 @@ import * as Expensicons from '@components/Icon/Expensicons'; import * as defaultGroupAvatars from '@components/Icon/GroupDefaultAvatars'; import * as defaultWorkspaceAvatars from '@components/Icon/WorkspaceDefaultAvatars'; import type {MoneyRequestAmountInputProps} from '@components/MoneyRequestAmountInput'; -import * as ReportUtils from '@libs/ReportUtils'; import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import type {ParentNavigationSummaryParams, TranslationPaths} from '@src/languages/types'; @@ -2392,6 +2391,14 @@ function isReportFieldOfTypeTitle(reportField: OnyxEntry): bo return reportField?.type === 'formula' && reportField?.fieldID === CONST.REPORT_FIELD_TITLE_FIELD_ID; } +/** + * Check if Report has any held expenses + */ +function isHoldCreator(transaction: OnyxEntry, reportID: string): boolean { + const holdReportAction = ReportActionsUtils.getReportAction(reportID, `${transaction?.comment?.hold ?? ''}`); + return isActionCreator(holdReportAction); +} + /** * Check if report fields are available to use in a report */ @@ -2731,8 +2738,8 @@ function canHoldUnholdReportAction(reportAction: OnyxEntry): {canH return {canHoldRequest: false, canUnholdRequest: false}; } - const isSettled = ReportUtils.isSettled(moneyRequestReport?.reportID); - const isApproved = ReportUtils.isReportApproved(moneyRequestReport); + const isRequestSettled = isSettled(moneyRequestReport?.reportID); + const isApproved = isReportApproved(moneyRequestReport); const transactionID = moneyRequestReport ? reportAction?.originalMessage?.IOUTransactionID : 0; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`; @@ -2741,23 +2748,22 @@ function canHoldUnholdReportAction(reportAction: OnyxEntry): {canH const parentReportAction = getParentReportAction(parentReportActions, moneyRequestReport?.parentReportActionID); const isRequestIOU = parentReport?.type === 'iou'; - const isHoldCreator = ReportUtils.isHoldCreator(transaction, moneyRequestReport?.reportID) && isRequestIOU; - const isTrackExpenseReport = ReportUtils.isTrackExpenseReport(moneyRequestReport); + const isRequestHoldCreator = isHoldCreator(transaction, moneyRequestReport?.reportID) && isRequestIOU; + const isTrackExpenseMoneyReport = isTrackExpenseReport(moneyRequestReport); const isActionOwner = typeof parentReportAction?.actorAccountID === 'number' && typeof currentUserPersonalDetails?.accountID === 'number' && parentReportAction.actorAccountID === currentUserPersonalDetails?.accountID; - const isApprover = - ReportUtils.isMoneyRequestReport(moneyRequestReport) && moneyRequestReport?.managerID !== null && currentUserPersonalDetails?.accountID === moneyRequestReport?.managerID; + const isApprover = isMoneyRequestReport(moneyRequestReport) && moneyRequestReport?.managerID !== null && currentUserPersonalDetails?.accountID === moneyRequestReport?.managerID; const isOnHold = TransactionUtils.isOnHold(transaction); const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); - const canModifyStatus = !isTrackExpenseReport && (isPolicyAdmin || isActionOwner || isApprover); + const canModifyStatus = !isTrackExpenseMoneyReport && (isPolicyAdmin || isActionOwner || isApprover); const isDeletedParentAction = ReportActionsUtils.isDeletedAction(parentReportAction); - const canHoldOrUnholdRequest = !isSettled && !isApproved && !isDeletedParentAction; - const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && (isHoldCreator || (!isRequestIOU && canModifyStatus)) && !isScanning; - const canUnholdRequest = Boolean(canHoldOrUnholdRequest && isOnHold && (isHoldCreator || (!isRequestIOU && canModifyStatus))); + const canHoldOrUnholdRequest = !isRequestSettled && !isApproved && !isDeletedParentAction; + const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus)) && !isScanning; + const canUnholdRequest = Boolean(canHoldOrUnholdRequest && isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus))); return {canHoldRequest, canUnholdRequest}; } @@ -2773,21 +2779,16 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry): vo return; } - const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`; - const parentReportActions = allReportActions?.[parentReportActionsKey]; - const parentReportAction = getParentReportAction(parentReportActions, moneyRequestReport?.parentReportActionID); - const transactionID = moneyRequestReport ? reportAction?.originalMessage?.IOUTransactionID : 0; + const transactionID = reportAction?.originalMessage?.IOUTransactionID ?? ''; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); const isOnHold = TransactionUtils.isOnHold(transaction); const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`] ?? null; - // const iouTransactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage?.IOUTransactionID ?? '' : ''; - if (isOnHold) { - IOU.unholdRequest(transactionID, reportAction.childReportID); + IOU.unholdRequest(transactionID, reportAction.childReportID ?? ''); } else { const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); - Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID, activeRoute)); + Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID ?? '', activeRoute)); } }; @@ -6294,14 +6295,6 @@ function navigateToPrivateNotes(report: OnyxEntry, session: OnyxEntry, reportID: string): boolean { - const holdReportAction = ReportActionsUtils.getReportAction(reportID, `${transaction?.comment?.hold ?? ''}`); - return isActionCreator(holdReportAction); -} - /** * Get all held transactions of a iouReport */ From 9f330e4d6f101b5cb6c6bffc3c28b847bed73af3 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Tue, 21 May 2024 18:38:16 +0530 Subject: [PATCH 3/6] canHoldUnholdReportAction util function refactoring. Signed-off-by: Krishna Gupta --- src/libs/ReportUtils.ts | 21 ++++--------------- .../report/ContextMenu/ContextMenuActions.tsx | 2 -- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8454ea5b918c..23874dc2da13 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2715,26 +2715,15 @@ function canEditReportAction(reportAction: OnyxEntry): boolean { ); } -function getParentReportAction(parentReportActions: ReportActions | null | undefined, parentReportActionID: string | undefined): ReportAction | null { - if (!parentReportActions || !parentReportActionID) { - return null; - } - return parentReportActions[parentReportActionID ?? '0']; -} - function canHoldUnholdReportAction(reportAction: OnyxEntry): {canHoldRequest: boolean; canUnholdRequest: boolean} { if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU) { return {canHoldRequest: false, canUnholdRequest: false}; } - const moneyRequestReportID = reportAction?.originalMessage?.IOUReportID ?? 0; - - if (!moneyRequestReportID) { - return {canHoldRequest: false, canUnholdRequest: false}; - } + const moneyRequestReportID = reportAction?.originalMessage?.IOUReportID ?? 0; const moneyRequestReport = getReport(String(moneyRequestReportID)); - if (!moneyRequestReport) { + if (!moneyRequestReportID || !moneyRequestReport) { return {canHoldRequest: false, canUnholdRequest: false}; } @@ -2742,10 +2731,8 @@ function canHoldUnholdReportAction(reportAction: OnyxEntry): {canH const isApproved = isReportApproved(moneyRequestReport); const transactionID = moneyRequestReport ? reportAction?.originalMessage?.IOUTransactionID : 0; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); - const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`; - const parentReportActions = allReportActions?.[parentReportActionsKey]; const parentReport = getReport(String(moneyRequestReport.parentReportID)); - const parentReportAction = getParentReportAction(parentReportActions, moneyRequestReport?.parentReportActionID); + const parentReportAction = ReportActionsUtils.getParentReportAction(moneyRequestReport); const isRequestIOU = parentReport?.type === 'iou'; const isRequestHoldCreator = isHoldCreator(transaction, moneyRequestReport?.reportID) && isRequestIOU; @@ -2759,7 +2746,7 @@ function canHoldUnholdReportAction(reportAction: OnyxEntry): {canH const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); const canModifyStatus = !isTrackExpenseMoneyReport && (isPolicyAdmin || isActionOwner || isApprover); - const isDeletedParentAction = ReportActionsUtils.isDeletedAction(parentReportAction); + const isDeletedParentAction = !isEmpty(parentReportAction) ? ReportActionsUtils.isDeletedAction(parentReportAction as ReportAction) : true; const canHoldOrUnholdRequest = !isRequestSettled && !isApproved && !isDeletedParentAction; const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus)) && !isScanning; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 5d5b6c070eb0..5ccdefce0646 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -262,7 +262,6 @@ const ContextMenuActions: ContextMenuAction[] = [ shouldShow: (type, reportAction) => type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canEditReportAction(reportAction) && ReportUtils.canHoldUnholdReportAction(reportAction).canUnholdRequest, onPress: (closePopover, {reportAction}) => { - // const hold=ReportUtils.changeMoneyRequestHoldStatus(). if (closePopover) { hideContextMenu(false, () => ReportUtils.changeMoneyRequestHoldStatus(reportAction)); return; @@ -280,7 +279,6 @@ const ContextMenuActions: ContextMenuAction[] = [ shouldShow: (type, reportAction) => type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canEditReportAction(reportAction) && ReportUtils.canHoldUnholdReportAction(reportAction).canHoldRequest, onPress: (closePopover, {reportAction}) => { - // const hold=ReportUtils.changeMoneyRequestHoldStatus(). if (closePopover) { hideContextMenu(false, () => ReportUtils.changeMoneyRequestHoldStatus(reportAction)); return; From 0fac245e625ef26324c3b32c52f259698906dfa9 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Wed, 22 May 2024 02:21:04 +0530 Subject: [PATCH 4/6] add getParentReportAction in ReportUtils. Signed-off-by: Krishna Gupta --- src/libs/ReportUtils.ts | 15 +++++++++++++-- src/pages/home/ReportScreen.tsx | 13 +++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 23874dc2da13..d5f0cc8a3158 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2715,6 +2715,13 @@ function canEditReportAction(reportAction: OnyxEntry): boolean { ); } +function getParentReportAction(parentReportActions: OnyxEntry, parentReportActionID: string | undefined): OnyxEntry { + if (!parentReportActions || !parentReportActionID) { + return null; + } + return parentReportActions[parentReportActionID ?? '0']; +} + function canHoldUnholdReportAction(reportAction: OnyxEntry): {canHoldRequest: boolean; canUnholdRequest: boolean} { if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU) { return {canHoldRequest: false, canUnholdRequest: false}; @@ -2731,8 +2738,11 @@ function canHoldUnholdReportAction(reportAction: OnyxEntry): {canH const isApproved = isReportApproved(moneyRequestReport); const transactionID = moneyRequestReport ? reportAction?.originalMessage?.IOUTransactionID : 0; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); + + const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`; + const parentReportActions = allReportActions?.[parentReportActionsKey]; const parentReport = getReport(String(moneyRequestReport.parentReportID)); - const parentReportAction = ReportActionsUtils.getParentReportAction(moneyRequestReport); + const parentReportAction = getParentReportAction(parentReportActions ?? {}, moneyRequestReport?.parentReportActionID); const isRequestIOU = parentReport?.type === 'iou'; const isRequestHoldCreator = isHoldCreator(transaction, moneyRequestReport?.reportID) && isRequestIOU; @@ -2746,7 +2756,7 @@ function canHoldUnholdReportAction(reportAction: OnyxEntry): {canH const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); const canModifyStatus = !isTrackExpenseMoneyReport && (isPolicyAdmin || isActionOwner || isApprover); - const isDeletedParentAction = !isEmpty(parentReportAction) ? ReportActionsUtils.isDeletedAction(parentReportAction as ReportAction) : true; + const isDeletedParentAction = ReportActionsUtils.isDeletedAction(parentReportAction); const canHoldOrUnholdRequest = !isRequestSettled && !isApproved && !isDeletedParentAction; const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus)) && !isScanning; @@ -6847,6 +6857,7 @@ export { getOriginalReportID, getOutstandingChildRequest, getParentNavigationSubtitle, + getParentReportAction, getParsedComment, getParticipantAccountIDs, getParticipants, diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 8620d8d4866e..d55f5f42b34d 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -124,13 +124,6 @@ function isEmpty(report: OnyxTypes.Report): boolean { return !Object.values(report).some((value) => value !== undefined && value !== ''); } -function getParentReportAction(parentReportActions: OnyxEntry, parentReportActionID: string | undefined): OnyxEntry { - if (!parentReportActions || !parentReportActionID) { - return null; - } - return parentReportActions[parentReportActionID ?? '0']; -} - function ReportScreen({ betas = [], route, @@ -261,7 +254,7 @@ function ReportScreen({ ], ); - const parentReportAction = useMemo(() => getParentReportAction(parentReportActions, report?.parentReportActionID), [parentReportActions, report.parentReportActionID]); + const parentReportAction = useMemo(() => ReportUtils.getParentReportAction(parentReportActions, report?.parentReportActionID), [parentReportActions, report.parentReportActionID]); const prevReport = usePrevious(report); const prevUserLeavingStatus = usePrevious(userLeavingStatus); @@ -813,8 +806,8 @@ export default withCurrentReportID( }, })( memo(ReportScreen, (prevProps, nextProps) => { - const prevParentReportAction = getParentReportAction(prevProps.parentReportActions, prevProps.report?.parentReportActionID); - const nextParentReportAction = getParentReportAction(nextProps.parentReportActions, nextProps.report?.parentReportActionID); + const prevParentReportAction = ReportUtils.getParentReportAction(prevProps.parentReportActions, prevProps.report?.parentReportActionID); + const nextParentReportAction = ReportUtils.getParentReportAction(nextProps.parentReportActions, nextProps.report?.parentReportActionID); return ( prevProps.isSidebarLoaded === nextProps.isSidebarLoaded && lodashIsEqual(prevProps.sortedAllReportActions, nextProps.sortedAllReportActions) && From 2df4f551b736e393cb4abc275cf9204420c2928f Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Sat, 8 Jun 2024 13:43:44 +0530 Subject: [PATCH 5/6] use deprecated ReportActionsUtils.getParentReportAction. Signed-off-by: Krishna Gupta --- src/libs/ReportUtils.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 435460ec596e..fe732724ef3e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2729,13 +2729,6 @@ function canEditReportAction(reportAction: OnyxEntry): boolean { ); } -function getParentReportAction(parentReportActions: OnyxEntry, parentReportActionID: string | undefined): OnyxEntry { - if (!parentReportActions || !parentReportActionID) { - return null; - } - return parentReportActions[parentReportActionID ?? '0']; -} - function canHoldUnholdReportAction(reportAction: OnyxEntry): {canHoldRequest: boolean; canUnholdRequest: boolean} { if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU) { return {canHoldRequest: false, canUnholdRequest: false}; @@ -2753,10 +2746,8 @@ function canHoldUnholdReportAction(reportAction: OnyxEntry): {canH const transactionID = moneyRequestReport ? reportAction?.originalMessage?.IOUTransactionID : 0; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); - const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`; - const parentReportActions = allReportActions?.[parentReportActionsKey]; const parentReport = getReport(String(moneyRequestReport.parentReportID)); - const parentReportAction = getParentReportAction(parentReportActions ?? {}, moneyRequestReport?.parentReportActionID); + const parentReportAction = ReportActionsUtils.getParentReportAction(moneyRequestReport); const isRequestIOU = parentReport?.type === 'iou'; const isRequestHoldCreator = isHoldCreator(transaction, moneyRequestReport?.reportID) && isRequestIOU; @@ -2770,7 +2761,7 @@ function canHoldUnholdReportAction(reportAction: OnyxEntry): {canH const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); const canModifyStatus = !isTrackExpenseMoneyReport && (isPolicyAdmin || isActionOwner || isApprover); - const isDeletedParentAction = ReportActionsUtils.isDeletedAction(parentReportAction); + const isDeletedParentAction = isEmptyObject(parentReportAction) || ReportActionsUtils.isDeletedAction(parentReportAction); const canHoldOrUnholdRequest = !isRequestSettled && !isApproved && !isDeletedParentAction; const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus)) && !isScanning; @@ -7031,7 +7022,6 @@ export { getOriginalReportID, getOutstandingChildRequest, getParentNavigationSubtitle, - getParentReportAction, getParsedComment, getParticipantAccountIDs, getParticipants, From 721e40787bbfdaf9cbdc5f040edd04914f36ac4a Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Sat, 8 Jun 2024 14:19:36 +0530 Subject: [PATCH 6/6] fix lint issue. Signed-off-by: Krishna Gupta --- 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 fe732724ef3e..269f4c7bc01b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2765,7 +2765,7 @@ function canHoldUnholdReportAction(reportAction: OnyxEntry): {canH const canHoldOrUnholdRequest = !isRequestSettled && !isApproved && !isDeletedParentAction; const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus)) && !isScanning; - const canUnholdRequest = Boolean(canHoldOrUnholdRequest && isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus))); + const canUnholdRequest = !!(canHoldOrUnholdRequest && isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus))); return {canHoldRequest, canUnholdRequest}; }