-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Changes from 11 commits
713e1e0
de85a84
1c7bce4
8408423
7f11c94
b301b28
8260661
b654d97
5e37db3
2705f6e
2763fc4
9b1b0b6
3dc5dc6
c87a3e6
18d11f3
11cddbc
a298893
7468ac5
630f75c
d9909a2
df12dbd
a689a90
10b86ee
bc124fc
bca0f8b
39fd1ec
0be9f97
852e636
599ca8b
2d7de46
8954f03
8ebc4f7
d2695b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1049,21 +1049,35 @@ function deleteReportComment(reportID, reportAction) { | |
* @param {Number} reportID | ||
*/ | ||
function openReport(reportID) { | ||
const sequenceNumber = getMaxSequenceNumber(reportID); | ||
API.write('OpenReport', | ||
API.read('OpenReport', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are right it should be a write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make this a |
||
{ | ||
reportID, | ||
sequenceNumber, | ||
}, | ||
{ | ||
optimisticData: [{ | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
value: { | ||
lastReadSequenceNumber: sequenceNumber, | ||
lastVisitedTimestamp: Date.now(), | ||
unreadActionCount: 0, | ||
optimisticData: [ | ||
{ | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.IS_LOADING_REPORT_ACTIONS}${reportID}`, | ||
value: true, | ||
}, | ||
{ | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
value: { | ||
lastVisitedTimestamp: Date.now(), | ||
unreadActionCount: 0, | ||
}, | ||
}, | ||
], | ||
successData: [{ | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.IS_LOADING_REPORT_ACTIONS}${reportID}`, | ||
value: false, | ||
}], | ||
failureData: [{ | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.IS_LOADING_REPORT_ACTIONS}${reportID}`, | ||
value: false, | ||
}], | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,8 +66,8 @@ const propTypes = { | |
/** Beta features list */ | ||
betas: PropTypes.arrayOf(PropTypes.string), | ||
|
||
/** Flag to check if the initial report actions data are loading */ | ||
isLoadingInitialReportActions: PropTypes.bool, | ||
/** Flag to check if the report actions data are loading */ | ||
isLoadingReportActions: PropTypes.bool, | ||
|
||
/** The policies which the user has access to */ | ||
policies: PropTypes.objectOf(PropTypes.shape({ | ||
|
@@ -92,7 +92,7 @@ const defaultProps = { | |
}, | ||
isComposerFullSize: false, | ||
betas: [], | ||
isLoadingInitialReportActions: false, | ||
isLoadingReportActions: false, | ||
}; | ||
|
||
/** | ||
|
@@ -136,10 +136,10 @@ class ReportScreen extends React.Component { | |
} | ||
|
||
componentWillUnmount() { | ||
clearTimeout(this.loadingTimerId); | ||
marcaaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (window.visualViewport) { | ||
window.visualViewport.removeEventListener('resize', this.viewportOffsetTop); | ||
if (!window.visualViewport) { | ||
return; | ||
} | ||
window.visualViewport.removeEventListener('resize', this.viewportOffsetTop); | ||
} | ||
marcaaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
|
@@ -163,7 +163,8 @@ class ReportScreen extends React.Component { | |
* @returns {Boolean} | ||
*/ | ||
shouldShowLoader() { | ||
return !getReportID(this.props.route) || (_.isEmpty(this.props.reportActions) && this.props.isLoadingInitialReportActions); | ||
const isLoadingInitialReportActions = _.isEmpty(this.props.reportActions) && this.props.isLoadingReportActions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marc suggested this and I agreed, this makes it easier to understand the purpose of the check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please update the method description in the JSDocs to be more clear? It is answering "what", but not "why" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this really be more like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "initial" means you have no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you happy with that @tgolen or do you want me to rename the var? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really like Marc's explanation. Could you add that as a code comment to help explain it to others who will see this? If the comment is added, then I think the name is OK then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a shorter version of Marcs answer, that I feel makes more sense to read, let me know if that works. |
||
return !getReportID(this.props.route) || isLoadingInitialReportActions; | ||
} | ||
|
||
/** | ||
|
@@ -285,8 +286,8 @@ export default withOnyx({ | |
betas: { | ||
key: ONYXKEYS.BETAS, | ||
}, | ||
isLoadingInitialReportActions: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.IS_LOADING_INITIAL_REPORT_ACTIONS}${getReportID(route)}`, | ||
isLoadingReportActions: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.IS_LOADING_REPORT_ACTIONS}${getReportID(route)}`, | ||
initWithStoredValues: false, | ||
marcaaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
policies: { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -68,9 +68,6 @@ const propTypes = { | |||||||||
/** Are we loading more report actions? */ | ||||||||||
isLoadingMoreReportActions: PropTypes.bool, | ||||||||||
|
||||||||||
/** Are we waiting for more report data? */ | ||||||||||
isLoadingReportData: PropTypes.bool, | ||||||||||
|
||||||||||
/** Information about the network */ | ||||||||||
network: networkPropTypes.isRequired, | ||||||||||
|
||||||||||
|
@@ -88,7 +85,6 @@ const defaultProps = { | |||||||||
reportActions: {}, | ||||||||||
session: {}, | ||||||||||
isLoadingMoreReportActions: false, | ||||||||||
isLoadingReportData: false, | ||||||||||
}; | ||||||||||
|
||||||||||
class ReportActionsView extends React.Component { | ||||||||||
|
@@ -116,7 +112,6 @@ class ReportActionsView extends React.Component { | |||||||||
this.loadMoreChats = this.loadMoreChats.bind(this); | ||||||||||
this.recordTimeToMeasureItemLayout = this.recordTimeToMeasureItemLayout.bind(this); | ||||||||||
this.scrollToBottomAndMarkReportAsRead = this.scrollToBottomAndMarkReportAsRead.bind(this); | ||||||||||
this.updateNewMarkerAndMarkReadOnce = _.once(this.updateNewMarkerAndMarkRead.bind(this)); | ||||||||||
} | ||||||||||
|
||||||||||
componentDidMount() { | ||||||||||
|
@@ -141,11 +136,7 @@ class ReportActionsView extends React.Component { | |||||||||
ReportScrollManager.scrollToBottom(); | ||||||||||
}); | ||||||||||
|
||||||||||
if (!this.props.isLoadingReportData) { | ||||||||||
this.updateNewMarkerAndMarkReadOnce(); | ||||||||||
} | ||||||||||
|
||||||||||
this.fetchData(); | ||||||||||
Report.openReport(this.props.reportID); | ||||||||||
sketchydroide marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
} | ||||||||||
|
||||||||||
shouldComponentUpdate(nextProps, nextState) { | ||||||||||
|
@@ -168,10 +159,6 @@ class ReportActionsView extends React.Component { | |||||||||
return true; | ||||||||||
} | ||||||||||
|
||||||||||
if (!nextProps.isLoadingReportData && this.props.isLoadingReportData) { | ||||||||||
return true; | ||||||||||
} | ||||||||||
|
||||||||||
if (nextState.isFloatingMessageCounterVisible !== this.state.isFloatingMessageCounterVisible) { | ||||||||||
return true; | ||||||||||
} | ||||||||||
|
@@ -203,14 +190,9 @@ class ReportActionsView extends React.Component { | |||||||||
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); | ||||||||||
} else { | ||||||||||
this.fetchData(); | ||||||||||
} | ||||||||||
this.fetchData(); | ||||||||||
} | ||||||||||
|
||||||||||
// Update the last read action for the report currently in view when report data finishes loading. | ||||||||||
// This report should now be up-to-date and since it is in view we mark it as read. | ||||||||||
if (!this.props.isLoadingReportData && prevProps.isLoadingReportData) { | ||||||||||
this.updateNewMarkerAndMarkReadOnce(); | ||||||||||
} | ||||||||||
|
||||||||||
// The last sequenceNumber of the same report has changed. | ||||||||||
|
@@ -350,18 +332,6 @@ class ReportActionsView extends React.Component { | |||||||||
}); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Update NEW marker and mark report as read | ||||||||||
*/ | ||||||||||
updateNewMarkerAndMarkRead() { | ||||||||||
this.updateNewMarkerPosition(this.props.report.unreadActionCount); | ||||||||||
|
||||||||||
// Only mark as read if the report is fully visible | ||||||||||
if (this.getIsReportFullyVisible()) { | ||||||||||
Report.openReport(this.props.reportID); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Show the new floating message counter | ||||||||||
*/ | ||||||||||
|
@@ -454,9 +424,6 @@ export default compose( | |||||||||
withLocalize, | ||||||||||
withNetwork(), | ||||||||||
withOnyx({ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does the component get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from the parent component here: App/src/pages/home/ReportScreen.js Lines 242 to 245 in 972b835
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, Thanks! I don't think we should pass both the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can do that, but reportID at the moment is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds like an easy change and a good thing to look into. I also think it would be OK to do in a follow up and not add additional refactoring scope to these changes. I don't immediately see a clear reason for passing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should make I won't fight tooth-and-nail about it being done in this PR, but I also think this is a refactor PR and I am not too concerned about scope for something small like this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just made the change and tested it after, seems to work great, let me know if you are happy with that @tgolen |
||||||||||
isLoadingReportData: { | ||||||||||
key: ONYXKEYS.IS_LOADING_REPORT_DATA, | ||||||||||
}, | ||||||||||
isLoadingMoreReportActions: { | ||||||||||
key: ({reportID}) => `${ONYXKEYS.COLLECTION.IS_LOADING_MORE_REPORT_ACTIONS}${reportID}`, | ||||||||||
initWithStoredValues: false, | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between this collection, the one above it, and the one below it? This feels like it's getting a little bit out of hand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using collections for these things at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the
IS_LOADING_INITIAL_REPORT_ACTIONS
one. It seems like nothing is subscribing to this key. So that just leaves the others...But I think we are using collections because:
Any specific concern with this approach?
Thinking on what we should we do as an alternative... One idea is to possibly use the
report
object to store aisLoadingActions
andisLoadingMoreActions
. The report object is a little bloated already with all sorts of random stuff, but maybe it's better than what we have here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is basically what I would propose otherwise. It sounds like that's the best practice considering pattern B.
My concern is that I think this leads to an anti-pattern. It becomes a bunch of keys holding a single boolean value, when the boolean value could be a property on the normal report collection. If a new engineer looks at this, and sees it's OK, then what are the next collections with single values? Collections for just report names? You can use this argument to say that instead of one collection with
n
reports, then it's OK to haven
collections forn
reports (one collection for each report property).Unless there is a real advantage to having these kinds of simple value collections (I am just not seeing it), I think we should avoid it and stick to our best practices. (not trying to blame anyone!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wanna move this to Slack to discuss? After, we can put it down in the style guide / fix anything that is not following the best practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove the
isLoadingInitialReportActions_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok seems like we had a good discussion here and are adding this to the style guide.
So, @sketchydroide we just need to update these so that the boolean properties are on the report instead of collection keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have done this for the
isLoadingReportActions
Should I do it for the IS_LOADING_MORE_REPORT_ACTIONS as well in this PR as well, it's from the previous PR for
ReadOldestAction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% I did that correctly, but I think so, did I miss something? it feels odd that
isLoadingReportActions
is not always defined...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks correct to me.
This is JavaScript which means 99% of all things are possibly
undefined
, but hey at least it's a boolean!