Skip to content

Commit

Permalink
Merge pull request Expensify#45043 from nkdengineer/fix/44603
Browse files Browse the repository at this point in the history
fix: replace attachmentInfo with isAttachmentWithText
  • Loading branch information
iwiznia authored Jul 25, 2024
2 parents b1739fb + 4c18661 commit 904e950
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,8 @@ function getAllReportActions(reportID: string): ReportActions {
function isReportActionAttachment(reportAction: OnyxInputOrEntry<ReportAction>): 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) {
Expand Down
43 changes: 21 additions & 22 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ type OptimisticAddCommentReportAction = Pick<
| 'created'
| 'message'
| 'isFirstItem'
| 'isAttachment'
| 'attachmentInfo'
| 'isAttachmentOnly'
| 'isAttachmentWithText'
| 'pendingAction'
| 'shouldShow'
| 'originalMessage'
Expand Down Expand Up @@ -163,7 +163,7 @@ type OptimisticIOUReportAction = Pick<
| 'actorAccountID'
| 'automatic'
| 'avatar'
| 'isAttachment'
| 'isAttachmentOnly'
| 'originalMessage'
| 'message'
| 'person'
Expand Down Expand Up @@ -191,12 +191,12 @@ type ReportOfflinePendingActionAndErrors = {

type OptimisticApprovedReportAction = Pick<
ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.APPROVED>,
'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<typeof CONST.REPORT.ACTIONS.TYPE.UNAPPROVED>,
'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<
Expand All @@ -206,7 +206,7 @@ type OptimisticSubmittedReportAction = Pick<
| 'adminAccountID'
| 'automatic'
| 'avatar'
| 'isAttachment'
| 'isAttachmentOnly'
| 'originalMessage'
| 'message'
| 'person'
Expand All @@ -218,7 +218,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<
Expand Down Expand Up @@ -295,7 +295,7 @@ type OptimisticTaskReportAction = Pick<
| 'automatic'
| 'avatar'
| 'created'
| 'isAttachment'
| 'isAttachmentOnly'
| 'message'
| 'originalMessage'
| 'person'
Expand Down Expand Up @@ -324,7 +324,7 @@ type OptimisticWorkspaceChats = {

type OptimisticModifiedExpenseReportAction = Pick<
ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE>,
'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<
Expand Down Expand Up @@ -2815,7 +2815,7 @@ function canEditReportAction(reportAction: OnyxInputOrEntry<ReportAction>): 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
Expand Down Expand Up @@ -3778,8 +3778,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
Expand Down Expand Up @@ -3812,8 +3811,8 @@ function buildOptimisticAddCommentReportAction(
whisperedTo: [],
},
isFirstItem: false,
isAttachment,
attachmentInfo,
isAttachmentOnly,
isAttachmentWithText,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
shouldShow: true,
isOptimisticAction: true,
Expand Down Expand Up @@ -4221,7 +4220,7 @@ function buildOptimisticIOUReportAction(
actorAccountID: currentUserAccountID,
automatic: false,
avatar: getCurrentUserAvatar(),
isAttachment: false,
isAttachmentOnly: false,
originalMessage,
message: getIOUReportActionMessage(iouReportID, type, amount, comment, currency, paymentType, isSettlingUp),
person: [
Expand Down Expand Up @@ -4253,7 +4252,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: [
Expand All @@ -4279,7 +4278,7 @@ function buildOptimisticUnapprovedReportAction(amount: number, currency: string,
actorAccountID: currentUserAccountID,
automatic: false,
avatar: getCurrentUserAvatar(),
isAttachment: false,
isAttachmentOnly: false,
originalMessage: {
amount,
currency,
Expand Down Expand Up @@ -4325,7 +4324,7 @@ function buildOptimisticMovedReportAction(fromPolicyID: string, toPolicyID: stri
actorAccountID: currentUserAccountID,
automatic: false,
avatar: getCurrentUserAvatar(),
isAttachment: false,
isAttachmentOnly: false,
originalMessage,
message: movedActionMessage,
person: [
Expand Down Expand Up @@ -4359,7 +4358,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: [
Expand Down Expand Up @@ -4476,7 +4475,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
Expand Down Expand Up @@ -4512,7 +4511,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
Expand Down Expand Up @@ -4615,7 +4614,7 @@ function buildOptimisticTaskReportAction(
actorAccountID,
automatic: false,
avatar: getCurrentUserAvatar(),
isAttachment: false,
isAttachmentOnly: false,
originalMessage,
message: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionsListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -134,7 +134,7 @@ function ReportActionsListItemRenderer({
reportAction.isOptimisticAction,
reportAction.delegateAccountID,
reportAction.previousMessage,
reportAction.attachmentInfo,
reportAction.isAttachmentWithText,
reportAction.childStateNum,
reportAction.childStatusNum,
reportAction.childReportName,
Expand Down
11 changes: 5 additions & 6 deletions src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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<string, string>;

Expand Down
2 changes: 1 addition & 1 deletion tests/utils/ReportTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/collections/reportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}

Expand Down

0 comments on commit 904e950

Please sign in to comment.