Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace attachmentInfo with isAttachmentWithText #45043

Merged
merged 12 commits into from
Jul 25, 2024
4 changes: 2 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,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;
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -102,8 +102,8 @@ type OptimisticAddCommentReportAction = Pick<
| 'created'
| 'message'
| 'isFirstItem'
| 'isAttachment'
| 'attachmentInfo'
| 'isAttachmentOnly'
| 'isAttachmentWithText'
| 'pendingAction'
| 'shouldShow'
| 'originalMessage'
Expand Down Expand Up @@ -158,7 +158,7 @@ type OptimisticIOUReportAction = Pick<
| 'actorAccountID'
| 'automatic'
| 'avatar'
| 'isAttachment'
| 'isAttachmentOnly'
| 'originalMessage'
| 'message'
| 'person'
Expand Down Expand Up @@ -186,12 +186,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 @@ -201,7 +201,7 @@ type OptimisticSubmittedReportAction = Pick<
| 'adminAccountID'
| 'automatic'
| 'avatar'
| 'isAttachment'
| 'isAttachmentOnly'
| 'originalMessage'
| 'message'
| 'person'
Expand All @@ -213,7 +213,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 @@ -290,7 +290,7 @@ type OptimisticTaskReportAction = Pick<
| 'automatic'
| 'avatar'
| 'created'
| 'isAttachment'
| 'isAttachmentOnly'
| 'message'
| 'originalMessage'
| 'person'
Expand Down Expand Up @@ -319,7 +319,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 @@ -2762,7 +2762,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.isOptimisticAction) &&
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
!ReportActionsUtils.isDeletedAction(reportAction) &&
!ReportActionsUtils.isCreatedTaskReportAction(reportAction) &&
reportAction?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE
Expand Down Expand Up @@ -3698,8 +3698,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 @@ -3732,8 +3731,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 @@ -4143,7 +4142,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 @@ -4175,7 +4174,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 @@ -4201,7 +4200,7 @@ function buildOptimisticUnapprovedReportAction(amount: number, currency: string,
actorAccountID: currentUserAccountID,
automatic: false,
avatar: getCurrentUserAvatar(),
isAttachment: false,
isAttachmentOnly: false,
originalMessage: {
amount,
currency,
Expand Down Expand Up @@ -4247,7 +4246,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 @@ -4281,7 +4280,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 @@ -4400,7 +4399,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 @@ -4436,7 +4435,7 @@ function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThrea
automatic: false,
avatar: getCurrentUserAvatar(),
created: DateUtils.getDBTime(),
isAttachment: false,
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -4539,7 +4538,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
Loading