-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Use initialValue in withOnyx and other optimizations for ReportScreen #26772
Merged
mountiny
merged 48 commits into
Expensify:main
from
margelo:osp/further-report-screen-optimizations
Sep 28, 2023
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
3be5e69
Separate ReportScreenContext to prevent cyclic re-renders
ospfranco 6125c38
Get rid of full list re-render when marking messages as unread
ospfranco be7ea56
Linting
ospfranco caed994
Merge branch 'main' into osp/ReportScreen-optimizations
ospfranco 37926ee
Merge branch 'main' into osp/ReportScreen-optimizations
ospfranco 90c9119
create new onyx metadata collection and connect components
ospfranco 9829fd8
Clean code on ReportScreen main body
ospfranco bbeb353
Merge branch 'main' into osp/report-metadata
ospfranco 426c3cb
Do not use context on SidebarLinks
ospfranco 9fd2f94
Eagerly initialize date-fns locale
ospfranco b3b33eb
Update src/pages/home/ReportScreen.js
ospfranco 40d48bb
Update src/pages/home/report/ReportActionsList.js
ospfranco 14808d9
Remove requestIdleCallback as it might not be available everywhere
ospfranco 4f75359
Merge branch 'main' into osp/report-metadata
ospfranco 6effb37
Fix wrong variable name
ospfranco 3619a25
Report screen performance improvements
ospfranco eb44749
Prevent SidebarLinks from re-rendering on opening report
ospfranco a77072a
Change delayUpdates prop on ReportScreen to new shouldDelayUpdates
ospfranco 76fafe0
Merge branch 'main' into osp/further-report-screen-optimizations
ospfranco 5d3f53b
Merge branch 'main' into osp/report-metadata
ospfranco cfa7db6
Merge branch 'main' into osp/report-metadata
ospfranco ceda644
Remove options object from ReportScreen withOnyx, replace with should…
ospfranco 12c8fa9
Get rid of unused currentReportId prop
ospfranco d761db0
Merge branch 'main' into osp/report-metadata
ospfranco ffaf7a8
Remove containerHeight from ReportActionsSkeletonView because onLayou…
ospfranco 3df387b
Lint
ospfranco 8d5031b
Merge branch 'main' into osp/report-metadata
ospfranco 063d658
Removed skeleton height calculation
ospfranco f74d674
Merge branch 'main' into osp/report-metadata
ospfranco f6b382c
Merge branch 'osp/report-metadata' into osp/further-report-screen-opt…
ospfranco 42d54fa
Merge branch 'main' into osp/further-report-screen-optimizations
ospfranco 6985019
Merge branch 'main' into osp/further-report-screen-optimizations
ospfranco 035874c
Fix botched merge
ospfranco 5628d27
Merge branch 'main' into osp/further-report-screen-optimizations
ospfranco 492f847
Change onListLayout from actions to container
ospfranco dd43fd0
Add check before calling onLayout on ReportActionsView
ospfranco 9eddbea
Completely remove onLayout prop from ReportActionsView
ospfranco 66670d5
PR comments
ospfranco 8f27192
Merge branch 'main' into osp/further-report-screen-optimizations
ospfranco 4ea2342
Merge branch 'main' into osp/further-report-screen-optimizations
ospfranco 4c2abca
Merge branch 'main' into osp/further-report-screen-optimizations
ospfranco 6ecee83
Fix memo on ReportActionItem to re-render when a task is canceled
ospfranco e3fd39e
Replace withNetwork HOC with useNetwork hook
ospfranco 3825371
Revert firstRenderRef calculation of isLoading flag
ospfranco 24710b7
Move firstRenderRef from isLoading to shouldShowNotFoundPage
ospfranco ee7f4c7
Merge branch 'main' into osp/further-report-screen-optimizations
ospfranco f006f1d
PR Comments
ospfranco 3aaef2f
Merge branch 'main' into osp/further-report-screen-optimizations
ospfranco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/libs/Navigation/AppNavigator/ReportScreenIDSetter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import {useEffect} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import lodashGet from 'lodash/get'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import ONYXKEYS from '../../../ONYXKEYS'; | ||
import * as ReportUtils from '../../ReportUtils'; | ||
import reportPropTypes from '../../../pages/reportPropTypes'; | ||
import {withNavigationPropTypes} from '../../../components/withNavigation'; | ||
import * as App from '../../actions/App'; | ||
import usePermissions from '../../../hooks/usePermissions'; | ||
import CONST from '../../../CONST'; | ||
import Navigation from '../Navigation'; | ||
|
||
const propTypes = { | ||
/** Available reports that would be displayed in this navigator */ | ||
reports: PropTypes.objectOf(reportPropTypes), | ||
|
||
/** The policies which the user has access to */ | ||
policies: PropTypes.objectOf( | ||
PropTypes.shape({ | ||
/** The policy name */ | ||
name: PropTypes.string, | ||
|
||
/** The type of the policy */ | ||
type: PropTypes.string, | ||
}), | ||
), | ||
|
||
isFirstTimeNewExpensifyUser: PropTypes.bool, | ||
|
||
/** Navigation route context info provided by react navigation */ | ||
route: PropTypes.shape({ | ||
/** Route specific parameters used on this screen */ | ||
params: PropTypes.shape({ | ||
/** If the admin room should be opened */ | ||
openOnAdminRoom: PropTypes.bool, | ||
|
||
/** The ID of the report this screen should display */ | ||
reportID: PropTypes.string, | ||
}), | ||
}).isRequired, | ||
|
||
...withNavigationPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
reports: {}, | ||
policies: {}, | ||
isFirstTimeNewExpensifyUser: false, | ||
}; | ||
|
||
/** | ||
* Get the most recently accessed report for the user | ||
* | ||
* @param {Object} reports | ||
* @param {Boolean} ignoreDefaultRooms | ||
* @param {Object} policies | ||
* @param {Boolean} isFirstTimeNewExpensifyUser | ||
* @param {Boolean} openOnAdminRoom | ||
* @returns {Number} | ||
*/ | ||
const getLastAccessedReportID = (reports, ignoreDefaultRooms, policies, isFirstTimeNewExpensifyUser, openOnAdminRoom) => { | ||
// If deeplink url is of an attachment, we should show the report that the attachment comes from. | ||
const currentRoute = Navigation.getActiveRoute(); | ||
const matches = CONST.REGEX.ATTACHMENT_ROUTE.exec(currentRoute); | ||
const reportID = lodashGet(matches, 1, null); | ||
if (reportID) { | ||
return reportID; | ||
} | ||
|
||
const lastReport = ReportUtils.findLastAccessedReport(reports, ignoreDefaultRooms, policies, isFirstTimeNewExpensifyUser, openOnAdminRoom); | ||
|
||
return lodashGet(lastReport, 'reportID'); | ||
}; | ||
|
||
// This wrapper is reponsible for opening the last accessed report if there is no reportID specified in the route params | ||
function ReportScreenIDSetter({route, reports, policies, isFirstTimeNewExpensifyUser, navigation}) { | ||
const {canUseDefaultRooms} = usePermissions(); | ||
|
||
useEffect(() => { | ||
// Don't update if there is a reportID in the params already | ||
if (lodashGet(route, 'params.reportID', null)) { | ||
App.confirmReadyToOpenApp(); | ||
return; | ||
} | ||
|
||
// If there is no reportID in route, try to find last accessed and use it for setParams | ||
const reportID = getLastAccessedReportID(reports, !canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, lodashGet(route, 'params.openOnAdminRoom', false)); | ||
|
||
// It's possible that reports aren't fully loaded yet | ||
// in that case the reportID is undefined | ||
if (reportID) { | ||
navigation.setParams({reportID: String(reportID)}); | ||
} else { | ||
App.confirmReadyToOpenApp(); | ||
} | ||
}, [route, navigation, reports, canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser]); | ||
|
||
// The ReportScreen without the reportID set will display a skeleton | ||
// until the reportID is loaded and set in the route param | ||
return null; | ||
} | ||
|
||
ReportScreenIDSetter.propTypes = propTypes; | ||
ReportScreenIDSetter.defaultProps = defaultProps; | ||
ReportScreenIDSetter.displayName = 'ReportScreenIDSetter'; | ||
|
||
export default withOnyx({ | ||
reports: { | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
allowStaleData: true, | ||
}, | ||
policies: { | ||
key: ONYXKEYS.COLLECTION.POLICY, | ||
allowStaleData: true, | ||
}, | ||
isFirstTimeNewExpensifyUser: { | ||
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, | ||
initialValue: false, | ||
}, | ||
})(ReportScreenIDSetter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Request: can we please add a comment to explain what belongs in
report_
and what belongs inreportMetadata_
. Without all the context the distinction isn't very clear.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.
For now we've separated the loading states
isLoadingReportActions
andisLoadingMoreReportActions
intoreportMetadata_
, as they were causing many re-renders on smaller components every time the report actions were being fetched. It makes sense to add it a comment for future reference.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.
Thanks, sounds good. Maybe the distinction is that REPORT_METADATA is for client-generated data?
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 a performance optimization, not a hard cut between functionality/logic.