Skip to content

Commit a4c70a6

Browse files
authored
Merge pull request #10164 from Expensify/afonseca_get_history_open_report
Refactor OpenReport API call for Report GetHistory
2 parents 99271b8 + d2695b2 commit a4c70a6

File tree

4 files changed

+63
-109
lines changed

4 files changed

+63
-109
lines changed

src/ONYXKEYS.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ export default {
9696
POLICY: 'policy_',
9797
REPORTS_WITH_DRAFT: 'reportWithDraft_',
9898
REPORT_IS_COMPOSER_FULL_SIZE: 'reportIsComposerFullSize_',
99-
IS_LOADING_INITIAL_REPORT_ACTIONS: 'isLoadingInitialReportActions_',
100-
IS_LOADING_MORE_REPORT_ACTIONS: 'isLoadingMoreReportActions_',
10199
POLICY_MEMBER_LIST: 'policyMemberList_',
102100
},
103101

src/libs/actions/Report.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -625,15 +625,14 @@ function fetchOrCreateChatReport(participants, shouldNavigate = true) {
625625
}
626626

627627
/**
628-
* Get the actions of a report
628+
* Get the initial actions of a report
629629
*
630630
* @param {Number} reportID
631-
* @returns {Promise}
632631
*/
633-
function fetchActions(reportID) {
632+
function fetchInitialActions(reportID) {
634633
const reportActionsOffset = -1;
635634

636-
return DeprecatedAPI.Report_GetHistory({
635+
DeprecatedAPI.Report_GetHistory({
637636
reportID,
638637
reportActionsOffset,
639638
reportActionsLimit: CONST.REPORT.ACTIONS.LIMIT,
@@ -644,17 +643,6 @@ function fetchActions(reportID) {
644643
});
645644
}
646645

647-
/**
648-
* Get the initial actions of a report
649-
*
650-
* @param {Number} reportID
651-
*/
652-
function fetchInitialActions(reportID) {
653-
Onyx.set(`${ONYXKEYS.COLLECTION.IS_LOADING_INITIAL_REPORT_ACTIONS}${reportID}`, true);
654-
fetchActions(reportID)
655-
.finally(() => Onyx.set(`${ONYXKEYS.COLLECTION.IS_LOADING_INITIAL_REPORT_ACTIONS}${reportID}`, false));
656-
}
657-
658646
/**
659647
* Get all of our reports
660648
*
@@ -989,22 +977,34 @@ function deleteReportComment(reportID, reportAction) {
989977
* @param {Number} reportID
990978
*/
991979
function openReport(reportID) {
992-
const sequenceNumber = getMaxSequenceNumber(reportID);
993980
API.write('OpenReport',
994981
{
995982
reportID,
996-
sequenceNumber,
997983
},
998984
{
999985
optimisticData: [{
1000986
onyxMethod: CONST.ONYX.METHOD.MERGE,
1001987
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
1002988
value: {
1003-
lastReadSequenceNumber: sequenceNumber,
989+
isLoadingReportActions: true,
1004990
lastVisitedTimestamp: Date.now(),
1005991
unreadActionCount: 0,
1006992
},
1007993
}],
994+
successData: [{
995+
onyxMethod: CONST.ONYX.METHOD.MERGE,
996+
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
997+
value: {
998+
isLoadingReportActions: false,
999+
},
1000+
}],
1001+
failureData: [{
1002+
onyxMethod: CONST.ONYX.METHOD.MERGE,
1003+
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
1004+
value: {
1005+
isLoadingReportActions: false,
1006+
},
1007+
}],
10081008
});
10091009
}
10101010

@@ -1024,18 +1024,24 @@ function readOldestAction(reportID, oldestActionSequenceNumber) {
10241024
{
10251025
optimisticData: [{
10261026
onyxMethod: CONST.ONYX.METHOD.MERGE,
1027-
key: `${ONYXKEYS.COLLECTION.IS_LOADING_MORE_REPORT_ACTIONS}${reportID}`,
1028-
value: true,
1027+
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
1028+
value: {
1029+
isLoadingMoreReportActions: true,
1030+
},
10291031
}],
10301032
successData: [{
10311033
onyxMethod: CONST.ONYX.METHOD.MERGE,
1032-
key: `${ONYXKEYS.COLLECTION.IS_LOADING_MORE_REPORT_ACTIONS}${reportID}`,
1033-
value: false,
1034+
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
1035+
value: {
1036+
isLoadingMoreReportActions: false,
1037+
},
10341038
}],
10351039
failureData: [{
10361040
onyxMethod: CONST.ONYX.METHOD.MERGE,
1037-
key: `${ONYXKEYS.COLLECTION.IS_LOADING_MORE_REPORT_ACTIONS}${reportID}`,
1038-
value: false,
1041+
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
1042+
value: {
1043+
isLoadingMoreReportActions: false,
1044+
},
10391045
}],
10401046
});
10411047
}

src/pages/home/ReportScreen.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ const propTypes = {
6060

6161
/** Whether there is an outstanding amount in IOU */
6262
hasOutstandingIOU: PropTypes.bool,
63+
64+
/** Flag to check if the report actions data are loading */
65+
isLoadingReportActions: PropTypes.bool,
6366
}),
6467

6568
/** Array of report actions for this report */
@@ -71,9 +74,6 @@ const propTypes = {
7174
/** Beta features list */
7275
betas: PropTypes.arrayOf(PropTypes.string),
7376

74-
/** Flag to check if the initial report actions data are loading */
75-
isLoadingInitialReportActions: PropTypes.bool,
76-
7777
/** The policies which the user has access to */
7878
policies: PropTypes.objectOf(PropTypes.shape({
7979
/** The policy name */
@@ -99,10 +99,10 @@ const defaultProps = {
9999
unreadActionCount: 0,
100100
maxSequenceNumber: 0,
101101
hasOutstandingIOU: false,
102+
isLoadingReportActions: false,
102103
},
103104
isComposerFullSize: false,
104105
betas: [],
105-
isLoadingInitialReportActions: false,
106106
policies: {},
107107
};
108108

@@ -146,7 +146,6 @@ class ReportScreen extends React.Component {
146146
}
147147

148148
componentWillUnmount() {
149-
clearTimeout(this.loadingTimerId);
150149
this.removeViewportResizeListener();
151150
}
152151

@@ -163,11 +162,14 @@ class ReportScreen extends React.Component {
163162

164163
/**
165164
* When reports change there's a brief time content is not ready to be displayed
165+
* It Should show the loader if it's the first time we are opening the report
166166
*
167167
* @returns {Boolean}
168168
*/
169169
shouldShowLoader() {
170-
return !getReportID(this.props.route) || (_.isEmpty(this.props.reportActions) && this.props.isLoadingInitialReportActions);
170+
// This means there are no reportActions at all to display, but it is still in the process of loading the next set of actions.
171+
const isLoadingInitialReportActions = _.isEmpty(this.props.reportActions) && this.props.report.isLoadingReportActions;
172+
return !getReportID(this.props.route) || isLoadingInitialReportActions;
171173
}
172174

173175
/**
@@ -240,7 +242,6 @@ class ReportScreen extends React.Component {
240242
)
241243
: (
242244
<ReportActionsView
243-
reportID={reportID}
244245
reportActions={this.props.reportActions}
245246
report={this.props.report}
246247
session={this.props.session}
@@ -303,10 +304,6 @@ export default compose(
303304
betas: {
304305
key: ONYXKEYS.BETAS,
305306
},
306-
isLoadingInitialReportActions: {
307-
key: ({route}) => `${ONYXKEYS.COLLECTION.IS_LOADING_INITIAL_REPORT_ACTIONS}${getReportID(route)}`,
308-
initWithStoredValues: false,
309-
},
310307
policies: {
311308
key: ONYXKEYS.COLLECTION.POLICY,
312309
},

0 commit comments

Comments
 (0)