From 6cf9590baa272605aff339645a9ff9afa6fbc724 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 9 Jul 2024 12:05:39 +0700 Subject: [PATCH 1/9] fix: replace attachmentInfo with isAttachmentWithText --- src/libs/ReportActionsUtils.ts | 4 +- src/libs/ReportUtils.ts | 42 +++++++++---------- .../report/ReportActionsListItemRenderer.tsx | 4 +- src/types/onyx/ReportAction.ts | 11 +++-- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 3f8acd0e06fe..19d8a5d74554 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -981,8 +981,8 @@ function getAllReportActions(reportID: string): ReportActions { function isReportActionAttachment(reportAction: OnyxInputOrEntry): boolean { const message = getReportActionMessage(reportAction); - if (reportAction && ('isAttachment' in reportAction || 'attachmentInfo' in reportAction)) { - return reportAction?.isAttachment ?? !!reportAction?.attachmentInfo ?? false; + if (reportAction && ('isAttachmentOnly' in reportAction || 'isAttachmentWithText' in reportAction)) { + return reportAction?.isAttachmentOnly ?? !!reportAction?.isAttachmentWithText ?? false; } if (message) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index bf1d86dad32f..9c4a14982844 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -101,8 +101,8 @@ type OptimisticAddCommentReportAction = Pick< | 'created' | 'message' | 'isFirstItem' - | 'isAttachment' - | 'attachmentInfo' + | 'isAttachmentOnly' + | 'isAttachmentWithText' | 'pendingAction' | 'shouldShow' | 'originalMessage' @@ -157,7 +157,7 @@ type OptimisticIOUReportAction = Pick< | 'actorAccountID' | 'automatic' | 'avatar' - | 'isAttachment' + | 'isAttachmentOnly' | 'originalMessage' | 'message' | 'person' @@ -185,12 +185,12 @@ type ReportOfflinePendingActionAndErrors = { type OptimisticApprovedReportAction = Pick< ReportAction, - 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachment' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' + 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachmentOnly' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' >; type OptimisticUnapprovedReportAction = Pick< ReportAction, - 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachment' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' + 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachmentOnly' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' >; type OptimisticSubmittedReportAction = Pick< @@ -200,7 +200,7 @@ type OptimisticSubmittedReportAction = Pick< | 'adminAccountID' | 'automatic' | 'avatar' - | 'isAttachment' + | 'isAttachmentOnly' | 'originalMessage' | 'message' | 'person' @@ -212,7 +212,7 @@ type OptimisticSubmittedReportAction = Pick< type OptimisticHoldReportAction = Pick< ReportAction, - 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachment' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' + 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachmentOnly' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' >; type OptimisticCancelPaymentReportAction = Pick< @@ -289,7 +289,7 @@ type OptimisticTaskReportAction = Pick< | 'automatic' | 'avatar' | 'created' - | 'isAttachment' + | 'isAttachmentOnly' | 'message' | 'originalMessage' | 'person' @@ -318,7 +318,7 @@ type OptimisticWorkspaceChats = { type OptimisticModifiedExpenseReportAction = Pick< ReportAction, - 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'isAttachment' | 'message' | 'originalMessage' | 'person' | 'pendingAction' | 'reportActionID' | 'shouldShow' + 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'isAttachmentOnly' | 'message' | 'originalMessage' | 'person' | 'pendingAction' | 'reportActionID' | 'shouldShow' > & {reportID?: string}; type OptimisticTaskReport = Pick< @@ -2778,7 +2778,7 @@ function canEditReportAction(reportAction: OnyxInputOrEntry): bool isCommentOrIOU && (!ReportActionsUtils.isMoneyRequestAction(reportAction) || canEditMoneyRequest(reportAction)) && // Returns true for non-IOU actions !isReportMessageAttachment(message) && - (isEmptyObject(reportAction.attachmentInfo) || !reportAction.isOptimisticAction) && + (!!reportAction.isAttachmentWithText || !reportAction.isOptimisticAction) && !ReportActionsUtils.isDeletedAction(reportAction) && !ReportActionsUtils.isCreatedTaskReportAction(reportAction) && reportAction?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE @@ -3712,8 +3712,7 @@ function buildOptimisticAddCommentReportAction( textForNewComment = `${Parser.htmlToText(commentText)}\n${CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML}`; } - const isAttachment = !text && file !== undefined; - const attachmentInfo = file ?? {}; + const isAttachmentWithText = !text && file !== undefined; const accountID = actorAccountID ?? currentUserAccountID; // Remove HTML from text when applying optimistic offline comment @@ -3746,8 +3745,8 @@ function buildOptimisticAddCommentReportAction( whisperedTo: [], }, isFirstItem: false, - isAttachment, - attachmentInfo, + isAttachmentOnly, + isAttachmentWithText, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, shouldShow: true, isOptimisticAction: true, @@ -4149,7 +4148,7 @@ function buildOptimisticIOUReportAction( actorAccountID: currentUserAccountID, automatic: false, avatar: getCurrentUserAvatar(), - isAttachment: false, + isAttachmentOnly: false, originalMessage, message: getIOUReportActionMessage(iouReportID, type, amount, comment, currency, paymentType, isSettlingUp), person: [ @@ -4181,7 +4180,7 @@ function buildOptimisticApprovedReportAction(amount: number, currency: string, e actorAccountID: currentUserAccountID, automatic: false, avatar: getCurrentUserAvatar(), - isAttachment: false, + isAttachmentOnly: false, originalMessage, message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.APPROVED, Math.abs(amount), '', currency), person: [ @@ -4207,7 +4206,7 @@ function buildOptimisticUnapprovedReportAction(amount: number, currency: string, actorAccountID: currentUserAccountID, automatic: false, avatar: getCurrentUserAvatar(), - isAttachment: false, + isAttachmentOnly: false, originalMessage: { amount, currency, @@ -4253,7 +4252,7 @@ function buildOptimisticMovedReportAction(fromPolicyID: string, toPolicyID: stri actorAccountID: currentUserAccountID, automatic: false, avatar: getCurrentUserAvatar(), - isAttachment: false, + isAttachmentOnly: false, originalMessage, message: movedActionMessage, person: [ @@ -4287,7 +4286,7 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, adminAccountID, automatic: false, avatar: getCurrentUserAvatar(), - isAttachment: false, + isAttachmentOnly: false, originalMessage, message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.SUBMITTED, Math.abs(amount), '', currency), person: [ @@ -4406,7 +4405,7 @@ function buildOptimisticModifiedExpenseReportAction( automatic: false, avatar: getCurrentUserAvatar(), created: DateUtils.getDBTime(), - isAttachment: false, + isAttachmentOnly: false, message: [ { // Currently we are composing the message from the originalMessage and message is only used in OldDot and not in the App @@ -4442,7 +4441,6 @@ function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThrea automatic: false, avatar: getCurrentUserAvatar(), created: DateUtils.getDBTime(), - isAttachment: false, message: [ { // Currently we are composing the message from the originalMessage and message is only used in OldDot and not in the App @@ -4545,7 +4543,7 @@ function buildOptimisticTaskReportAction( actorAccountID, automatic: false, avatar: getCurrentUserAvatar(), - isAttachment: false, + isAttachmentOnly: false, originalMessage, message: [ { diff --git a/src/pages/home/report/ReportActionsListItemRenderer.tsx b/src/pages/home/report/ReportActionsListItemRenderer.tsx index 1ef689ab1da4..c57e02f1d0f1 100644 --- a/src/pages/home/report/ReportActionsListItemRenderer.tsx +++ b/src/pages/home/report/ReportActionsListItemRenderer.tsx @@ -104,7 +104,7 @@ function ReportActionsListItemRenderer({ isOptimisticAction: reportAction.isOptimisticAction, delegateAccountID: reportAction.delegateAccountID, previousMessage: reportAction.previousMessage, - attachmentInfo: reportAction.attachmentInfo, + isAttachmentWithText: reportAction.isAttachmentWithText, childStateNum: reportAction.childStateNum, childStatusNum: reportAction.childStatusNum, childReportName: reportAction.childReportName, @@ -134,7 +134,7 @@ function ReportActionsListItemRenderer({ reportAction.isOptimisticAction, reportAction.delegateAccountID, reportAction.previousMessage, - reportAction.attachmentInfo, + reportAction.isAttachmentWithText, reportAction.childStateNum, reportAction.childStatusNum, reportAction.childReportName, diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index a28cac54717f..80ef5e9698fe 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -1,5 +1,4 @@ import type {Spread, ValueOf} from 'type-fest'; -import type {FileObject} from '@components/AttachmentModal'; import type {AvatarSource} from '@libs/UserUtils'; import type CONST from '@src/CONST'; import type ONYXKEYS from '@src/ONYXKEYS'; @@ -217,8 +216,11 @@ type ReportActionBase = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Whether the report action is the first one */ isFirstItem?: boolean; - /** Informations about attachments of report action */ - attachmentInfo?: FileObject; + /** Whether the report action is only an attachment */ + isAttachmentOnly?: boolean; + + /** Whether the report action is an attachment with text */ + isAttachmentWithText?: boolean; /** Receipt tied to report action */ receipt?: Receipt; @@ -235,9 +237,6 @@ type ReportActionBase = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Error associated with the report action */ error?: string; - /** Whether the report action is attachment */ - isAttachment?: boolean; - /** Recent receipt transaction IDs keyed by reportID */ childRecentReceiptTransactionIDs?: Record; From 6acba416ce592b456787289a785821783031843f Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 9 Jul 2024 12:15:08 +0700 Subject: [PATCH 2/9] fix ts error --- tests/utils/collections/reportActions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils/collections/reportActions.ts b/tests/utils/collections/reportActions.ts index 3a7bff05253b..9a05ba6ad992 100644 --- a/tests/utils/collections/reportActions.ts +++ b/tests/utils/collections/reportActions.ts @@ -72,7 +72,7 @@ export default function createRandomReportAction(index: number): ReportAction { pendingAction: rand(Object.values(CONST.RED_BRICK_ROAD_PENDING_ACTION)), delegateAccountID: index, errors: {}, - isAttachment: randBoolean(), + isAttachmentOnly: randBoolean(), }; } From d04995b8e0ddabb40426b77357aad742f64292d8 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 10 Jul 2024 10:39:30 +0700 Subject: [PATCH 3/9] Update src/libs/ReportActionsUtils.ts Co-authored-by: Vinh Hoang --- src/libs/ReportActionsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 19d8a5d74554..32e6ad7d00b9 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -982,7 +982,7 @@ function isReportActionAttachment(reportAction: OnyxInputOrEntry): const message = getReportActionMessage(reportAction); if (reportAction && ('isAttachmentOnly' in reportAction || 'isAttachmentWithText' in reportAction)) { - return reportAction?.isAttachmentOnly ?? !!reportAction?.isAttachmentWithText ?? false; + return reportAction?.isAttachmentOnly ?? reportAction?.isAttachmentWithText ?? false; } if (message) { From fe12c89662eebf84718bb980af32c5457c587f9c Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 10 Jul 2024 10:39:37 +0700 Subject: [PATCH 4/9] Update src/libs/ReportUtils.ts Co-authored-by: Vinh Hoang --- 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 89ee5cb794bd..13e822df73ec 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3725,7 +3725,7 @@ function buildOptimisticAddCommentReportAction( textForNewComment = `${Parser.htmlToText(commentText)}\n${CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML}`; } - const isAttachmentWithText = !text && file !== undefined; + const isAttachmentWithText = !!text && file !== undefined; const accountID = actorAccountID ?? currentUserAccountID; // Remove HTML from text when applying optimistic offline comment From 841df69347c182210add34b40062423b23dbd681 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 15 Jul 2024 10:40:28 +0700 Subject: [PATCH 5/9] fix ts error --- tests/utils/ReportTestUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils/ReportTestUtils.ts b/tests/utils/ReportTestUtils.ts index bd62aca882b2..deab909cd272 100644 --- a/tests/utils/ReportTestUtils.ts +++ b/tests/utils/ReportTestUtils.ts @@ -11,7 +11,7 @@ const getFakeReportAction = (index: number, actionName?: ReportActionName): Repo automatic: false, avatar: '', created: '2023-09-12 16:27:35.124', - isAttachment: true, + isAttachmentOnly: true, isFirstItem: false, lastModified: '2021-07-14T15:00:00Z', message: [ From ba2e21906d194001276f8d34cb89fbd7efb06fa5 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 15 Jul 2024 10:42:27 +0700 Subject: [PATCH 6/9] add missing field --- src/libs/ReportUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 4fab29e811da..5cfddfce599f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4435,6 +4435,7 @@ function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThrea automatic: false, avatar: getCurrentUserAvatar(), created: DateUtils.getDBTime(), + isAttachmentOnly: false, message: [ { // Currently we are composing the message from the originalMessage and message is only used in OldDot and not in the App From beb45517edeb8327d5d86195f6cc19b479bcf230 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 17 Jul 2024 14:26:35 +0700 Subject: [PATCH 7/9] Update src/libs/ReportUtils.ts Co-authored-by: Vinh Hoang --- 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 5cfddfce599f..b0b8d8660ce8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2762,7 +2762,7 @@ function canEditReportAction(reportAction: OnyxInputOrEntry): bool isCommentOrIOU && (!ReportActionsUtils.isMoneyRequestAction(reportAction) || canEditMoneyRequest(reportAction)) && // Returns true for non-IOU actions !isReportMessageAttachment(message) && - (!!reportAction.isAttachmentWithText || !reportAction.isOptimisticAction) && + (!reportAction.isAttachmentWithText || !reportAction.isOptimisticAction) && !ReportActionsUtils.isDeletedAction(reportAction) && !ReportActionsUtils.isCreatedTaskReportAction(reportAction) && reportAction?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE From 78f138568d82c43b7512418cc73da907b8aead82 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 22 Jul 2024 17:55:55 +0700 Subject: [PATCH 8/9] fix edit option appears in offline --- 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 04762a0e82a0..19ab48d658c4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2780,7 +2780,7 @@ function canEditReportAction(reportAction: OnyxInputOrEntry): bool isCommentOrIOU && (!ReportActionsUtils.isMoneyRequestAction(reportAction) || canEditMoneyRequest(reportAction)) && // Returns true for non-IOU actions !isReportMessageAttachment(message) && - (!reportAction.isAttachmentWithText || !reportAction.isOptimisticAction) && + ((!reportAction.isAttachmentWithText && !reportAction.isAttachmentOnly) || !reportAction.isOptimisticAction) && !ReportActionsUtils.isDeletedAction(reportAction) && !ReportActionsUtils.isCreatedTaskReportAction(reportAction) && reportAction?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE From 4c186610b909e2dfde21594c9c3cddfd64a1c00a Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:53:00 +0700 Subject: [PATCH 9/9] Update src/libs/ReportActionsUtils.ts Co-authored-by: Ionatan Wiznia --- src/libs/ReportActionsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 8ebdf5a703d6..eb206d0d0478 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1038,7 +1038,7 @@ function isReportActionAttachment(reportAction: OnyxInputOrEntry): const message = getReportActionMessage(reportAction); if (reportAction && ('isAttachmentOnly' in reportAction || 'isAttachmentWithText' in reportAction)) { - return reportAction?.isAttachmentOnly ?? reportAction?.isAttachmentWithText ?? false; + return reportAction.isAttachmentOnly ?? reportAction.isAttachmentWithText ?? false; } if (message) {