Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor OpenReport API call for Report GetHistory #10164

Merged
merged 33 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
713e1e0
removing fetch data
sketchydroide Jul 28, 2022
de85a84
sequence number is no longer used
sketchydroide Jul 28, 2022
1c7bce4
reorganizing this a bit
sketchydroide Aug 1, 2022
8408423
removing updateNewMarkerAndMarkReadOnce
sketchydroide Aug 2, 2022
7f11c94
the view will decide on this
sketchydroide Aug 2, 2022
b301b28
using the isLoadingReportData only if we have no reportActions
sketchydroide Aug 2, 2022
8260661
Merge branch 'main' into afonseca_get_history_open_report
sketchydroide Aug 2, 2022
b654d97
the actions does not know if it's the inital loading or not, the scre…
sketchydroide Aug 2, 2022
5e37db3
removing isLoadingReportData
sketchydroide Aug 2, 2022
2705f6e
adding the fetchData back for now until we do the reconnect action
sketchydroide Aug 2, 2022
2763fc4
linter
sketchydroide Aug 3, 2022
9b1b0b6
Merge branch 'main' into afonseca_get_history_open_report
sketchydroide Aug 8, 2022
3dc5dc6
Merge branch 'main' into afonseca_get_history_open_report
sketchydroide Aug 9, 2022
c87a3e6
remove IS_LOADING_INITIAL_REPORT_ACTIONS
sketchydroide Aug 10, 2022
18d11f3
the OpenReport action is write
sketchydroide Aug 10, 2022
11cddbc
adding why to the doc
sketchydroide Aug 10, 2022
a298893
missing semi colon
sketchydroide Aug 10, 2022
7468ac5
Merge branch 'main' into afonseca_get_history_open_report
sketchydroide Aug 11, 2022
630f75c
removing the collection
sketchydroide Aug 11, 2022
d9909a2
adding the comment
sketchydroide Aug 11, 2022
df12dbd
adding for isLoadingMoreReportActions
sketchydroide Aug 11, 2022
a689a90
missed the route
sketchydroide Aug 11, 2022
10b86ee
correcting the compose
sketchydroide Aug 12, 2022
bc124fc
linter
sketchydroide Aug 12, 2022
bca0f8b
styling suggestions
sketchydroide Aug 15, 2022
39fd1ec
forgot indenting
sketchydroide Aug 15, 2022
0be9f97
Merge branch 'main' into afonseca_get_history_open_report
sketchydroide Aug 16, 2022
852e636
wrong method changed
sketchydroide Aug 16, 2022
599ca8b
remove fetchActions
sketchydroide Aug 16, 2022
2d7de46
setting the report as required
sketchydroide Aug 17, 2022
8954f03
Merge branch 'main' into afonseca_get_history_open_report
sketchydroide Aug 17, 2022
8ebc4f7
Update src/pages/home/report/ReportActionsView.js
marcaaron Aug 17, 2022
d2695b2
Merge branch 'main' into afonseca_get_history_open_report
sketchydroide Aug 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,23 +1038,48 @@ function deleteReportComment(reportID, reportAction) {
* @param {Number} reportID
*/
function openReport(reportID) {
const sequenceNumber = getMaxSequenceNumber(reportID);
API.write('OpenReport',
let onyxData;
let commonOptimisticData = {
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
lastVisitedTimestamp: Date.now(),
unreadActionCount: 0,
}
};
// only show loading state if the report has not been open yet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like something the view should handle. We can still set the loading state. The view will decide to use it or not based on whether it has initial report actions to display.

if (getLastReadSequenceNumber(reportID) === 0) {
onyxData = {
optimisticData: [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.IS_LOADING_REPORT_DATA}`,
value: true,
},
commonOptimisticData,
],
successData: [{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.IS_LOADING_REPORT_DATA}`,
value: false,
}],
failureData: [{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.IS_LOADING_REPORT_DATA}`,
value: false,
}],
};
} else {
onyxData = {
optimisticData: [commonOptimisticData],
};
}

API.read('OpenReport',
{
reportID,
sequenceNumber,
},
{
optimisticData: [{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
lastReadSequenceNumber: sequenceNumber,
lastVisitedTimestamp: Date.now(),
unreadActionCount: 0,
},
}],
});
onyxData);
}

/**
Expand Down
11 changes: 2 additions & 9 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class ReportActionsView extends React.Component {
this.updateNewMarkerAndMarkReadOnce();
}

this.fetchData();
Report.openReport(this.props.reportID);
sketchydroide marked this conversation as resolved.
Show resolved Hide resolved
}

shouldComponentUpdate(nextProps, nextState) {
Expand Down Expand Up @@ -201,10 +201,7 @@ class ReportActionsView extends React.Component {

componentDidUpdate(prevProps) {
if (prevProps.network.isOffline && !this.props.network.isOffline) {
if (this.getIsReportFullyVisible()) {
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
Report.openReport(this.props.reportID);
}
this.fetchData();
Report.openReport(this.props.reportID);
}

// Update the last read action for the report currently in view when report data finishes loading.
Expand Down Expand Up @@ -274,10 +271,6 @@ class ReportActionsView extends React.Component {
return Visibility.isVisible() && !isSidebarCoveringReportView;
}

fetchData() {
Report.fetchActions(this.props.reportID);
}

/**
* Retrieves the next set of report actions for the chat once we are nearing the end of what we are currently
* displaying.
Expand Down