Skip to content

Commit 8d650c6

Browse files
authored
Merge pull request #18423 from Expensify/cristi_display-report-preview
Display report preview using new reportAction data source
2 parents f323b14 + 1330745 commit 8d650c6

File tree

11 files changed

+186
-275
lines changed

11 files changed

+186
-275
lines changed

src/CONST.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ const CONST = {
469469
CHRONOSOOOLIST: 'CHRONOSOOOLIST',
470470
TASKCOMPLETED: 'TASKCOMPLETED',
471471
TASKREOPENED: 'TASKREOPENED',
472+
REPORTPREVIEW: 'REPORTPREVIEW',
472473
POLICYCHANGELOG: {
473474
ADD_APPROVER_RULE: 'POLICYCHANGELOG_ADD_APPROVER_RULE',
474475
ADD_CATEGORY: 'POLICYCHANGELOG_ADD_CATEGORY',

src/components/ReportActionItem/IOUPreview.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ const IOUPreview = (props) => {
224224
</View>
225225
)}
226226
</View>
227-
228227
<View style={[styles.flexRow]}>
229228
<View style={[styles.flex1]}>
230229
{!isCurrentUserManager && props.shouldShowPendingConversionMessage && (

src/components/ReportActionItem/MoneyRequestAction.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import ONYXKEYS from '../../ONYXKEYS';
77
import CONST from '../../CONST';
88
import {withNetwork} from '../OnyxProvider';
99
import compose from '../../libs/compose';
10-
import ReportPreview from './ReportPreview';
1110
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
1211
import networkPropTypes from '../networkPropTypes';
1312
import iouReportPropTypes from '../../pages/iouReportPropTypes';
@@ -149,17 +148,6 @@ const MoneyRequestAction = (props) => {
149148
containerStyles={[styles.cursorPointer, props.isHovered ? styles.iouPreviewBoxHover : undefined]}
150149
isHovered={props.isHovered}
151150
/>
152-
{props.isMostRecentIOUReportAction && !hasMultipleParticipants && (
153-
<ReportPreview
154-
action={props.action}
155-
chatReportID={props.chatReportID}
156-
iouReportID={props.requestReportID}
157-
contextMenuAnchor={props.contextMenuAnchor}
158-
onViewDetailsPressed={onIOUPreviewPressed}
159-
checkIfContextMenuActive={props.checkIfContextMenuActive}
160-
isHovered={props.isHovered}
161-
/>
162-
)}
163151
</>
164152
);
165153
};

src/components/ReportActionItem/ReportPreview.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import styles from '../../styles/styles';
1212
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
1313
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
1414
import compose from '../../libs/compose';
15-
import ONYXKEYS from '../../ONYXKEYS';
1615
import ControlSelection from '../../libs/ControlSelection';
1716
import * as DeviceCapabilities from '../../libs/DeviceCapabilities';
1817
import {showContextMenuForReport} from '../ShowContextMenuContext';
1918
import * as StyleUtils from '../../styles/StyleUtils';
2019
import * as CurrencyUtils from '../../libs/CurrencyUtils';
2120
import * as ReportUtils from '../../libs/ReportUtils';
2221
import Button from '../Button';
23-
import Navigation from '../../libs/Navigation/Navigation';
24-
import ROUTES from '../../ROUTES';
2522
import themeColors from '../../styles/themes/default';
2623
import getButtonState from '../../libs/getButtonState';
24+
import Navigation from '../../libs/Navigation/Navigation';
25+
import ROUTES from '../../ROUTES';
26+
import ONYXKEYS from '../../ONYXKEYS';
2727

2828
const propTypes = {
2929
/** All the data of the action */
@@ -36,6 +36,7 @@ const propTypes = {
3636
// eslint-disable-next-line react/no-unused-prop-types
3737
iouReportID: PropTypes.string.isRequired,
3838

39+
/* Onyx Props */
3940
/** chatReport associated with iouReport */
4041
chatReport: PropTypes.shape({
4142
/** The participants of this report */
@@ -72,9 +73,6 @@ const propTypes = {
7273
/** Popover context menu anchor, used for showing context menu */
7374
contextMenuAnchor: PropTypes.shape({current: PropTypes.elementType}),
7475

75-
/** Callback invoked when View Details is pressed */
76-
onViewDetailsPressed: PropTypes.func,
77-
7876
/** Callback for updating context menu active state, used for showing context menu */
7977
checkIfContextMenuActive: PropTypes.func,
8078

@@ -89,7 +87,6 @@ const defaultProps = {
8987
isHovered: false,
9088
chatReport: {},
9189
iouReport: {},
92-
onViewDetailsPressed: () => {},
9390
checkIfContextMenuActive: () => {},
9491
session: {
9592
email: null,
@@ -106,7 +103,9 @@ const ReportPreview = (props) => {
106103
{_.map(props.action.message, (index) => (
107104
<Pressable
108105
key={`ReportPreview-${props.action.reportActionID}-${index}`}
109-
onPress={props.onViewDetailsPressed}
106+
onPress={() => {
107+
Navigation.navigate(ROUTES.getReportRoute(props.iouReportID));
108+
}}
110109
onPressIn={() => DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()}
111110
onPressOut={() => ControlSelection.unblock()}
112111
onLongPress={(event) => showContextMenuForReport(event, props.contextMenuAnchor, props.chatReportID, props.action, props.checkIfContextMenuActive)}

src/libs/ReportActionsUtils.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ function getSortedReportActions(reportActions, shouldSortInDescendingOrder = fal
100100
if ((first.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED || second.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) && first.actionName !== second.actionName) {
101101
return (first.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED ? -1 : 1) * invertedMultiplier;
102102
}
103+
// Ensure that `REPORTPREVIEW` actions always come after if they have the same timestamp as another action type
104+
if ((first.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW || second.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW) && first.actionName !== second.actionName) {
105+
return (first.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW ? 1 : -1) * invertedMultiplier;
106+
}
103107

104108
// Then fallback on reportActionID as the final sorting criteria. It is a random number,
105109
// but using this will ensure that the order of reportActions with the same created time and action type
@@ -333,6 +337,18 @@ function getLinkedTransactionID(reportID, reportActionID) {
333337
return reportAction.originalMessage.IOUTransactionID;
334338
}
335339

340+
/**
341+
* @param {*} chatReportID
342+
* @param {*} iouReportID
343+
* @returns {Object} The report preview action or `null` if one couldn't be found
344+
*/
345+
function getReportPreviewAction(chatReportID, iouReportID) {
346+
return _.find(
347+
allReportActions[chatReportID],
348+
(reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lodashGet(reportAction, 'originalMessage.linkedReportID') === iouReportID,
349+
);
350+
}
351+
336352
function isCreatedTaskReportAction(reportAction) {
337353
return reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && _.has(reportAction.originalMessage, 'taskReportID');
338354
}
@@ -351,6 +367,7 @@ export {
351367
getLatestReportActionFromOnyxData,
352368
isMoneyRequestAction,
353369
getLinkedTransactionID,
370+
getReportPreviewAction,
354371
isCreatedTaskReportAction,
355372
getParentReportAction,
356373
isTransactionThread,

src/libs/ReportUtils.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,29 @@ function buildOptimisticIOUReportAction(type, amount, currency, comment, partici
14271427
};
14281428
}
14291429

1430+
function buildOptimisticReportPreview(reportID, iouReportID, payeeAccountID) {
1431+
return {
1432+
reportActionID: NumberUtils.rand64(),
1433+
reportID,
1434+
created: DateUtils.getDBTime(),
1435+
actionName: CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW,
1436+
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
1437+
accountID: payeeAccountID,
1438+
message: [
1439+
{
1440+
html: '',
1441+
text: '',
1442+
isEdited: false,
1443+
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
1444+
},
1445+
],
1446+
originalMessage: {
1447+
linkedReportID: iouReportID,
1448+
},
1449+
actorEmail: currentUserEmail,
1450+
};
1451+
}
1452+
14301453
function buildOptimisticTaskReportAction(taskReportID, actionName, message = '') {
14311454
const originalMessage = {
14321455
taskReportID,
@@ -2219,6 +2242,7 @@ export {
22192242
buildOptimisticIOUReport,
22202243
buildOptimisticExpenseReport,
22212244
buildOptimisticIOUReportAction,
2245+
buildOptimisticReportPreview,
22222246
buildOptimisticTaskReportAction,
22232247
buildOptimisticAddCommentReportAction,
22242248
buildOptimisticTaskCommentReportAction,

0 commit comments

Comments
 (0)