-
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
Improve the readability and maintainability of the code which groups and sorts the reports in the sidebar #12558
Conversation
src/libs/SidebarUtils.js
Outdated
// 5. Archived reports | ||
// - Sorted by lastMessageTimestamp in default (most recent) view mode | ||
// - Sorted by reportDisplayName in GSD (focus) view mode | ||
const reportGroups = _.groupBy(reportsToDisplay, (report) => { |
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.
Grouping these into an object keyed with these strings is less clear than something like setting up a bunch of empty arrays:
const pinnedReports = [];
const outstandingIOUReports = [];
I forgot what groupBy
does, wasn't really sure what was happening here and had to look it up.
Could we just set up the arrays, then sort them, then concat them?
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.
Yes, that is a good idea and hopefully it will be more clear that way. I've update the PR for that.
src/libs/ReportUtils.js
Outdated
return iouReport.ownerEmail === currentUserLogin; | ||
} | ||
} | ||
return null; |
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.
Could we return false
here and keep the type consistent?
src/libs/ReportUtils.js
Outdated
* @param {Object} report | ||
* @param {String} report.iouReportID | ||
* @param {Object} iouReports | ||
* @returns {null|Number} |
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.
Same here.
src/libs/ReportUtils.js
Outdated
* @param {Object} iouReports | ||
* @returns {null|Boolean} | ||
*/ | ||
function isIOUOwnedByCurrentUser(report, currentUserLogin, iouReports) { |
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 but we can lose the iouReports &&
if we default to an object like this
function isIOUOwnedByCurrentUser(report, currentUserLogin, iouReports) { | |
function isIOUOwnedByCurrentUser(report, currentUserLogin, iouReports = {}) { |
src/libs/ReportUtils.js
Outdated
*/ | ||
function isIOUOwnedByCurrentUser(report, currentUserLogin, iouReports) { | ||
if (report.hasOutstandingIOU) { | ||
const iouReport = (iouReports && iouReports[`${ONYXKEYS.COLLECTION.REPORT_IOUS}${report.iouReportID}`]) || null; |
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, short circuit to null
would also be unnecessary with the default argument as undefined
is falsy.
Updated! |
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.
Much cleaner! @eVoloshchak - Can you test and review?
Reviewer Checklist
Screenshots/Videos |
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.
It's much better in terms of readability, cool!
Works well
Looks like we are all good here and everything is approved, so I'll merge it. |
@tgolen looks like this was merged without the checklist test passing. Please add a note explaining why this was done and remove the |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
Hm, they were definitely all passing when I clicked the button |
🚀 Deployed to production by @luacmartins in version: 1.2.30-0 🚀
|
This uncovered a few other bugs:
Fixed Issues
$ https://github.com/Expensify/Expensify/issues/229617
Tests
QA Steps
Same as the test steps above
PR Author Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
filesWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
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 reviewer 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/*
filesWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
have been tested & I retested again)/** comment above it */
this
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)Screenshots/Videos
Web
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android