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 5 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
20 changes: 5 additions & 15 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,15 +625,14 @@ function fetchOrCreateChatReport(participants, shouldNavigate = true) {
}

/**
* Get the actions of a report
* Get the initial actions of a report
*
* @param {Number} reportID
* @returns {Promise}
*/
function fetchActions(reportID) {
function fetchInitialActions(reportID) {
const reportActionsOffset = -1;

return DeprecatedAPI.Report_GetHistory({
DeprecatedAPI.Report_GetHistory({
reportID,
reportActionsOffset,
reportActionsLimit: CONST.REPORT.ACTIONS.LIMIT,
Expand All @@ -644,15 +643,6 @@ function fetchActions(reportID) {
});
}

/**
* Get the initial actions of a report
*
* @param {Number} reportID
*/
function fetchInitialActions(reportID) {
fetchActions(reportID);
}

/**
* Get all of our reports
*
Expand Down Expand Up @@ -987,7 +977,7 @@ function deleteReportComment(reportID, reportAction) {
* @param {Number} reportID
*/
function openReport(reportID) {
API.read('OpenReport',
API.write('OpenReport',
{
reportID,
},
Expand Down Expand Up @@ -1026,7 +1016,7 @@ function openReport(reportID) {
* @param {Number} oldestActionSequenceNumber
*/
function readOldestAction(reportID, oldestActionSequenceNumber) {
API.write('ReadOldestAction',
API.read('ReadOldestAction',
{
reportID,
reportActionsOffset: oldestActionSequenceNumber,
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ class ReportScreen extends React.Component {
)
: (
<ReportActionsView
reportID={reportID}
reportActions={this.props.reportActions}
report={this.props.report}
session={this.props.session}
Expand Down
40 changes: 17 additions & 23 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ import EmojiPicker from '../../../components/EmojiPicker/EmojiPicker';
import * as ReportActionsUtils from '../../../libs/ReportActionsUtils';

const propTypes = {
/** The ID of the report actions will be created for */
reportID: PropTypes.number.isRequired,

/* Onyx Props */

/** The report currently being looked at */
report: PropTypes.shape({
/** The ID of the report actions will be created for */
reportID: PropTypes.number,
marcaaron marked this conversation as resolved.
Show resolved Hide resolved

/** Number of actions unread */
unreadActionCount: PropTypes.number,

Expand All @@ -52,7 +52,7 @@ const propTypes = {

/** Are we loading more report actions? */
isLoadingMoreReportActions: PropTypes.bool,
}),
}).isRequired,

/** Array of report actions for this report */
reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)),
Expand All @@ -75,12 +75,6 @@ const propTypes = {
};

const defaultProps = {
report: {
unreadActionCount: 0,
maxSequenceNumber: 0,
hasOutstandingIOU: false,
isLoadingMoreReportActions: false,
},
reportActions: {},
session: {},
};
Expand Down Expand Up @@ -118,23 +112,23 @@ class ReportActionsView extends React.Component {
return;
}

Report.openReport(this.props.reportID);
Report.openReport(this.props.report.reportID);
});

// If the reportID is not found then we have either not loaded this chat or the user is unable to access it.
// We will attempt to fetch it and redirect if still not accessible.
if (!this.props.report.reportID) {
Report.fetchChatReportsByIDs([this.props.reportID], true);
Report.fetchChatReportsByIDs([this.props.report.reportID], true);
}
Report.subscribeToReportTypingEvents(this.props.reportID);
Report.subscribeToReportTypingEvents(this.props.report.reportID);
this.keyboardEvent = Keyboard.addListener('keyboardDidShow', () => {
if (!ReportActionComposeFocusManager.isFocused()) {
return;
}
ReportScrollManager.scrollToBottom();
});

Report.openReport(this.props.reportID);
Report.openReport(this.props.report.reportID);
}

shouldComponentUpdate(nextProps, nextState) {
Expand Down Expand Up @@ -187,7 +181,7 @@ class ReportActionsView extends React.Component {
componentDidUpdate(prevProps) {
if (lodashGet(prevProps.network, 'isOffline') && !lodashGet(this.props.network, 'isOffline')) {
if (this.getIsReportFullyVisible()) {
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
Report.openReport(this.props.reportID);
Report.openReport(this.props.report.reportID);
} else {
this.fetchData();
}
Expand Down Expand Up @@ -223,14 +217,14 @@ class ReportActionsView extends React.Component {
// When the last action changes, record the max action
// This will make the NEW marker line go away if you receive comments in the same chat you're looking at
if (isReportFullyVisible) {
Report.readNewestAction(this.props.reportID);
Report.readNewestAction(this.props.report.reportID);
}
}

// Update the new marker position and last read action when we are closing the sidebar or moving from a small to large screen size
if (isReportFullyVisible && reportBecomeVisible) {
this.updateNewMarkerPosition(this.props.report.unreadActionCount);
Report.openReport(this.props.reportID);
Report.openReport(this.props.report.reportID);
}
}

Expand All @@ -243,7 +237,7 @@ class ReportActionsView extends React.Component {
this.appStateChangeListener.remove();
}

Report.unsubscribeFromReportChannel(this.props.reportID);
Report.unsubscribeFromReportChannel(this.props.report.reportID);
}

/**
Expand All @@ -255,7 +249,7 @@ class ReportActionsView extends React.Component {
}

fetchData() {
Report.fetchInitialActions(this.props.reportID);
Report.fetchInitialActions(this.props.report.reportID);
}

/**
Expand All @@ -280,13 +274,13 @@ class ReportActionsView extends React.Component {
// Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments, unless we're near the beginning, in which
// case just get everything starting from 0.
const oldestActionSequenceNumber = Math.max(minSequenceNumber - CONST.REPORT.ACTIONS.LIMIT, 0);
Report.readOldestAction(this.props.reportID, oldestActionSequenceNumber);
Report.readOldestAction(this.props.report.reportID, oldestActionSequenceNumber);
}

scrollToBottomAndMarkReportAsRead() {
ReportScrollManager.scrollToBottom();
Report.readNewestAction(this.props.reportID);
Report.setNewMarkerPosition(this.props.reportID, 0);
Report.readNewestAction(this.props.report.reportID);
Report.setNewMarkerPosition(this.props.report.reportID, 0);
}

/**
Expand All @@ -298,7 +292,7 @@ class ReportActionsView extends React.Component {
// We determine the last read action by deducting the number of unread actions from the total number.
// Then, we add 1 because we want the New marker displayed over the oldest unread sequence.
const oldestUnreadSequenceNumber = unreadActionCount === 0 ? 0 : this.props.report.lastReadSequenceNumber + 1;
Report.setNewMarkerPosition(this.props.reportID, oldestUnreadSequenceNumber);
Report.setNewMarkerPosition(this.props.report.reportID, oldestUnreadSequenceNumber);
}

/**
Expand Down