diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 73784873201a..eb206d0d0478 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1037,8 +1037,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 73132ceb853e..19ab48d658c4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -103,8 +103,8 @@ type OptimisticAddCommentReportAction = Pick< | 'created' | 'message' | 'isFirstItem' - | 'isAttachment' - | 'attachmentInfo' + | 'isAttachmentOnly' + | 'isAttachmentWithText' | 'pendingAction' | 'shouldShow' | 'originalMessage' @@ -160,7 +160,7 @@ type OptimisticIOUReportAction = Pick< | 'actorAccountID' | 'automatic' | 'avatar' - | 'isAttachment' + | 'isAttachmentOnly' | 'originalMessage' | 'message' | 'person' @@ -188,12 +188,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< @@ -203,7 +203,7 @@ type OptimisticSubmittedReportAction = Pick< | 'adminAccountID' | 'automatic' | 'avatar' - | 'isAttachment' + | 'isAttachmentOnly' | 'originalMessage' | 'message' | 'person' @@ -215,7 +215,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< @@ -293,7 +293,7 @@ type OptimisticTaskReportAction = Pick< | 'automatic' | 'avatar' | 'created' - | 'isAttachment' + | 'isAttachmentOnly' | 'message' | 'originalMessage' | 'person' @@ -322,7 +322,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< @@ -2780,7 +2780,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.isAttachmentOnly) || !reportAction.isOptimisticAction) && !ReportActionsUtils.isDeletedAction(reportAction) && !ReportActionsUtils.isCreatedTaskReportAction(reportAction) && reportAction?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE @@ -3734,8 +3734,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 @@ -3768,8 +3767,8 @@ function buildOptimisticAddCommentReportAction( whisperedTo: [], }, isFirstItem: false, - isAttachment, - attachmentInfo, + isAttachmentOnly, + isAttachmentWithText, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, shouldShow: true, isOptimisticAction: true, @@ -4177,7 +4176,7 @@ function buildOptimisticIOUReportAction( actorAccountID: currentUserAccountID, automatic: false, avatar: getCurrentUserAvatar(), - isAttachment: false, + isAttachmentOnly: false, originalMessage, message: getIOUReportActionMessage(iouReportID, type, amount, comment, currency, paymentType, isSettlingUp), person: [ @@ -4209,7 +4208,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: [ @@ -4235,7 +4234,7 @@ function buildOptimisticUnapprovedReportAction(amount: number, currency: string, actorAccountID: currentUserAccountID, automatic: false, avatar: getCurrentUserAvatar(), - isAttachment: false, + isAttachmentOnly: false, originalMessage: { amount, currency, @@ -4281,7 +4280,7 @@ function buildOptimisticMovedReportAction(fromPolicyID: string, toPolicyID: stri actorAccountID: currentUserAccountID, automatic: false, avatar: getCurrentUserAvatar(), - isAttachment: false, + isAttachmentOnly: false, originalMessage, message: movedActionMessage, person: [ @@ -4315,7 +4314,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: [ @@ -4432,7 +4431,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 @@ -4468,7 +4467,7 @@ function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThrea 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 @@ -4571,7 +4570,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; 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: [ 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(), }; }