Skip to content

Commit 05d256a

Browse files
committed
clean up, reuse const and isHarvestCreatedExpenseReport
1 parent 066fe9b commit 05d256a

8 files changed

Lines changed: 139 additions & 158 deletions

File tree

src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,7 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
578578
personalDetails={personalDetails}
579579
originalReportID={originalReportID}
580580
isReportArchived={isReportArchived}
581-
reportNameValuePairsOrigin={reportNameValuePairs?.origin}
582-
reportNameValuePairsOriginalID={reportNameValuePairs?.originalID}
581+
isHarvestCreatedExpenseReport={shouldShowHarvestCreatedAction}
583582
/>
584583
);
585584
},
@@ -595,8 +594,7 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
595594
linkedReportActionID,
596595
personalDetails,
597596
isReportArchived,
598-
reportNameValuePairs?.origin,
599-
reportNameValuePairs?.originalID,
597+
shouldShowHarvestCreatedAction,
600598
],
601599
);
602600

src/components/ReportActionItem/CreateHarvestReportAction.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import ReportActionItemBasicMessage from '@pages/inbox/report/ReportActionItemBa
88
import ONYXKEYS from '@src/ONYXKEYS';
99

1010
type CreateHarvestReportActionProps = {
11-
/** The original ID of the report */
12-
reportNameValuePairsOriginalID: string | undefined;
11+
/** ID of the chat report the harvest "Created" action belongs to */
12+
reportID: string | undefined;
1313
};
1414

15-
function CreateHarvestReportAction({reportNameValuePairsOriginalID}: CreateHarvestReportActionProps) {
15+
function CreateHarvestReportAction({reportID}: CreateHarvestReportActionProps) {
1616
const {translate} = useLocalize();
17-
const [harvestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportNameValuePairsOriginalID}`);
17+
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`);
18+
const [harvestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportNameValuePairs?.originalID}`);
1819
const harvestReportName = getReportName(harvestReport);
1920
const htmlContent = `<comment><muted-text>${getHarvestCreatedExpenseReportMessage(harvestReport?.reportID, harvestReportName, translate)}</muted-text></comment>`;
2021

src/pages/inbox/report/PureReportActionItem.tsx

Lines changed: 108 additions & 117 deletions
Large diffs are not rendered by default.

src/pages/inbox/report/ReportActionsList.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
isArchivedNonExpenseReport,
5555
isCanceledTaskReport,
5656
isExpenseReport,
57+
isHarvestCreatedExpenseReport,
5758
isInvoiceReport,
5859
isIOUReport,
5960
isMoneyRequestReport,
@@ -215,6 +216,7 @@ function ReportActionsList({
215216
const [reportLoadingState] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${report.reportID}`);
216217
const prevIsLoadingInitialReportActions = usePrevious(reportLoadingState?.isLoadingInitialReportActions);
217218
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`);
219+
const isHarvestCreatedExpenseReportAction = isHarvestCreatedExpenseReport(reportNameValuePairs?.origin, reportNameValuePairs?.originalID);
218220

219221
const backTo = route?.params?.backTo as string;
220222
const linkedReportActionID = route?.params?.reportActionID;
@@ -797,8 +799,7 @@ function ReportActionsList({
797799
personalDetails={personalDetailsList}
798800
originalReportID={originalReportID}
799801
isReportArchived={isReportArchived}
800-
reportNameValuePairsOrigin={reportNameValuePairs?.origin}
801-
reportNameValuePairsOriginalID={reportNameValuePairs?.originalID}
802+
isHarvestCreatedExpenseReport={isHarvestCreatedExpenseReportAction}
802803
/>
803804
<ShowPreviousMessagesButton
804805
reportID={report.reportID}
@@ -825,8 +826,7 @@ function ReportActionsList({
825826
shouldUseThreadDividerLine,
826827
personalDetailsList,
827828
isReportArchived,
828-
reportNameValuePairs?.origin,
829-
reportNameValuePairs?.originalID,
829+
isHarvestCreatedExpenseReportAction,
830830
reportActionsFromOnyx,
831831
showHiddenHistory,
832832
hasPreviousMessages,

src/pages/inbox/report/ReportActionsListItemRenderer.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,8 @@ type ReportActionsListItemRendererProps = {
6161
/** Whether the report is archived */
6262
isReportArchived: boolean;
6363

64-
/** Report name value pairs origin */
65-
reportNameValuePairsOrigin?: string;
66-
67-
/** Report name value pairs originalID */
68-
reportNameValuePairsOriginalID?: string;
64+
/** Whether the action is the "Created" action of a harvest-created expense report */
65+
isHarvestCreatedExpenseReport?: boolean;
6966
};
7067

7168
function ReportActionsListItemRenderer({
@@ -86,8 +83,7 @@ function ReportActionsListItemRenderer({
8683
originalReportID,
8784
personalDetails,
8885
isReportArchived = false,
89-
reportNameValuePairsOrigin,
90-
reportNameValuePairsOriginalID,
86+
isHarvestCreatedExpenseReport = false,
9187
}: ReportActionsListItemRendererProps) {
9288
const originalMessage = useMemo(() => getOriginalMessage(reportAction), [reportAction]);
9389

@@ -203,8 +199,7 @@ function ReportActionsListItemRenderer({
203199
shouldHighlight={shouldHighlight}
204200
personalDetails={personalDetails}
205201
draftMessage={draftMessage}
206-
reportNameValuePairsOrigin={reportNameValuePairsOrigin}
207-
reportNameValuePairsOriginalID={reportNameValuePairsOriginalID}
202+
isHarvestCreatedExpenseReport={isHarvestCreatedExpenseReport}
208203
/>
209204
);
210205
}

src/pages/inbox/report/actionContents/ActionContentRouter.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ type ActionContentRouterProps = {
112112
/** Whether the report action is the "Created" action of a harvest-created expense report */
113113
isHarvestCreatedExpenseReport: boolean;
114114

115-
/** The originalID component of report name value pairs (used by the Created action of harvest reports) */
116-
reportNameValuePairsOriginalID?: string;
117-
118115
/** Whether to show border for MoneyRequestReportPreviewContent */
119116
shouldShowBorder?: boolean;
120117

@@ -145,7 +142,6 @@ function ActionContentRouter({
145142
isReportArchived,
146143
isClosedExpenseReportWithNoExpenses,
147144
isHarvestCreatedExpenseReport,
148-
reportNameValuePairsOriginalID,
149145
shouldShowBorder,
150146
isOnSearch,
151147
index,
@@ -156,6 +152,7 @@ function ActionContentRouter({
156152

157153
const actionReport = originalReport ?? report;
158154
const actionReportID = originalReportID ?? reportID;
155+
const policyID = report?.policyID;
159156

160157
if (isIOURequestReportAction(action)) {
161158
const moneyRequestOriginalMessage = isMoneyRequestAction(action) ? getOriginalMessage(action) : undefined;
@@ -211,7 +208,7 @@ function ActionContentRouter({
211208
return (
212209
<MoneyRequestReportPreview
213210
iouReportID={getIOUReportIDFromReportActionPreview(action)}
214-
policyID={report?.policyID}
211+
policyID={policyID}
215212
chatReportID={reportID}
216213
action={action}
217214
isHovered={hovered}
@@ -232,7 +229,7 @@ function ActionContentRouter({
232229
chatReportID={reportID}
233230
action={action}
234231
isHovered={hovered}
235-
policyID={report?.policyID}
232+
policyID={policyID}
236233
/>
237234
);
238235
}
@@ -257,7 +254,7 @@ function ActionContentRouter({
257254
return (
258255
<ModifiedExpenseContent
259256
action={action}
260-
report={report}
257+
policyID={policyID}
261258
originalReport={originalReport}
262259
/>
263260
);
@@ -266,7 +263,7 @@ function ActionContentRouter({
266263
return (
267264
<ApprovalFlowContent
268265
action={action}
269-
policyID={report?.policyID}
266+
policyID={policyID}
270267
reportID={reportID}
271268
originalReport={originalReport}
272269
/>
@@ -276,7 +273,7 @@ function ActionContentRouter({
276273
return (
277274
<PaymentContent
278275
action={action}
279-
policyID={report?.policyID}
276+
policyID={policyID}
280277
/>
281278
);
282279
}
@@ -311,7 +308,7 @@ function ActionContentRouter({
311308
return (
312309
<PolicyChangeLogContent
313310
action={action}
314-
policyID={report?.policyID}
311+
policyID={policyID}
315312
/>
316313
);
317314
}
@@ -365,7 +362,7 @@ function ActionContentRouter({
365362
<JoinRequestContent
366363
action={action}
367364
actionReportID={actionReportID}
368-
policyID={report?.policyID}
365+
policyID={policyID}
369366
/>
370367
);
371368
}
@@ -406,7 +403,7 @@ function ActionContentRouter({
406403
return (
407404
<IssueCardMessage
408405
action={action}
409-
policyID={report?.policyID}
406+
policyID={policyID}
410407
/>
411408
);
412409
}
@@ -428,7 +425,7 @@ function ActionContentRouter({
428425
return (
429426
<IntegrationSyncFailedMessage
430427
action={action}
431-
policyID={report?.policyID}
428+
policyID={policyID}
432429
/>
433430
);
434431
}
@@ -447,7 +444,7 @@ function ActionContentRouter({
447444
);
448445
}
449446
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.CREATED) && isHarvestCreatedExpenseReport) {
450-
return <CreateHarvestReportAction reportNameValuePairsOriginalID={reportNameValuePairsOriginalID} />;
447+
return <CreateHarvestReportAction reportID={reportID} />;
451448
}
452449
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.CREATED_REPORT_FOR_UNAPPROVED_TRANSACTIONS)) {
453450
return <CreatedReportForUnapprovedTransactionsAction action={action} />;

src/pages/inbox/report/actionContents/ModifiedExpenseContent.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ import type {Report, ReportAction} from '@src/types/onyx';
1313

1414
type ModifiedExpenseContentProps = {
1515
action: ReportAction;
16-
report: OnyxEntry<Report>;
16+
policyID: string | undefined;
1717
originalReport: OnyxEntry<Report>;
1818
};
1919

20-
function ModifiedExpenseContent({action, report, originalReport}: ModifiedExpenseContentProps) {
20+
function ModifiedExpenseContent({action, policyID, originalReport}: ModifiedExpenseContentProps) {
2121
const {translate} = useLocalize();
2222
const {email: currentUserEmail} = useCurrentUserPersonalDetails();
2323
const {policyForMovingExpensesID} = usePolicyForMovingExpenses();
24-
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`);
24+
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
2525
const [childReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(action.childReportID)}`);
2626

2727
// When expense is moved from self-DM to workspace, policyID is temporarily OWNER_EMAIL_FAKE.
2828
// Fall back to policyForMovingExpensesID (actual destination workspace) for correct tag list.
29-
const policyIDForTags = report?.policyID === CONST.POLICY.OWNER_EMAIL_FAKE && policyForMovingExpensesID ? policyForMovingExpensesID : report?.policyID;
29+
const policyIDForTags = policyID === CONST.POLICY.OWNER_EMAIL_FAKE && policyForMovingExpensesID ? policyForMovingExpensesID : policyID;
3030
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyIDForTags}`);
3131
const [movedFromReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(action, CONST.REPORT.MOVE_TYPE.FROM)}`);
3232
const [movedToReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(action, CONST.REPORT.MOVE_TYPE.TO)}`);

tests/ui/PureReportActionItemTest.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,8 +2579,7 @@ describe('PureReportActionItem', () => {
25792579
shouldDisplayNewMarker={false}
25802580
index={0}
25812581
isFirstVisibleReportAction={false}
2582-
reportNameValuePairsOrigin="harvest"
2583-
reportNameValuePairsOriginalID="origReport123"
2582+
isHarvestCreatedExpenseReport
25842583
/>
25852584
</PortalProvider>
25862585
</ScreenWrapper>

0 commit comments

Comments
 (0)