Skip to content

Commit e331f34

Browse files
authored
Merge pull request #88568 from callstack-internal/perf-send-message-phase-8
[NoQA] refactor: PureReportActionItem, TripRoomPreview
2 parents 6ffff4a + dd1f647 commit e331f34

5 files changed

Lines changed: 30 additions & 72 deletions

File tree

src/components/ReportActionItem/TripRoomPreview.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Text from '@components/Text';
1212
import {useCurrencyListActions} from '@hooks/useCurrencyList';
1313
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
1414
import useLocalize from '@hooks/useLocalize';
15+
import useOnyx from '@hooks/useOnyx';
1516
import useStyleUtils from '@hooks/useStyleUtils';
1617
import useTheme from '@hooks/useTheme';
1718
import useThemeStyles from '@hooks/useThemeStyles';
@@ -20,11 +21,13 @@ import ControlSelection from '@libs/ControlSelection';
2021
import DateUtils from '@libs/DateUtils';
2122
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
2223
import Navigation from '@libs/Navigation/Navigation';
24+
import {getOriginalMessage} from '@libs/ReportActionsUtils';
2325
import type {ReservationData} from '@libs/TripReservationUtils';
2426
import {formatCancelledDescription, getReservationsFromTripReport, getTripReservationIcon, getTripTotal} from '@libs/TripReservationUtils';
2527
import type {ContextMenuAnchor} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu';
2628
import variables from '@styles/variables';
2729
import CONST from '@src/CONST';
30+
import ONYXKEYS from '@src/ONYXKEYS';
2831
import ROUTES from '@src/ROUTES';
2932
import type {Report, ReportAction} from '@src/types/onyx';
3033
import type {Reservation} from '@src/types/onyx/Transaction';
@@ -33,12 +36,6 @@ type TripRoomPreviewProps = {
3336
/** All the data of the action */
3437
action: ReportAction;
3538

36-
/** The associated chatReport */
37-
chatReport: OnyxEntry<Report>;
38-
39-
/** The associated iouReport */
40-
iouReport: OnyxEntry<Report>;
41-
4239
/** Extra styles to pass to View wrapper */
4340
containerStyles?: StyleProp<ViewStyle>;
4441

@@ -58,6 +55,8 @@ type TripRoomPreviewProps = {
5855
shouldDisplayContextMenu?: boolean;
5956
};
6057

58+
const selectCurrency = (report: OnyxEntry<Report>) => report?.currency;
59+
6160
type ReservationViewProps = {
6261
reservation: Reservation;
6362
onPress?: () => void;
@@ -129,8 +128,6 @@ function ReservationView({reservation, onPress, isCancelled}: ReservationViewPro
129128

130129
function TripRoomPreview({
131130
action,
132-
chatReport,
133-
iouReport,
134131
containerStyles,
135132
contextMenuAnchor,
136133
isHovered = false,
@@ -141,6 +138,12 @@ function TripRoomPreview({
141138
const styles = useThemeStyles();
142139
const {translate} = useLocalize();
143140
const {convertToDisplayString} = useCurrencyListActions();
141+
142+
const originalMessage = getOriginalMessage(action);
143+
const linkedReportID = originalMessage && 'linkedReportID' in originalMessage ? originalMessage.linkedReportID : undefined;
144+
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${linkedReportID}`);
145+
const [iouReportCurrency] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.iouReportID}`, {selector: selectCurrency});
146+
144147
const chatReportID = chatReport?.reportID;
145148
const tripTransactions = useTripTransactions(chatReportID);
146149

@@ -149,7 +152,7 @@ function TripRoomPreview({
149152
chatReport?.tripData?.startDate && chatReport?.tripData?.endDate
150153
? DateUtils.getFormattedDateRange(translate, new Date(chatReport.tripData.startDate), new Date(chatReport.tripData.endDate))
151154
: '';
152-
const reportCurrency = iouReport?.currency ?? chatReport?.currency;
155+
const reportCurrency = iouReportCurrency ?? chatReport?.currency;
153156

154157
const {totalDisplaySpend = 0, currency = reportCurrency} = chatReport ? getTripTotal(chatReport) : {};
155158

src/pages/inbox/report/PureReportActionItem.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,6 @@ type PureReportActionItemProps = {
222222
/** The task report associated with this action, if any */
223223
taskReport: OnyxEntry<OnyxTypes.Report>;
224224

225-
/** The linked report associated with this action, if any */
226-
linkedReport: OnyxEntry<OnyxTypes.Report>;
227-
228-
/** The iou report associated with the linked report, if any */
229-
iouReportOfLinkedReport: OnyxEntry<OnyxTypes.Report>;
230-
231225
/** Linked transaction route error */
232226
linkedTransactionRouteError?: Errors;
233227

@@ -347,8 +341,6 @@ function PureReportActionItem({
347341
draftMessage,
348342
iouReport,
349343
taskReport,
350-
linkedReport,
351-
iouReportOfLinkedReport,
352344
linkedTransactionRouteError,
353345
isUserValidated,
354346
parentReport,
@@ -729,8 +721,6 @@ function PureReportActionItem({
729721
children = (
730722
<TripRoomPreview
731723
action={action}
732-
chatReport={linkedReport}
733-
iouReport={iouReportOfLinkedReport}
734724
isHovered={hovered}
735725
contextMenuAnchor={popoverAnchorRef.current}
736726
containerStyles={displayAsGroup ? [] : [styles.mt2]}

src/pages/inbox/report/ReportActionItem.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type {PersonalDetailsList, Transaction} from '@src/types/onyx';
2323
import type {PureReportActionItemProps} from './PureReportActionItem';
2424
import PureReportActionItem from './PureReportActionItem';
2525

26-
type ReportActionItemProps = Omit<PureReportActionItemProps, 'taskReport' | 'linkedReport' | 'iouReportOfLinkedReport' | 'personalPolicyID'> & {
26+
type ReportActionItemProps = Omit<PureReportActionItemProps, 'taskReport' | 'personalPolicyID'> & {
2727
/** Whether to show the draft message or not */
2828
shouldShowDraftMessage?: boolean;
2929

@@ -69,10 +69,6 @@ function ReportActionItem({
6969

7070
const taskReportID = originalMessage && 'taskReportID' in originalMessage ? originalMessage.taskReportID : undefined;
7171
const [taskReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`);
72-
const linkedReportID = originalMessage && 'linkedReportID' in originalMessage ? originalMessage.linkedReportID : undefined;
73-
const [linkedReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${linkedReportID}`);
74-
const iouReportOfLinkedReportID = linkedReport && 'iouReportID' in linkedReport ? linkedReport.iouReportID : undefined;
75-
const [iouReportOfLinkedReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${iouReportOfLinkedReportID}`);
7672

7773
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`);
7874
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
@@ -103,8 +99,6 @@ function ReportActionItem({
10399
draftMessage={draftMessage}
104100
iouReport={iouReport}
105101
taskReport={taskReport}
106-
linkedReport={linkedReport}
107-
iouReportOfLinkedReport={iouReportOfLinkedReport}
108102
linkedTransactionRouteError={linkedTransactionRouteError}
109103
isUserValidated={isUserValidated}
110104
parentReport={parentReport}

tests/ui/ClearReportActionErrorsUITest.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ describe('ClearReportActionErrors UI', () => {
102102
index={0}
103103
isFirstVisibleReportAction={false}
104104
taskReport={undefined}
105-
linkedReport={undefined}
106-
iouReportOfLinkedReport={undefined}
107105
clearAllRelatedReportActionErrors={clearErrorFn}
108106
originalReportID={originalReportID}
109107
/>

tests/ui/PureReportActionItemTest.tsx

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ describe('PureReportActionItem', () => {
110110
index={0}
111111
isFirstVisibleReportAction={false}
112112
taskReport={undefined}
113-
linkedReport={undefined}
114-
iouReportOfLinkedReport={undefined}
115113
/>
116114
</PortalProvider>
117115
</ScreenWrapper>
@@ -400,8 +398,6 @@ describe('PureReportActionItem', () => {
400398
index={0}
401399
isFirstVisibleReportAction={false}
402400
taskReport={undefined}
403-
linkedReport={undefined}
404-
iouReportOfLinkedReport={undefined}
405401
reportMetadata={reportMetadata}
406402
/>
407403
</PortalProvider>
@@ -454,8 +450,6 @@ describe('PureReportActionItem', () => {
454450
index={0}
455451
isFirstVisibleReportAction={false}
456452
taskReport={undefined}
457-
linkedReport={undefined}
458-
iouReportOfLinkedReport={undefined}
459453
/>
460454
</PortalProvider>
461455
</ScreenWrapper>
@@ -510,8 +504,6 @@ describe('PureReportActionItem', () => {
510504
index={0}
511505
isFirstVisibleReportAction={false}
512506
taskReport={undefined}
513-
linkedReport={undefined}
514-
iouReportOfLinkedReport={undefined}
515507
reportMetadata={reportMetadata}
516508
/>
517509
</PortalProvider>
@@ -560,8 +552,6 @@ describe('PureReportActionItem', () => {
560552
index={0}
561553
isFirstVisibleReportAction={false}
562554
taskReport={undefined}
563-
linkedReport={undefined}
564-
iouReportOfLinkedReport={undefined}
565555
/>
566556
</PortalProvider>
567557
</ScreenWrapper>
@@ -633,8 +623,6 @@ describe('PureReportActionItem', () => {
633623
index={0}
634624
isFirstVisibleReportAction={false}
635625
taskReport={undefined}
636-
linkedReport={undefined}
637-
iouReportOfLinkedReport={undefined}
638626
/>
639627
</PortalProvider>
640628
</ScreenWrapper>
@@ -693,8 +681,6 @@ describe('PureReportActionItem', () => {
693681
index={0}
694682
isFirstVisibleReportAction={false}
695683
taskReport={undefined}
696-
linkedReport={undefined}
697-
iouReportOfLinkedReport={undefined}
698684
/>
699685
</PortalProvider>
700686
</ScreenWrapper>
@@ -780,8 +766,6 @@ describe('PureReportActionItem', () => {
780766
index={0}
781767
isFirstVisibleReportAction={false}
782768
taskReport={undefined}
783-
linkedReport={undefined}
784-
iouReportOfLinkedReport={undefined}
785769
/>
786770
</PortalProvider>
787771
</ScreenWrapper>
@@ -1094,8 +1078,6 @@ describe('PureReportActionItem', () => {
10941078
index={0}
10951079
isFirstVisibleReportAction={false}
10961080
taskReport={undefined}
1097-
linkedReport={undefined}
1098-
iouReportOfLinkedReport={undefined}
10991081
/>
11001082
</PortalProvider>
11011083
</ScreenWrapper>
@@ -1277,8 +1259,6 @@ describe('PureReportActionItem', () => {
12771259
index={0}
12781260
isFirstVisibleReportAction={false}
12791261
taskReport={undefined}
1280-
linkedReport={undefined}
1281-
iouReportOfLinkedReport={undefined}
12821262
/>
12831263
</PortalProvider>
12841264
</ScreenWrapper>
@@ -1372,8 +1352,6 @@ describe('PureReportActionItem', () => {
13721352
index={0}
13731353
isFirstVisibleReportAction={false}
13741354
taskReport={undefined}
1375-
linkedReport={undefined}
1376-
iouReportOfLinkedReport={undefined}
13771355
isClosedExpenseReportWithNoExpenses
13781356
/>
13791357
</PortalProvider>
@@ -1403,8 +1381,6 @@ describe('PureReportActionItem', () => {
14031381
index={0}
14041382
isFirstVisibleReportAction={false}
14051383
taskReport={undefined}
1406-
linkedReport={undefined}
1407-
iouReportOfLinkedReport={undefined}
14081384
missingPaymentMethod="bankAccount"
14091385
/>
14101386
</PortalProvider>
@@ -1436,8 +1412,6 @@ describe('PureReportActionItem', () => {
14361412
index={0}
14371413
isFirstVisibleReportAction={false}
14381414
taskReport={undefined}
1439-
linkedReport={undefined}
1440-
iouReportOfLinkedReport={undefined}
14411415
missingPaymentMethod="wallet"
14421416
/>
14431417
</PortalProvider>
@@ -1472,8 +1446,6 @@ describe('PureReportActionItem', () => {
14721446
index={0}
14731447
isFirstVisibleReportAction={false}
14741448
taskReport={undefined}
1475-
linkedReport={undefined}
1476-
iouReportOfLinkedReport={undefined}
14771449
// eslint-disable-next-line @typescript-eslint/naming-convention
14781450
bankAccountList={{12345: {accountData: {accountNumber: '000098765'}} as never}}
14791451
/>
@@ -1509,8 +1481,6 @@ describe('PureReportActionItem', () => {
15091481
index={0}
15101482
isFirstVisibleReportAction={false}
15111483
taskReport={undefined}
1512-
linkedReport={undefined}
1513-
iouReportOfLinkedReport={undefined}
15141484
// eslint-disable-next-line @typescript-eslint/naming-convention
15151485
bankAccountList={{12345: {accountData: {accountNumber: '000098765'}} as never}}
15161486
/>
@@ -1549,8 +1519,6 @@ describe('PureReportActionItem', () => {
15491519
index={0}
15501520
isFirstVisibleReportAction={false}
15511521
taskReport={undefined}
1552-
linkedReport={undefined}
1553-
iouReportOfLinkedReport={undefined}
15541522
// eslint-disable-next-line @typescript-eslint/naming-convention
15551523
bankAccountList={{55555: {accountData: {accountNumber: '000012345'}} as never}}
15561524
/>
@@ -1590,8 +1558,6 @@ describe('PureReportActionItem', () => {
15901558
index={0}
15911559
isFirstVisibleReportAction={false}
15921560
taskReport={undefined}
1593-
linkedReport={undefined}
1594-
iouReportOfLinkedReport={undefined}
15951561
// eslint-disable-next-line @typescript-eslint/naming-convention
15961562
bankAccountList={{77777: {accountData: {accountNumber: '000067890'}} as never}}
15971563
/>
@@ -1682,8 +1648,6 @@ describe('PureReportActionItem', () => {
16821648
index={0}
16831649
isFirstVisibleReportAction={false}
16841650
taskReport={undefined}
1685-
linkedReport={undefined}
1686-
iouReportOfLinkedReport={undefined}
16871651
/>
16881652
</PortalProvider>
16891653
</ScreenWrapper>
@@ -1723,8 +1687,6 @@ describe('PureReportActionItem', () => {
17231687
index={0}
17241688
isFirstVisibleReportAction={false}
17251689
taskReport={undefined}
1726-
linkedReport={undefined}
1727-
iouReportOfLinkedReport={undefined}
17281690
/>
17291691
</PortalProvider>
17301692
</ScreenWrapper>
@@ -2306,8 +2268,6 @@ describe('PureReportActionItem', () => {
23062268
index={0}
23072269
isFirstVisibleReportAction={false}
23082270
taskReport={undefined}
2309-
linkedReport={undefined}
2310-
iouReportOfLinkedReport={undefined}
23112271
/>
23122272
</PortalProvider>
23132273
</ScreenWrapper>
@@ -2327,6 +2287,23 @@ describe('PureReportActionItem', () => {
23272287
expect(screen.getByLabelText(translateLocal('iou.viewDetails'))).toBeOnTheScreen();
23282288
});
23292289

2290+
it('isTripPreview renders TripRoomPreview with live reportName from Onyx', async () => {
2291+
await act(async () => {
2292+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}tripReportLive`, {
2293+
reportID: 'tripReportLive',
2294+
reportName: 'Paris Trip 2026',
2295+
currency: 'USD',
2296+
});
2297+
});
2298+
await waitForBatchedUpdatesWithAct();
2299+
2300+
const action = createReportAction(CONST.REPORT.ACTIONS.TYPE.TRIP_PREVIEW, {linkedReportID: 'tripReportLive'});
2301+
renderItemWithAction(action);
2302+
await waitForBatchedUpdatesWithAct();
2303+
2304+
expect(screen.getByText('Paris Trip 2026')).toBeOnTheScreen();
2305+
});
2306+
23302307
it('isCreatedTaskReportAction renders TaskPreview', async () => {
23312308
const action = createReportAction(CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, {taskReportID: 'task123'});
23322309
renderItemWithAction(action);
@@ -2360,8 +2337,6 @@ describe('PureReportActionItem', () => {
23602337
index={0}
23612338
isFirstVisibleReportAction={false}
23622339
taskReport={undefined}
2363-
linkedReport={undefined}
2364-
iouReportOfLinkedReport={undefined}
23652340
reportNameValuePairsOrigin="harvest"
23662341
reportNameValuePairsOriginalID="origReport123"
23672342
/>
@@ -2413,8 +2388,6 @@ describe('PureReportActionItem', () => {
24132388
isFirstVisibleReportAction={false}
24142389
isThreadReportParentAction
24152390
taskReport={undefined}
2416-
linkedReport={undefined}
2417-
iouReportOfLinkedReport={undefined}
24182391
/>
24192392
</PortalProvider>
24202393
</ScreenWrapper>

0 commit comments

Comments
 (0)