From 9918425c48ae370c47e2825d83fa3ae6c2bfafa4 Mon Sep 17 00:00:00 2001 From: Someshwar Tripathi Date: Wed, 3 Jul 2024 00:08:41 +0530 Subject: [PATCH 01/11] Update fallback receipt logic --- .../SelectionList/Search/TransactionListItemRow.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/SelectionList/Search/TransactionListItemRow.tsx b/src/components/SelectionList/Search/TransactionListItemRow.tsx index 0adc7ee21fd1..1772f76ed88a 100644 --- a/src/components/SelectionList/Search/TransactionListItemRow.tsx +++ b/src/components/SelectionList/Search/TransactionListItemRow.tsx @@ -12,6 +12,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as CurrencyUtils from '@libs/CurrencyUtils'; +import * as ReportUtils from '@libs/ReportUtils'; import DateUtils from '@libs/DateUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; @@ -66,6 +67,8 @@ function ReceiptCell({transactionItem}: TransactionCellProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); + const canModifyReceipt = !ReportUtils.isReportApproved(transactionItem.reportID) && !ReportUtils.isSettled(transactionItem.reportID); + return ( Date: Mon, 15 Jul 2024 08:20:06 +0530 Subject: [PATCH 02/11] Prettier fix --- .../SelectionList/Search/TransactionListItemRow.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/SelectionList/Search/TransactionListItemRow.tsx b/src/components/SelectionList/Search/TransactionListItemRow.tsx index 00e555198554..0e4e1393610b 100644 --- a/src/components/SelectionList/Search/TransactionListItemRow.tsx +++ b/src/components/SelectionList/Search/TransactionListItemRow.tsx @@ -14,8 +14,8 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as CurrencyUtils from '@libs/CurrencyUtils'; -import * as ReportUtils from '@libs/ReportUtils'; import DateUtils from '@libs/DateUtils'; +import * as ReportUtils from '@libs/ReportUtils'; import StringUtils from '@libs/StringUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; @@ -78,7 +78,7 @@ function ReceiptCell({transactionItem}: TransactionCellProps) { const backgroundStyles = transactionItem.isSelected ? StyleUtils.getBackgroundColorStyle(theme.buttonHoveredBG) : StyleUtils.getBackgroundColorStyle(theme.border); const canModifyReceipt = !ReportUtils.isReportApproved(transactionItem.reportID) && !ReportUtils.isSettled(transactionItem.reportID); - + return ( Date: Tue, 16 Jul 2024 01:02:55 +0530 Subject: [PATCH 03/11] Update isClosedReport to accept reportID as param --- src/libs/ReportUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f7dca71fd15f..f2be823a1fab 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1286,7 +1286,8 @@ function isArchivedRoomWithID(reportID?: string) { /** * Whether the provided report is a closed report */ -function isClosedReport(report: OnyxEntry): boolean { +function isClosedReport(reportOrID: OnyxInputOrEntry | string): boolean { + const report = typeof reportOrID === 'string' ? ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED; } From 5abb0e3d0095db22a42eada369f909d7aaca6c97 Mon Sep 17 00:00:00 2001 From: Someshwar Tripathi Date: Tue, 16 Jul 2024 01:04:06 +0530 Subject: [PATCH 04/11] Update canModifyReceipt --- src/components/SelectionList/Search/TransactionListItemRow.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SelectionList/Search/TransactionListItemRow.tsx b/src/components/SelectionList/Search/TransactionListItemRow.tsx index 0e4e1393610b..2c245b761173 100644 --- a/src/components/SelectionList/Search/TransactionListItemRow.tsx +++ b/src/components/SelectionList/Search/TransactionListItemRow.tsx @@ -77,7 +77,7 @@ function ReceiptCell({transactionItem}: TransactionCellProps) { const StyleUtils = useStyleUtils(); const backgroundStyles = transactionItem.isSelected ? StyleUtils.getBackgroundColorStyle(theme.buttonHoveredBG) : StyleUtils.getBackgroundColorStyle(theme.border); - const canModifyReceipt = !ReportUtils.isReportApproved(transactionItem.reportID) && !ReportUtils.isSettled(transactionItem.reportID); + const canModifyReceipt = !ReportUtils.isReportApproved(transactionItem.reportID) && !ReportUtils.isSettled(transactionItem.reportID) && !ReportUtils.isClosedReport(transactionItem.reportID); return ( Date: Wed, 31 Jul 2024 22:47:39 +0530 Subject: [PATCH 05/11] Add util functions for isReportOpen and isReportSubmitted --- src/libs/ReportUtils.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 57ed13c69fd0..ffba5fa1cc08 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -847,6 +847,26 @@ function isOpenExpenseReport(report: OnyxInputOrEntry): boolean { return isExpenseReport(report) && report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN; } +/** + * Checks if the supplied report is a report in Open state and status. + */ +function isReportOpen(reportOrID: OnyxInputOrEntry | string): boolean { + const report = typeof reportOrID === 'string' ? ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; + + // console.log('getAllReports: ', ReportConnection.getAllReports(), 'length: ', Object.keys(ReportConnection.getAllReports()).length); + // console.log('isReportOpen report: ', report); + + return report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN; +} + +/** + * Checks if the supplied report is a report in Submitted state and status. + */ +function isReportSubmitted(reportOrID: OnyxInputOrEntry | string): boolean { + const report = typeof reportOrID === 'string' ? ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; + return report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED; +} + /** * Checks if the supplied report has a member with the array passed in params. */ @@ -7577,6 +7597,8 @@ export { getReport, getReportNameValuePairs, hasReportViolations, + isReportOpen, + isReportSubmitted, }; export type { From 44bde03788bf59dae05c49fe68b4e8310e3a4d6c Mon Sep 17 00:00:00 2001 From: Someshwar Tripathi Date: Wed, 31 Jul 2024 22:48:17 +0530 Subject: [PATCH 06/11] Update logic for canModifyReceipt --- .../SelectionList/Search/TransactionListItemRow.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/SelectionList/Search/TransactionListItemRow.tsx b/src/components/SelectionList/Search/TransactionListItemRow.tsx index 2f5cd94468e5..9bd2e076aa27 100644 --- a/src/components/SelectionList/Search/TransactionListItemRow.tsx +++ b/src/components/SelectionList/Search/TransactionListItemRow.tsx @@ -77,7 +77,11 @@ function ReceiptCell({transactionItem}: TransactionCellProps) { const StyleUtils = useStyleUtils(); const backgroundStyles = transactionItem.isSelected ? StyleUtils.getBackgroundColorStyle(theme.buttonHoveredBG) : StyleUtils.getBackgroundColorStyle(theme.border); - const canModifyReceipt = !ReportUtils.isReportApproved(transactionItem.reportID) && !ReportUtils.isSettled(transactionItem.reportID) && !ReportUtils.isClosedReport(transactionItem.reportID); + + const reportID = transactionItem.reportID !== '0' ? transactionItem.reportID : transactionItem.transactionThreadReportID + const isPaidAction = transactionItem.action === CONST.SEARCH.ACTION_TYPES.PAID; + const isDoneAction = transactionItem.action === CONST.SEARCH.ACTION_TYPES.DONE; + const canModifyReceipt = !isPaidAction && !isDoneAction && (ReportUtils.isReportOpen(reportID) || ReportUtils.isReportSubmitted(reportID)); return ( Date: Thu, 1 Aug 2024 01:11:45 +0530 Subject: [PATCH 07/11] Prettier fix --- .../SelectionList/Search/TransactionListItemRow.tsx | 4 ++-- src/libs/ReportUtils.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/SelectionList/Search/TransactionListItemRow.tsx b/src/components/SelectionList/Search/TransactionListItemRow.tsx index 9bd2e076aa27..627d6ef88ca6 100644 --- a/src/components/SelectionList/Search/TransactionListItemRow.tsx +++ b/src/components/SelectionList/Search/TransactionListItemRow.tsx @@ -77,8 +77,8 @@ function ReceiptCell({transactionItem}: TransactionCellProps) { const StyleUtils = useStyleUtils(); const backgroundStyles = transactionItem.isSelected ? StyleUtils.getBackgroundColorStyle(theme.buttonHoveredBG) : StyleUtils.getBackgroundColorStyle(theme.border); - - const reportID = transactionItem.reportID !== '0' ? transactionItem.reportID : transactionItem.transactionThreadReportID + + const reportID = transactionItem.reportID !== '0' ? transactionItem.reportID : transactionItem.transactionThreadReportID; const isPaidAction = transactionItem.action === CONST.SEARCH.ACTION_TYPES.PAID; const isDoneAction = transactionItem.action === CONST.SEARCH.ACTION_TYPES.DONE; const canModifyReceipt = !isPaidAction && !isDoneAction && (ReportUtils.isReportOpen(reportID) || ReportUtils.isReportSubmitted(reportID)); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ffba5fa1cc08..524414e2a70a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -855,7 +855,7 @@ function isReportOpen(reportOrID: OnyxInputOrEntry | string): boolean { // console.log('getAllReports: ', ReportConnection.getAllReports(), 'length: ', Object.keys(ReportConnection.getAllReports()).length); // console.log('isReportOpen report: ', report); - + return report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN; } From e507698381586131f5440b8e11ca572d053bfa20 Mon Sep 17 00:00:00 2001 From: Someshwar Tripathi Date: Thu, 1 Aug 2024 03:08:34 +0530 Subject: [PATCH 08/11] Remove comment --- src/libs/ReportUtils.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b10d848ac34a..846283c7a5ba 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -875,10 +875,6 @@ function isOpenExpenseReport(report: OnyxInputOrEntry): boolean { */ function isReportOpen(reportOrID: OnyxInputOrEntry | string): boolean { const report = typeof reportOrID === 'string' ? ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; - - // console.log('getAllReports: ', ReportConnection.getAllReports(), 'length: ', Object.keys(ReportConnection.getAllReports()).length); - // console.log('isReportOpen report: ', report); - return report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN; } From 80a687413c633495821b7b4d330a1f86b1dfeb34 Mon Sep 17 00:00:00 2001 From: Someshwar Tripathi Date: Fri, 2 Aug 2024 19:37:42 +0530 Subject: [PATCH 09/11] Update logic for Receipt Cell --- .../SelectionList/Search/TransactionListItemRow.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/SelectionList/Search/TransactionListItemRow.tsx b/src/components/SelectionList/Search/TransactionListItemRow.tsx index 627d6ef88ca6..7ab47e941f0c 100644 --- a/src/components/SelectionList/Search/TransactionListItemRow.tsx +++ b/src/components/SelectionList/Search/TransactionListItemRow.tsx @@ -78,10 +78,8 @@ function ReceiptCell({transactionItem}: TransactionCellProps) { const backgroundStyles = transactionItem.isSelected ? StyleUtils.getBackgroundColorStyle(theme.buttonHoveredBG) : StyleUtils.getBackgroundColorStyle(theme.border); - const reportID = transactionItem.reportID !== '0' ? transactionItem.reportID : transactionItem.transactionThreadReportID; - const isPaidAction = transactionItem.action === CONST.SEARCH.ACTION_TYPES.PAID; - const isDoneAction = transactionItem.action === CONST.SEARCH.ACTION_TYPES.DONE; - const canModifyReceipt = !isPaidAction && !isDoneAction && (ReportUtils.isReportOpen(reportID) || ReportUtils.isReportSubmitted(reportID)); + const isViewAction = transactionItem.action === CONST.SEARCH.ACTION_TYPES.VIEW; + const canModifyReceipt = isViewAction && transactionItem.canDelete; return ( Date: Fri, 2 Aug 2024 20:45:01 +0530 Subject: [PATCH 10/11] lint fix --- src/components/SelectionList/Search/TransactionListItemRow.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/SelectionList/Search/TransactionListItemRow.tsx b/src/components/SelectionList/Search/TransactionListItemRow.tsx index 7ab47e941f0c..be42642316b0 100644 --- a/src/components/SelectionList/Search/TransactionListItemRow.tsx +++ b/src/components/SelectionList/Search/TransactionListItemRow.tsx @@ -15,7 +15,6 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import DateUtils from '@libs/DateUtils'; -import * as ReportUtils from '@libs/ReportUtils'; import StringUtils from '@libs/StringUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; From 83f8d9b31b53e47de6435c9668c951cd88993525 Mon Sep 17 00:00:00 2001 From: Someshwar Tripathi Date: Sat, 3 Aug 2024 23:01:43 +0530 Subject: [PATCH 11/11] Revert ReportUtils changes --- src/libs/ReportUtils.ts | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 846283c7a5ba..b5780c889b21 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -870,22 +870,6 @@ function isOpenExpenseReport(report: OnyxInputOrEntry): boolean { return isExpenseReport(report) && report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN; } -/** - * Checks if the supplied report is a report in Open state and status. - */ -function isReportOpen(reportOrID: OnyxInputOrEntry | string): boolean { - const report = typeof reportOrID === 'string' ? ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; - return report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN; -} - -/** - * Checks if the supplied report is a report in Submitted state and status. - */ -function isReportSubmitted(reportOrID: OnyxInputOrEntry | string): boolean { - const report = typeof reportOrID === 'string' ? ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; - return report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED; -} - /** * Checks if the supplied report has a member with the array passed in params. */ @@ -1366,8 +1350,7 @@ function isArchivedRoomWithID(reportID?: string) { /** * Whether the provided report is a closed report */ -function isClosedReport(reportOrID: OnyxInputOrEntry | string): boolean { - const report = typeof reportOrID === 'string' ? ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; +function isClosedReport(report: OnyxEntry): boolean { return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED; } @@ -7723,8 +7706,6 @@ export { getReport, getReportNameValuePairs, hasReportViolations, - isReportOpen, - isReportSubmitted, }; export type {