-
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
Kill currentlyViewedReportID
#11450
Kill currentlyViewedReportID
#11450
Changes from 2 commits
289c62b
51254b7
925cd48
d31836e
f311b23
7c3ed8a
dbb2e11
51f029e
9ba6616
dddb605
4cbffa5
5dac271
0f4f8df
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 |
---|---|---|
|
@@ -41,12 +41,7 @@ Onyx.connect({ | |
}, | ||
}); | ||
|
||
let lastViewedReportID; | ||
Onyx.connect({ | ||
key: ONYXKEYS.CURRENTLY_VIEWED_REPORTID, | ||
callback: val => lastViewedReportID = val ? Number(val) : null, | ||
}); | ||
|
||
let currentlyViewedReportID; | ||
const allReports = {}; | ||
let conciergeChatReportID; | ||
const typingWatchTimers = {}; | ||
|
@@ -957,7 +952,14 @@ function handleReportChanged(report) { | |
* @param {Number} reportID | ||
*/ | ||
function updateCurrentlyViewedReportID(reportID) { | ||
Onyx.merge(ONYXKEYS.CURRENTLY_VIEWED_REPORTID, String(reportID)); | ||
currentlyViewedReportID = String(reportID); | ||
} | ||
|
||
/** | ||
* @returns {String} | ||
*/ | ||
function getCurrentlyViewedReportID() { | ||
return currentlyViewedReportID; | ||
} | ||
|
||
Onyx.connect({ | ||
|
@@ -1275,7 +1277,7 @@ function addPolicyReport(policy, reportName, visibility) { | |
); | ||
|
||
// Onyx.set is used on the optimistic data so that it is present before navigating to the workspace room. With Onyx.merge the workspace room reportID is not present when | ||
// storeCurrentlyViewedReport is called on the ReportScreen, so fetchChatReportsByIDs is called which is unnecessary since the optimistic data will be stored in Onyx. | ||
// fetchReportIfNeeded is called on the ReportScreen, so fetchChatReportsByIDs is called which is unnecessary since the optimistic data will be stored in Onyx. | ||
// If there was an error creating the room, then fetchChatReportsByIDs throws an error and the user is navigated away from the report instead of showing the RBR error message. | ||
// Therefore, Onyx.set is used instead of Onyx.merge. | ||
const optimisticData = [ | ||
|
@@ -1447,7 +1449,7 @@ function viewNewReportAction(reportID, action) { | |
} | ||
|
||
// If we are currently viewing this report do not show a notification. | ||
if (reportID === lastViewedReportID && Visibility.isVisible()) { | ||
if (reportID === currentlyViewedReportID && Visibility.isVisible()) { | ||
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. Randomly noticed while working on this, but I think this code could be improved. We only check app "visibility" but the report could be blocked by the sidebar and the app itself might still be "visible". |
||
Log.info('[LOCAL_NOTIFICATION] No notification because it was a comment for the current report'); | ||
return; | ||
} | ||
|
@@ -1557,4 +1559,5 @@ export { | |
updatePolicyRoomName, | ||
clearPolicyRoomNameErrors, | ||
clearIOUError, | ||
getCurrentlyViewedReportID, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,15 +132,18 @@ class ReportScreen extends React.Component { | |
} | ||
|
||
componentDidMount() { | ||
this.storeCurrentlyViewedReport(); | ||
this.fetchReportIfNeeded(); | ||
toggleReportActionComposeView(true); | ||
this.removeViewportResizeListener = addViewportResizeListener(this.updateViewportOffsetTop); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (this.props.route.params.reportID === prevProps.route.params.reportID) { | ||
return; | ||
} | ||
this.storeCurrentlyViewedReport(); | ||
|
||
this.fetchReportIfNeeded(); | ||
toggleReportActionComposeView(true); | ||
} | ||
|
||
componentWillUnmount() { | ||
|
@@ -170,20 +173,13 @@ class ReportScreen extends React.Component { | |
return !getReportID(this.props.route) || isLoadingInitialReportActions || !this.props.report.reportID; | ||
} | ||
|
||
/** | ||
* Persists the currently viewed report id | ||
*/ | ||
storeCurrentlyViewedReport() { | ||
fetchReportIfNeeded() { | ||
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. Renamed as we are not storing the reportID anymore (didn't really like that we are resetting the hide composer thing in the same method anyway). 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. NAB: to me, the name should be |
||
const reportIDFromPath = getReportID(this.props.route); | ||
if (_.isNaN(reportIDFromPath)) { | ||
Report.handleInaccessibleReport(); | ||
return; | ||
} | ||
|
||
// Always reset the state of the composer view when the current reportID changes | ||
toggleReportActionComposeView(true); | ||
Report.updateCurrentlyViewedReportID(reportIDFromPath); | ||
|
||
// It possible that we may not have the report object yet in Onyx yet e.g. we navigated to a URL for an accessible report that | ||
// is not stored locally yet. If props.report.reportID exists, then the report has been stored locally and nothing more needs to be done. | ||
// If it doesn't exist, then we fetch the report from the API. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,7 @@ class BaseSidebarScreen extends Component { | |
onAvatarClick={this.navigateToSettings} | ||
isSmallScreenWidth={this.props.isSmallScreenWidth} | ||
isDrawerOpen={this.props.isDrawerOpen} | ||
currentlyViewedReportID={this.props.currentlyViewedReportID} | ||
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. Passing this here is enough to ensure the |
||
/> | ||
<FAB | ||
accessibilityLabel={this.props.translate('sidebarScreen.fabNewChat')} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ export default function () { | |
Onyx.init({ | ||
keys: ONYXKEYS, | ||
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], | ||
keysToDisableSyncEvents: [ONYXKEYS.CURRENTLY_VIEWED_REPORTID], | ||
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. Probably we don't need this feature in Onyx. I think we added it so that the reportID would stay "synced" but if we are using a local value instead of Onyx then we won't have this problem. 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. Great! Let's remove it |
||
captureMetrics: Metrics.canCaptureOnyxMetrics(), | ||
initialKeyStates: { | ||
|
||
|
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.
Since the SidebarLinks component now has access to the reportID directly from the route, I think I'd like to pass it as a parameter to
getOrderedReportIDs()
.That would only leave one reference to
Report.getCurrentlyViewedReportID()
(the one in User.js). I'm not sure if there is any other way for User.js to access that reportID :(I'm just thinking if there is a way to get rid of it entirely.
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.
Let me think about that for a bit. I had a version where we were passing that more explicitly and then switched to it being better to do 2 things consistently (but less ideal) than 1 right thing and 1 wrong thing.
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.
My solution here ended up being to pass the params + parse the reportID from the navigation state for the one case where we needed that (and weren't triggering an action from a component). Both cases are using the reportID from the route as the "source of truth" so solves it for me, but lmk if you agree.