-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ReportActionsView.tsx
executable file
·591 lines (515 loc) · 28 KB
/
ReportActionsView.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
import type {RouteProp} from '@react-navigation/native';
import {useIsFocused, useRoute} from '@react-navigation/native';
import lodashIsEqual from 'lodash/isEqual';
import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
import {InteractionManager} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import useCopySelectionHelper from '@hooks/useCopySelectionHelper';
import useInitialValue from '@hooks/useInitialValue';
import useNetwork from '@hooks/useNetwork';
import usePrevious from '@hooks/usePrevious';
import useWindowDimensions from '@hooks/useWindowDimensions';
import DateUtils from '@libs/DateUtils';
import getIsReportFullyVisible from '@libs/getIsReportFullyVisible';
import type {CentralPaneNavigatorParamList} from '@libs/Navigation/types';
import * as NumberUtils from '@libs/NumberUtils';
import {generateNewRandomInt} from '@libs/NumberUtils';
import Performance from '@libs/Performance';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import {isUserCreatedPolicyRoom} from '@libs/ReportUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {didUserLogInDuringSession} from '@libs/SessionUtils';
import shouldFetchReport from '@libs/shouldFetchReport';
import {ReactionListContext} from '@pages/home/ReportScreenContext';
import * as Report from '@userActions/Report';
import Timing from '@userActions/Timing';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import getInitialPaginationSize from './getInitialPaginationSize';
import PopoverReactionList from './ReactionList/PopoverReactionList';
import ReportActionsList from './ReportActionsList';
type ReportActionsViewOnyxProps = {
/** Session info for the currently logged in user. */
session: OnyxEntry<OnyxTypes.Session>;
/** Array of report actions for the transaction thread report associated with the current report */
transactionThreadReportActions: OnyxTypes.ReportAction[];
/** The transaction thread report associated with the current report, if any */
transactionThreadReport: OnyxEntry<OnyxTypes.Report>;
};
type ReportActionsViewProps = ReportActionsViewOnyxProps & {
/** The report currently being looked at */
report: OnyxTypes.Report;
/** Array of report actions for this report */
reportActions?: OnyxTypes.ReportAction[];
/** The report's parentReportAction */
parentReportAction: OnyxEntry<OnyxTypes.ReportAction>;
/** The report metadata loading states */
isLoadingInitialReportActions?: boolean;
/** The report actions are loading more data */
isLoadingOlderReportActions?: boolean;
/** The report actions are loading newer data */
isLoadingNewerReportActions?: boolean;
/** Whether the report is ready for comment linking */
isReadyForCommentLinking?: boolean;
/** The reportID of the transaction thread report associated with this current report, if any */
// eslint-disable-next-line react/no-unused-prop-types
transactionThreadReportID?: string | null;
};
const DIFF_BETWEEN_SCREEN_HEIGHT_AND_LIST = 120;
const SPACER = 16;
let listOldID = Math.round(Math.random() * 100);
function ReportActionsView({
report,
transactionThreadReport,
session,
parentReportAction,
reportActions: allReportActions = [],
transactionThreadReportActions = [],
isLoadingInitialReportActions = false,
isLoadingOlderReportActions = false,
isLoadingNewerReportActions = false,
isReadyForCommentLinking = false,
}: ReportActionsViewProps) {
useCopySelectionHelper();
const reactionListRef = useContext(ReactionListContext);
const route = useRoute<RouteProp<CentralPaneNavigatorParamList, typeof SCREENS.REPORT>>();
const reportActionID = route?.params?.reportActionID;
const didLayout = useRef(false);
const didSubscribeToReportTypingEvents = useRef(false);
// triggerListID is used when navigating to a chat with messages loaded from LHN. Typically, these include thread actions, task actions, etc. Since these messages aren't the latest,we don't maintain their position and instead trigger a recalculation of their positioning in the list.
// we don't set currentReportActionID on initial render as linkedID as it should trigger visibleReportActions after linked message was positioned
const [currentReportActionID, setCurrentReportActionID] = useState('');
const isFirstLinkedActionRender = useRef(true);
const network = useNetwork();
const {isSmallScreenWidth, windowHeight} = useWindowDimensions();
const contentListHeight = useRef(0);
const isFocused = useIsFocused();
const prevAuthTokenType = usePrevious(session?.authTokenType);
const [isNavigatingToLinkedMessage, setNavigatingToLinkedMessage] = useState(!!reportActionID);
const prevIsSmallScreenWidthRef = useRef(isSmallScreenWidth);
const reportID = report.reportID;
const isLoading = (!!reportActionID && isLoadingInitialReportActions) || !isReadyForCommentLinking;
const isReportFullyVisible = useMemo((): boolean => getIsReportFullyVisible(isFocused), [isFocused]);
const openReportIfNecessary = () => {
if (!shouldFetchReport(report)) {
return;
}
Report.openReport(reportID, reportActionID);
};
useLayoutEffect(() => {
setCurrentReportActionID('');
}, [route]);
// Change the list ID only for comment linking to get the positioning right
const listID = useMemo(() => {
if (!reportActionID) {
// Keep the old list ID since we're not in the Comment Linking flow
return listOldID;
}
isFirstLinkedActionRender.current = true;
const newID = generateNewRandomInt(listOldID, 1, Number.MAX_SAFE_INTEGER);
listOldID = newID;
return newID;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [route, isLoadingInitialReportActions, reportActionID]);
// Get a sorted array of reportActions for both the current report and the transaction thread report associated with this report (if there is one)
// so that we display transaction-level and report-level report actions in order in the one-transaction view
const combinedReportActions = useMemo(() => {
if (isEmptyObject(transactionThreadReportActions)) {
return allReportActions;
}
// Filter out the created action from the transaction thread report actions, since we already have the parent report's created action in `reportActions`
const filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED);
// Filter out the money request actions because we don't want to show any preview actions for one-transaction reports
const filteredReportActions = [...allReportActions, ...filteredTransactionThreadReportActions].filter((action) => {
const actionType = (action as OnyxTypes.OriginalMessageIOU).originalMessage?.type ?? '';
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !ReportActionsUtils.isSentMoneyReportAction(action);
});
return ReportActionsUtils.getSortedReportActions(filteredReportActions, true);
}, [allReportActions, transactionThreadReportActions]);
const indexOfLinkedAction = useMemo(() => {
if (!reportActionID) {
return -1;
}
return combinedReportActions.findIndex((obj) => String(obj.reportActionID) === String(isFirstLinkedActionRender.current ? reportActionID : currentReportActionID));
}, [combinedReportActions, currentReportActionID, reportActionID]);
const reportActions = useMemo(() => {
if (!reportActionID) {
return combinedReportActions;
}
if (isLoading || indexOfLinkedAction === -1) {
return [];
}
if (isFirstLinkedActionRender.current) {
return combinedReportActions.slice(indexOfLinkedAction);
}
const paginationSize = getInitialPaginationSize;
return combinedReportActions.slice(Math.max(indexOfLinkedAction - paginationSize, 0));
// currentReportActionID is needed to trigger batching once the report action has been positioned
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [reportActionID, combinedReportActions, indexOfLinkedAction, isLoading, currentReportActionID]);
const reportActionIDMap = useMemo(() => {
const reportActionIDs = allReportActions.map((action) => action.reportActionID);
return reportActions.map((action) => ({
reportActionID: action.reportActionID,
reportID: reportActionIDs.includes(action.reportActionID) ? reportID : transactionThreadReport?.reportID,
}));
}, [allReportActions, reportID, transactionThreadReport, reportActions]);
/**
* Retrieves the next set of report actions for the chat once we are nearing the end of what we are currently
* displaying.
*/
const fetchNewerAction = useCallback(
(newestReportAction: OnyxTypes.ReportAction) => {
if (isLoadingNewerReportActions || isLoadingInitialReportActions) {
return;
}
// If this is a one transaction report, ensure we load newer actions for both this report and the report associated with the transaction
if (!isEmptyObject(transactionThreadReport)) {
// Get newer actions based on the newest reportAction for the current report
const newestActionCurrentReport = reportActionIDMap.find((item) => item.reportID === reportID);
Report.getNewerActions(newestActionCurrentReport?.reportID ?? '0', newestActionCurrentReport?.reportActionID ?? '0');
// Get newer actions based on the newest reportAction for the transaction thread report
const newestActionTransactionThreadReport = reportActionIDMap.find((item) => item.reportID === transactionThreadReport.reportID);
Report.getNewerActions(newestActionTransactionThreadReport?.reportID ?? '0', newestActionTransactionThreadReport?.reportActionID ?? '0');
} else {
Report.getNewerActions(reportID, newestReportAction.reportActionID);
}
},
[isLoadingNewerReportActions, isLoadingInitialReportActions, reportID, transactionThreadReport, reportActionIDMap],
);
const hasMoreCached = reportActions.length < combinedReportActions.length;
const newestReportAction = useMemo(() => reportActions?.[0], [reportActions]);
const handleReportActionPagination = useCallback(
({firstReportActionID}: {firstReportActionID: string}) => {
// This function is a placeholder as the actual pagination is handled by visibleReportActions
if (!hasMoreCached) {
isFirstLinkedActionRender.current = false;
fetchNewerAction(newestReportAction);
}
if (isFirstLinkedActionRender.current) {
isFirstLinkedActionRender.current = false;
}
setCurrentReportActionID(firstReportActionID);
},
[fetchNewerAction, hasMoreCached, newestReportAction],
);
const mostRecentIOUReportActionID = useMemo(() => ReportActionsUtils.getMostRecentIOURequestActionID(reportActions), [reportActions]);
const hasCachedActionOnFirstRender = useInitialValue(() => reportActions.length > 0);
const hasNewestReportAction = reportActions[0]?.created === report.lastVisibleActionCreated || reportActions[0]?.created === transactionThreadReport?.lastVisibleActionCreated;
const oldestReportAction = useMemo(() => reportActions?.at(-1), [reportActions]);
const hasCreatedAction = oldestReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED;
useEffect(() => {
if (reportActionID) {
return;
}
const interactionTask = InteractionManager.runAfterInteractions(() => {
openReportIfNecessary();
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
if (interactionTask) {
return () => {
interactionTask.cancel();
};
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
if (!reportActionID || indexOfLinkedAction > -1) {
return;
}
// This function is triggered when a user clicks on a link to navigate to a report.
// For each link click, we retrieve the report data again, even though it may already be cached.
// There should be only one openReport execution per page start or navigating
Report.openReport(reportID, reportActionID);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [route, indexOfLinkedAction]);
useEffect(() => {
const wasLoginChangedDetected = prevAuthTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS && !session?.authTokenType;
if (wasLoginChangedDetected && didUserLogInDuringSession() && isUserCreatedPolicyRoom(report)) {
openReportIfNecessary();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [session, report]);
useEffect(() => {
const prevIsSmallScreenWidth = prevIsSmallScreenWidthRef.current;
// If the view is expanded from mobile to desktop layout
// we update the new marker position, mark the report as read, and fetch new report actions
const didScreenSizeIncrease = prevIsSmallScreenWidth && !isSmallScreenWidth;
const didReportBecomeVisible = isReportFullyVisible && didScreenSizeIncrease;
if (didReportBecomeVisible) {
openReportIfNecessary();
}
// update ref with current state
prevIsSmallScreenWidthRef.current = isSmallScreenWidth;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSmallScreenWidth, reportActions, isReportFullyVisible]);
useEffect(() => {
// Ensures the optimistic report is created successfully
if (route?.params?.reportID !== reportID) {
return;
}
// Ensures subscription event succeeds when the report/workspace room is created optimistically.
// Check if the optimistic `OpenReport` or `AddWorkspaceRoom` has succeeded by confirming
// any `pendingFields.createChat` or `pendingFields.addWorkspaceRoom` fields are set to null.
// Existing reports created will have empty fields for `pendingFields`.
const didCreateReportSuccessfully = !report.pendingFields || (!report.pendingFields.addWorkspaceRoom && !report.pendingFields.createChat);
if (!didSubscribeToReportTypingEvents.current && didCreateReportSuccessfully) {
const interactionTask = InteractionManager.runAfterInteractions(() => {
Report.subscribeToReportTypingEvents(reportID);
didSubscribeToReportTypingEvents.current = true;
});
return () => {
interactionTask.cancel();
};
}
}, [report.pendingFields, didSubscribeToReportTypingEvents, route, reportID]);
const onContentSizeChange = useCallback((w: number, h: number) => {
contentListHeight.current = h;
}, []);
const checkIfContentSmallerThanList = useCallback(() => windowHeight - DIFF_BETWEEN_SCREEN_HEIGHT_AND_LIST - SPACER > contentListHeight.current, [windowHeight]);
/**
* Retrieves the next set of report actions for the chat once we are nearing the end of what we are currently
* displaying.
*/
const loadOlderChats = useCallback(() => {
// Only fetch more if we are neither already fetching (so that we don't initiate duplicate requests) nor offline.
if (!!network.isOffline || isLoadingOlderReportActions || isLoadingInitialReportActions) {
return;
}
// Don't load more chats if we're already at the beginning of the chat history
if (!oldestReportAction || hasCreatedAction) {
return;
}
if (!isEmptyObject(transactionThreadReport)) {
// Get newer actions based on the newest reportAction for the current report
const oldestActionCurrentReport = reportActionIDMap.findLast((item) => item.reportID === reportID);
Report.getNewerActions(oldestActionCurrentReport?.reportID ?? '0', oldestActionCurrentReport?.reportActionID ?? '0');
// Get newer actions based on the newest reportAction for the transaction thread report
const oldestActionTransactionThreadReport = reportActionIDMap.findLast((item) => item.reportID === transactionThreadReport.reportID);
Report.getNewerActions(oldestActionTransactionThreadReport?.reportID ?? '0', oldestActionTransactionThreadReport?.reportActionID ?? '0');
} else {
// Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments
Report.getOlderActions(reportID, oldestReportAction.reportActionID);
}
}, [network.isOffline, isLoadingOlderReportActions, isLoadingInitialReportActions, oldestReportAction, hasCreatedAction, reportID, reportActionIDMap, transactionThreadReport]);
const loadNewerChats = useCallback(() => {
if (isLoadingInitialReportActions || isLoadingOlderReportActions || network.isOffline || newestReportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return;
}
// Determines if loading older reports is necessary when the content is smaller than the list
// and there are fewer than 23 items, indicating we've reached the oldest message.
const isLoadingOlderReportsFirstNeeded = checkIfContentSmallerThanList() && reportActions.length > 23;
if (
(reportActionID && indexOfLinkedAction > -1 && !hasNewestReportAction && !isLoadingOlderReportsFirstNeeded) ||
(!reportActionID && !hasNewestReportAction && !isLoadingOlderReportsFirstNeeded)
) {
handleReportActionPagination({firstReportActionID: newestReportAction?.reportActionID});
}
}, [
isLoadingInitialReportActions,
isLoadingOlderReportActions,
checkIfContentSmallerThanList,
reportActionID,
indexOfLinkedAction,
hasNewestReportAction,
handleReportActionPagination,
network.isOffline,
reportActions.length,
newestReportAction,
]);
/**
* Runs when the FlatList finishes laying out
*/
const recordTimeToMeasureItemLayout = useCallback(() => {
if (didLayout.current) {
return;
}
didLayout.current = true;
// Capture the init measurement only once not per each chat switch as the value gets overwritten
if (!ReportActionsView.initMeasured) {
Performance.markEnd(CONST.TIMING.REPORT_INITIAL_RENDER);
Timing.end(CONST.TIMING.REPORT_INITIAL_RENDER);
ReportActionsView.initMeasured = true;
} else {
Performance.markEnd(CONST.TIMING.SWITCH_REPORT);
}
Timing.end(CONST.TIMING.SWITCH_REPORT, hasCachedActionOnFirstRender ? CONST.TIMING.WARM : CONST.TIMING.COLD);
}, [hasCachedActionOnFirstRender]);
useEffect(() => {
// Temporary solution for handling REPORTPREVIEW. More details: https://expensify.slack.com/archives/C035J5C9FAP/p1705417778466539?thread_ts=1705035404.136629&cid=C035J5C9FAP
// This code should be removed once REPORTPREVIEW is no longer repositioned.
// We need to call openReport for gaps created by moving REPORTPREVIEW, which causes mismatches in previousReportActionID and reportActionID of adjacent reportActions. The server returns the correct sequence, allowing us to overwrite incorrect data with the correct one.
const shouldOpenReport =
newestReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW &&
!hasCreatedAction &&
isReadyForCommentLinking &&
reportActions.length < 24 &&
reportActions.length >= 1 &&
!isLoadingInitialReportActions &&
!isLoadingOlderReportActions &&
!isLoadingNewerReportActions;
if (shouldOpenReport) {
Report.openReport(reportID, reportActionID);
}
}, [
hasCreatedAction,
reportID,
reportActions,
reportActionID,
newestReportAction?.actionName,
isReadyForCommentLinking,
isLoadingOlderReportActions,
isLoadingNewerReportActions,
isLoadingInitialReportActions,
]);
// Check if the first report action in the list is the one we're currently linked to
const isTheFirstReportActionIsLinked = newestReportAction?.reportActionID === reportActionID;
useEffect(() => {
let timerID: NodeJS.Timeout;
if (isTheFirstReportActionIsLinked) {
setNavigatingToLinkedMessage(true);
} else {
// After navigating to the linked reportAction, apply this to correctly set
// `autoscrollToTopThreshold` prop when linking to a specific reportAction.
InteractionManager.runAfterInteractions(() => {
// Using a short delay to ensure the view is updated after interactions
timerID = setTimeout(() => setNavigatingToLinkedMessage(false), 10);
});
}
return () => {
if (!timerID) {
return;
}
clearTimeout(timerID);
};
}, [isTheFirstReportActionIsLinked]);
// When we are offline before opening a money request report,
// the total of the report and sometimes the money request aren't displayed because these actions aren't returned until `OpenReport` API is complete.
// We generate a fake created action here if it doesn't exist to display the total whenever possible because the total just depends on report data
// and we also generate a money request action if the number of money requests in reportActions is less than the total number of money requests
// to display at least one money request action to match the total data.
const reportActionsToDisplay = useMemo(() => {
if (!ReportUtils.isMoneyRequestReport(report) || !reportActions.length) {
return reportActions;
}
const actions = [...reportActions];
const lastAction = reportActions[reportActions.length - 1];
if (!ReportActionsUtils.isCreatedAction(lastAction)) {
const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(String(report?.ownerAccountID), DateUtils.subtractMillisecondsFromDateTime(lastAction.created, 1));
optimisticCreatedAction.pendingAction = null;
actions.push(optimisticCreatedAction);
}
const reportPreviewAction = ReportActionsUtils.getReportPreviewAction(report.chatReportID ?? '', report.reportID);
const moneyRequestActions = reportActions.filter(
(action) =>
action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
action.originalMessage &&
(action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE ||
Boolean(action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && action.originalMessage.IOUDetails) ||
action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK),
);
if (report.total && moneyRequestActions.length < (reportPreviewAction?.childMoneyRequestCount ?? 0) && isEmptyObject(transactionThreadReport)) {
const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction(
CONST.IOU.REPORT_ACTION_TYPE.CREATE,
0,
CONST.CURRENCY.USD,
'',
[],
NumberUtils.rand64(),
undefined,
report.reportID,
false,
false,
{},
false,
DateUtils.subtractMillisecondsFromDateTime(actions[actions.length - 1].created, 1),
) as OnyxTypes.ReportAction;
moneyRequestActions.push(optimisticIOUAction);
actions.splice(actions.length - 1, 0, optimisticIOUAction);
}
// Update pending action of created action if we have some requests that are pending
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const createdAction = actions.pop()!;
if (moneyRequestActions.filter((action) => Boolean(action.pendingAction)).length > 0) {
createdAction.pendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE;
}
return [...actions, createdAction];
}, [reportActions, report, transactionThreadReport]);
// Comments have not loaded at all yet do nothing
if (!reportActions.length) {
return null;
}
// AutoScroll is disabled when we do linking to a specific reportAction
const shouldEnableAutoScroll = hasNewestReportAction && (!reportActionID || !isNavigatingToLinkedMessage);
return (
<>
<ReportActionsList
report={report}
transactionThreadReport={transactionThreadReport}
reportActions={reportActions}
parentReportAction={parentReportAction}
onLayout={recordTimeToMeasureItemLayout}
sortedReportActions={reportActionsToDisplay}
mostRecentIOUReportActionID={mostRecentIOUReportActionID}
loadOlderChats={loadOlderChats}
loadNewerChats={loadNewerChats}
isLoadingInitialReportActions={isLoadingInitialReportActions}
isLoadingOlderReportActions={isLoadingOlderReportActions}
isLoadingNewerReportActions={isLoadingNewerReportActions}
listID={listID}
onContentSizeChange={onContentSizeChange}
shouldEnableAutoScrollToTopThreshold={shouldEnableAutoScroll}
/>
<PopoverReactionList ref={reactionListRef} />
</>
);
}
ReportActionsView.displayName = 'ReportActionsView';
ReportActionsView.initMeasured = false;
function arePropsEqual(oldProps: ReportActionsViewProps, newProps: ReportActionsViewProps): boolean {
if (!lodashIsEqual(oldProps.isReadyForCommentLinking, newProps.isReadyForCommentLinking)) {
return false;
}
if (!lodashIsEqual(oldProps.reportActions, newProps.reportActions)) {
return false;
}
if (!lodashIsEqual(oldProps.transactionThreadReportActions, newProps.transactionThreadReportActions)) {
return false;
}
if (!lodashIsEqual(oldProps.parentReportAction, newProps.parentReportAction)) {
return false;
}
if (oldProps.session?.authTokenType !== newProps.session?.authTokenType) {
return false;
}
if (oldProps.isLoadingInitialReportActions !== newProps.isLoadingInitialReportActions) {
return false;
}
if (oldProps.isLoadingOlderReportActions !== newProps.isLoadingOlderReportActions) {
return false;
}
if (oldProps.isLoadingNewerReportActions !== newProps.isLoadingNewerReportActions) {
return false;
}
return lodashIsEqual(oldProps.report, newProps.report);
}
const MemoizedReportActionsView = React.memo(ReportActionsView, arePropsEqual);
export default Performance.withRenderTrace({id: '<ReportActionsView> rendering'})(
withOnyx<ReportActionsViewProps, ReportActionsViewOnyxProps>({
session: {
key: ONYXKEYS.SESSION,
},
transactionThreadReportActions: {
key: ({transactionThreadReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`,
canEvict: false,
selector: (reportActions: OnyxEntry<OnyxTypes.ReportActions>) => ReportActionsUtils.getSortedReportActionsForDisplay(reportActions, true),
},
transactionThreadReport: {
key: ({transactionThreadReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`,
},
})(MemoizedReportActionsView),
);