-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathReportActionsListItemRenderer.js
154 lines (140 loc) · 6.18 KB
/
ReportActionsListItemRenderer.js
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
import PropTypes from 'prop-types';
import React, {memo, useMemo} from 'react';
import _ from 'underscore';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import reportPropTypes from '@pages/reportPropTypes';
import CONST from '@src/CONST';
import ReportActionItem from './ReportActionItem';
import ReportActionItemParentAction from './ReportActionItemParentAction';
import reportActionPropTypes from './reportActionPropTypes';
const propTypes = {
/** All the data of the action item */
reportAction: PropTypes.shape(reportActionPropTypes).isRequired,
/** Position index of the report action in the overall report FlatList view */
index: PropTypes.number.isRequired,
/** Report for this action */
report: reportPropTypes.isRequired,
/** Should the comment have the appearance of being grouped with the previous comment? */
displayAsGroup: PropTypes.bool.isRequired,
/** The ID of the most recent IOU report action connected with the shown report */
mostRecentIOUReportActionID: PropTypes.string,
/** If the thread divider line should be hidden */
shouldHideThreadDividerLine: PropTypes.bool.isRequired,
/** Should we display the new marker on top of the comment? */
shouldDisplayNewMarker: PropTypes.bool.isRequired,
/** Linked report action ID */
linkedReportActionID: PropTypes.string,
};
const defaultProps = {
mostRecentIOUReportActionID: '',
linkedReportActionID: '',
};
function ReportActionsListItemRenderer({
reportAction,
index,
report,
displayAsGroup,
mostRecentIOUReportActionID,
shouldHideThreadDividerLine,
shouldDisplayNewMarker,
linkedReportActionID,
}) {
const shouldDisplayParentAction =
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED &&
ReportUtils.isChatThread(report) &&
!ReportActionsUtils.isTransactionThread(ReportActionsUtils.getParentReportAction(report));
/**
* Create a lightweight ReportAction so as to keep the re-rendering as light as possible by
* passing in only the required props.
*/
const action = useMemo(
() => ({
reportActionID: reportAction.reportActionID,
message: reportAction.message,
pendingAction: reportAction.pendingAction,
actionName: reportAction.actionName,
errors: reportAction.errors,
originalMessage: reportAction.originalMessage,
childCommenterCount: reportAction.childCommenterCount,
linkMetadata: reportAction.linkMetadata,
childReportID: reportAction.childReportID,
childLastVisibleActionCreated: reportAction.childLastVisibleActionCreated,
whisperedToAccountIDs: reportAction.whisperedToAccountIDs,
error: reportAction.error,
created: reportAction.created,
actorAccountID: reportAction.actorAccountID,
childVisibleActionCount: reportAction.childVisibleActionCount,
childOldestFourAccountIDs: reportAction.childOldestFourAccountIDs,
childType: reportAction.childType,
person: reportAction.person,
isOptimisticAction: reportAction.isOptimisticAction,
delegateAccountID: reportAction.delegateAccountID,
previousMessage: reportAction.previousMessage,
attachmentInfo: reportAction.attachmentInfo,
childStateNum: reportAction.childStateNum,
childStatusNum: reportAction.childStatusNum,
childReportName: reportAction.childReportName,
childManagerAccountID: reportAction.childManagerAccountID,
childMoneyRequestCount: reportAction.childMoneyRequestCount,
}),
[
reportAction.actionName,
reportAction.childCommenterCount,
reportAction.childLastVisibleActionCreated,
reportAction.childReportID,
reportAction.created,
reportAction.error,
reportAction.errors,
reportAction.linkMetadata,
reportAction.message,
reportAction.originalMessage,
reportAction.pendingAction,
reportAction.reportActionID,
reportAction.whisperedToAccountIDs,
reportAction.actorAccountID,
reportAction.childVisibleActionCount,
reportAction.childOldestFourAccountIDs,
reportAction.person,
reportAction.isOptimisticAction,
reportAction.childType,
reportAction.delegateAccountID,
reportAction.previousMessage,
reportAction.attachmentInfo,
reportAction.childStateNum,
reportAction.childStatusNum,
reportAction.childReportName,
reportAction.childManagerAccountID,
reportAction.childMoneyRequestCount,
],
);
return shouldDisplayParentAction ? (
<ReportActionItemParentAction
shouldHideThreadDividerLine={shouldDisplayParentAction && shouldHideThreadDividerLine}
reportID={report.reportID}
index={index}
/>
) : (
<ReportActionItem
shouldHideThreadDividerLine={shouldHideThreadDividerLine}
report={report}
action={action}
linkedReportActionID={linkedReportActionID}
displayAsGroup={displayAsGroup}
shouldDisplayNewMarker={shouldDisplayNewMarker}
shouldShowSubscriptAvatar={
(ReportUtils.isPolicyExpenseChat(report) || ReportUtils.isExpenseReport(report)) &&
_.contains(
[CONST.REPORT.ACTIONS.TYPE.IOU, CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW, CONST.REPORT.ACTIONS.TYPE.SUBMITTED, CONST.REPORT.ACTIONS.TYPE.APPROVED],
reportAction.actionName,
)
}
isMostRecentIOUReportAction={reportAction.reportActionID === mostRecentIOUReportActionID}
index={index}
/>
);
}
ReportActionsListItemRenderer.propTypes = propTypes;
ReportActionsListItemRenderer.defaultProps = defaultProps;
ReportActionsListItemRenderer.displayName = 'ReportActionsListItemRenderer';
export default memo(ReportActionsListItemRenderer);