Skip to content

Commit

Permalink
Create more specific ModifiedExpenseAction
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaaron committed May 8, 2024
1 parent a2ead7f commit 5ab6a0f
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ export {
getParentReportAction,
getReportAction,
getReportActionMessageText,
getWhisperedTo,
isApprovedOrSubmittedReportAction,
getReportPreviewAction,
getSortedReportActions,
Expand Down
11 changes: 6 additions & 5 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import type {OnyxData} from '@src/types/onyx/Request';
import type {Comment, Receipt, ReceiptSource, SplitShares, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type {ReportPreviewAction} from '@src/types/onyx/ReportAction';
import * as CachedPDFPaths from './CachedPDFPaths';
import * as Policy from './Policy';
import * as Report from './Report';
Expand Down Expand Up @@ -1875,7 +1876,7 @@ function getMoneyRequestInformation(
let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID);

if (reportPreviewAction) {
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction, false, comment, optimisticTransaction);
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, false, comment, optimisticTransaction);
} else {
reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction);

Expand Down Expand Up @@ -2099,7 +2100,7 @@ function getTrackExpenseInformation(
reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID);

if (reportPreviewAction) {
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction, false, comment, optimisticTransaction);
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, false, comment, optimisticTransaction);
} else {
reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction);
// Generated ReportPreview action is a parent report action of the iou report.
Expand Down Expand Up @@ -3955,7 +3956,7 @@ function createSplitsAndOnyxData(

let oneOnOneReportPreviewAction = getReportPreviewAction(oneOnOneChatReport.reportID, oneOnOneIOUReport.reportID);
if (oneOnOneReportPreviewAction) {
oneOnOneReportPreviewAction = ReportUtils.updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction);
oneOnOneReportPreviewAction = ReportUtils.updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction as ReportPreviewAction);
} else {
oneOnOneReportPreviewAction = ReportUtils.buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport);
}
Expand Down Expand Up @@ -4644,7 +4645,7 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA

let oneOnOneReportPreviewAction = getReportPreviewAction(oneOnOneChatReport?.reportID ?? '', oneOnOneIOUReport?.reportID ?? '');
if (oneOnOneReportPreviewAction) {
oneOnOneReportPreviewAction = ReportUtils.updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction);
oneOnOneReportPreviewAction = ReportUtils.updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction as ReportPreviewAction);
} else {
oneOnOneReportPreviewAction = ReportUtils.buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, '', oneOnOneTransaction);
}
Expand Down Expand Up @@ -5685,7 +5686,7 @@ function getPayMoneyRequestParams(
let optimisticReportPreviewAction = null;
const reportPreviewAction = getReportPreviewAction(chatReport.reportID, iouReport.reportID);
if (reportPreviewAction) {
optimisticReportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction, true);
optimisticReportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, true);
}

const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport.reportID}`] ?? null;
Expand Down
12 changes: 6 additions & 6 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,12 @@ function ReportActionItem({
}

const hasErrors = !isEmptyObject(action.errors);
const whisperedToAccountIDs = action.whisperedToAccountIDs ?? [];
const isWhisper = whisperedToAccountIDs.length > 0;
const isMultipleParticipant = whisperedToAccountIDs.length > 1;
const isWhisperOnlyVisibleByUser = isWhisper && ReportUtils.isCurrentUserTheOnlyParticipant(whisperedToAccountIDs);
const whisperedTo = ReportActionsUtils.getWhisperedTo(action);
const isWhisper = whisperedTo.length > 0;
const isMultipleParticipant = whisperedTo.length > 1;
const isWhisperOnlyVisibleByUser = isWhisper && ReportUtils.isCurrentUserTheOnlyParticipant(whisperedTo);
const whisperedToPersonalDetails = isWhisper
? (Object.values(personalDetails ?? {}).filter((details) => whisperedToAccountIDs.includes(details?.accountID ?? -1)) as OnyxTypes.PersonalDetails[])
? (Object.values(personalDetails ?? {}).filter((details) => whisperedTo.includes(details?.accountID ?? -1)) as OnyxTypes.PersonalDetails[])
: [];
const displayNamesWithTooltips = isWhisper ? ReportUtils.getDisplayNamesWithTooltips(whisperedToPersonalDetails, isMultipleParticipant) : [];

Expand Down Expand Up @@ -993,7 +993,7 @@ function ReportActionItem({
 
</Text>
<DisplayNames
fullTitle={ReportUtils.getWhisperDisplayNames(whisperedToAccountIDs) ?? ''}
fullTitle={ReportUtils.getWhisperDisplayNames(whisperedTo) ?? ''}
displayNamesWithTooltips={displayNamesWithTooltips}
tooltipEnabled
numberOfLines={1}
Expand Down
2 changes: 0 additions & 2 deletions src/pages/home/report/ReportActionsListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ function ReportActionsListItemRenderer({
linkMetadata: reportAction.linkMetadata,
childReportID: reportAction.childReportID,
childLastVisibleActionCreated: reportAction.childLastVisibleActionCreated,
whisperedToAccountIDs: reportAction.whisperedToAccountIDs,
error: reportAction.error,
created: reportAction.created,
actorAccountID: reportAction.actorAccountID,
Expand Down Expand Up @@ -121,7 +120,6 @@ function ReportActionsListItemRenderer({
reportAction.linkMetadata,
reportAction.childReportID,
reportAction.childLastVisibleActionCreated,
reportAction.whisperedToAccountIDs,
reportAction.error,
reportAction.created,
reportAction.actorAccountID,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/report/reportActionPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export default {
originalMessage: PropTypes.shape({
// The ID of the iou transaction
IOUTransactionID: PropTypes.string,

/** accountIDs of the people to which the whisper was sent to (if any). Returns empty array if it is not a whisper */
whisperedTo: PropTypes.arrayOf(PropTypes.number)
}),

/** Error message that's come back from the server. */
error: PropTypes.string,

/** accountIDs of the people to which the whisper was sent to (if any). Returns empty array if it is not a whisper */
whisperedToAccountIDs: PropTypes.arrayOf(PropTypes.number),
};
2 changes: 2 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ type OriginalMessageModifiedExpense = {
taxRate?: string;
oldBillable?: string;
billable?: string;
whisperedTo?: number[];
};
};

Expand Down Expand Up @@ -388,6 +389,7 @@ export type {
OriginalMessageActionableMentionWhisper,
OriginalMessageActionableReportMentionWhisper,
OriginalMessageReportPreview,
OriginalMessageModifiedExpense,
OriginalMessageChronosOOOList,
OriginalMessageRoomChangeLog,
OriginalMessageSource,
Expand Down
5 changes: 3 additions & 2 deletions src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type ONYXKEYS from '@src/ONYXKEYS';
import type CollectionDataSet from '@src/types/utils/CollectionDataSet';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import type * as OnyxCommon from './OnyxCommon';
import type {Decision, OriginalMessageReportPreview, Reaction} from './OriginalMessage';
import type {Decision, OriginalMessageReportPreview, Reaction, OriginalMessageModifiedExpense} from './OriginalMessage';
import type OriginalMessage from './OriginalMessage';
import type {NotificationPreference} from './Report';
import type {Receipt} from './Transaction';
Expand Down Expand Up @@ -230,10 +230,11 @@ type ReportActionBase = OnyxCommon.OnyxValueWithOfflineFeedback<{

type ReportAction = ReportActionBase & OriginalMessage;
type ReportPreviewAction = ReportActionBase & OriginalMessageReportPreview;
type ModifiedExpenseAction = ReportActionBase & OriginalMessageModifiedExpense;

type ReportActions = Record<string, ReportAction>;

type ReportActionsCollectionDataSet = CollectionDataSet<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>;

export default ReportAction;
export type {ReportActions, ReportActionBase, Message, LinkMetadata, OriginalMessage, ReportActionsCollectionDataSet, ReportPreviewAction};
export type {ReportActions, ReportActionBase, Message, LinkMetadata, OriginalMessage, ReportActionsCollectionDataSet, ReportPreviewAction, ModifiedExpenseAction};
7 changes: 5 additions & 2 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx';
import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet';
import type {ModifiedExpenseAction} from '@src/types/onyx/ReportAction';
import * as NumberUtils from '../../src/libs/NumberUtils';
import * as LHNTestUtils from '../utils/LHNTestUtils';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
Expand Down Expand Up @@ -769,8 +770,10 @@ describe('ReportUtils', () => {
it("should disable on a whisper action and it's neither a report preview nor IOU action", () => {
const reportAction = {
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE,
whisperedToAccountIDs: [123456],
} as ReportAction;
originalMessage: {
whisperedTo: [123456],
},
} as ModifiedExpenseAction;
expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/utils/LHNTestUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ function getFakeReportAction(actor = '[email protected]', millisecondsInThePast =
text: 'Email One',
},
],
whisperedToAccountIDs: [],
automatic: false,
message: [
{
Expand All @@ -182,6 +181,7 @@ function getFakeReportAction(actor = '[email protected]', millisecondsInThePast =
},
],
originalMessage: {
whisperedTo: [],
childReportID: `${reportActionID}`,
emojiReactions: {
heart: {
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 @@ -68,8 +68,8 @@ export default function createRandomReportAction(index: number): ReportAction {
originalMessage: {
html: randWord(),
lastModified: getRandomDate(),
whisperedTo: randAggregation(),
},
whisperedToAccountIDs: randAggregation(),
avatar: randWord(),
automatic: randBoolean(),
shouldShow: randBoolean(),
Expand Down

0 comments on commit 5ab6a0f

Please sign in to comment.