-
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
Conversation
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Let's remove it
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Passing this here is enough to ensure the SidebarLinks
update with the currentlyViewedReportID
(and recalculate the options). That might not be obvious though so going to add a comment I think.
* Persists the currently viewed report id | ||
*/ | ||
storeCurrentlyViewedReport() { | ||
fetchReportIfNeeded() { |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
NAB: to me, the name should be fetchReport
because the IfNeeded
part is an implementation detail of the method which the outside world doesn't need to know about.
src/libs/actions/Report.js
Outdated
@@ -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 comment
The 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".
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 love seeing this cleaned up!
src/libs/SidebarUtils.js
Outdated
@@ -136,7 +131,7 @@ function getOrderedReportIDs() { | |||
|
|||
const shouldFilterReportIfRead = hideReadReports && !ReportUtils.isUnread(report); | |||
const shouldFilterReport = shouldFilterReportIfEmpty || shouldFilterReportIfRead; | |||
if (report.reportID.toString() !== currentlyViewedReportID | |||
if (report.reportID.toString() !== Report.getCurrentlyViewedReportID() |
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.
@@ -237,7 +230,7 @@ function validateLogin(accountID, validateCode) { | |||
} | |||
}).finally(() => { | |||
Onyx.merge(ONYXKEYS.ACCOUNT, {isLoading: false}); | |||
Navigation.navigate(redirectRoute); | |||
Navigation.navigate(ROUTES.HOME); |
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 decided to just change the behavior here as I think it makes more sense this way. If you navigate to the HOME
route it will open the drawer (which is where you would have been before validating a login via the settings page - which I presume is the isLoggedIn
version of this).
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 love those changes. This looks great now!
const drawerState = lodashGet(navigationRef.current.getState(), ['routes', 0, 'state']); | ||
const reportRoute = lodashGet(drawerState, ['routes', 0]); | ||
return lodashGet(reportRoute, ['params', 'reportID'], ''); |
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.
NAB: I'm guessing you did this for ultra clarity, but I think it's best to just do a single lodashGet
.
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.
Yep that's the reason. I think it's important for people to think about where these values are coming from. Especially if we have to change up something about the navigators at some point in the future. We could use a code comment to do the same I suppose. I'm finding myself more in the camp of using variables to explain stuff vs having long winded explanations. Not sure if one approach is better than the other or if it's something we should standardize.
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.
That's fair. I think I'm coming from mostly recently discovering that lodashGet
isn't very performant, so I think we should be careful with where we use it. I'm not entirely sure how often this code is triggered to understand if it's a performance concern, but you might know that better than me.
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 too concerned as this will only be triggered when someone sends you a new comment. That said, I can't guarantee how someone will decide to use it in the future.
Anyways, feels like the lodashGet
performance issue would be a good thing to bring up somewhere since the prevailing advice feels like it's becoming:
use lodash.get everywhere for consistency... except where it's not performant to do so
The argument for consistency is weakened by this new exception to the rule. I'm a bit concerned that people will start picking up a "lodash bad" mentality without really thinking too hard about why it should or should not be used.
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.
Haha, that's fair. Though, I think the opposite is equally bad (ie. lodash get everywhere!) as I've seen it misused way too many times to count. Regardless, I think your use of it here is fine as-is.
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.
Code LGTM, just one question.
Seems like we are ready to merge this, but need a reviewer to go through the checklist. |
Here goes
|
@marcaaron While I start working on that, the PR is missing screenshots/videos for the platforms |
@marcaaron I started testing on web, and the first set of tests work fine. However, when I attempt the second set of tests and get to point |
Thanks @tgolen I'll update with some screens in a bit and try to reproduce what you are seeing. |
Just to clarify - are you thinking that all PRs should have videos and screenshots or would a screenshot suffice? Unrelated to this PR I think this is a good thing to have everyone standardize on. |
@tgolen I was able to reproduce it and there's definitely an issue 😄 The diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js
index 09e8c5f01..458f086c6 100644
--- a/src/libs/actions/Report.js
+++ b/src/libs/actions/Report.js
@@ -1421,8 +1421,11 @@ function viewNewReportAction(reportID, action) {
// If we are currently viewing this report do not show a notification.
if (reportID === Navigation.getReportIDFromRoute() && Visibility.isVisible()) {
+ console.log('@marcaaron NOT SHOWING NOTIFICATION ', {reportID, reportIDInRoute: Navigation.getReportIDFromRoute(), isVisible: Visibility.isVisible()});
Log.info('[LOCAL_NOTIFICATION] No notification because it was a comment for the current report');
return;
+ } else {
+ console.log('@marcaaron SHOWING NOTIFICATION ', {reportID, reportIDInRoute: Navigation.getReportIDFromRoute(), isVisible: Visibility.isVisible()});
} |
@tgolen's recent changes made some rough conflicts for me so I will update you guys when this PR is ready again. |
Ok I think this is ready now for another review. |
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'll start testing now
src/libs/actions/Report.js
Outdated
@@ -1500,7 +1487,7 @@ Onyx.connect({ | |||
return; | |||
} | |||
|
|||
viewNewReportAction(reportID, action); | |||
viewNewReportAction(reportID.toString(), action); |
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 saw this, and immediately thought... why isn't this a string already? I see that it's being parsed as an integer from the onyx key up above. I think a better solution then is to stop parsing it as an integer in the first place. Does that work?
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.
Ah nice catch! yep sure that will work.
* Persists the currently viewed report id | ||
*/ | ||
storeCurrentlyViewedReport() { | ||
fetchReportIfNeeded() { |
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.
NAB: to me, the name should be fetchReport
because the IfNeeded
part is an implementation detail of the method which the outside world doesn't need to know about.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Let's remove it
tests/unit/LHNFilterTest.js
Outdated
@@ -306,15 +305,14 @@ describe('Sidebar', () => { | |||
...LHNTestUtils.getAdvancedFakeReport(...boolArr), | |||
policyID: policy.policyID, | |||
}; | |||
const sidebarLinks = LHNTestUtils.getDefaultRenderedSidebarLinks(); | |||
const sidebarLinks = LHNTestUtils.getDefaultRenderedSidebarLinks(report1.reportID.toString()); |
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.
Similar thinking here, but why isn't the reportID
a string in the first place? getFakeReport()
should return it as a string (maybe you're just copying what was there before and I missed these on another PR).
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 you're right that we don't need the cast. But I assumed here that the toString()
was necessary since it's already in the test here:
App/tests/unit/LHNFilterTest.js
Line 317 in 23ab716
[ONYXKEYS.CURRENTLY_VIEWED_REPORTID]: report1.reportID.toString(), |
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.
maybe you're just copying what was there before and I missed these on another PR
yep this
Sorry, I got pulled into a fire this morning and still haven't been able to test this out on anything but web. I'll get to it this afternoon hopefully |
Thanks for the extra notes @tgolen. Updated this one 🙇 |
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.
Great, thanks! I completed my testing and it all looks good 👍
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.
LGTM as well :)
@marcaaron looks like this was merged without passing tests. Please add a note explaining why this was done and remove the |
Checklist is checked. Unsure why failing. |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by @marcaaron in version: 1.2.12-0 🚀
|
🚀 Deployed to production by @AndrewGable in version: 1.2.12-4 🚀
|
…rentlyViewedReportID Kill `currentlyViewedReportID`
Details
cc @tgolen
currentlyViewedReportID
by parsing it out of the current route in theReportScreen
and saving it in OnyxSidebarLinks
which is kind of backwards since we are able to set the "current reportID" higher up the chain and avoid the re-rendercurrentlyViewedReportID
locally (no need to use Onyx for this)Also cleaned up some cases where we are using an HOC to pass the
navigation
object down to the SidebarScreen, but this is not necessary as it exists in the drawer props.Fixed Issues
$ https://github.com/Expensify/Expensify/issues/230467
Tests
Web & Desktop
Mobile Web / Android App / iOS App
There are no local notifications for these platforms so we will do a simpler test here:
PR Review Checklist
Contributor (PR Author) Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
filesSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)PR Reviewer Checklist
The Contributor+ will copy/paste it into a new comment and complete it after the author checklist is completed
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
).src/languages/*
filesSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
have been tested & I retested again)/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)QA Steps
Screenshots
Web
2022-10-04_08-50-21.mp4
Mobile Web - Chrome
2022-10-04_10-15-57.mp4
Mobile Web - Safari
2022-10-04_10-22-22.mp4
Desktop
2022-10-04_10-02-13.mp4
iOS
2022-10-04_10-33-06.mp4
Android
2022-10-04_11-05-17.mp4