diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 996c97e18269..3074672df706 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1897,14 +1897,14 @@ function canSeeDefaultRoom(report, policies, betas) { * filter out the majority of reports before filtering out very specific minority of reports. * * @param {Object} report - * @param {String} reportIDFromRoute + * @param {String} currentReportId * @param {Boolean} isInGSDMode * @param {Object} iouReports * @param {String[]} betas * @param {Object} policies * @returns {boolean} */ -function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, iouReports, betas, policies) { +function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouReports, betas, policies) { const isInDefaultMode = !isInGSDMode; // Exclude reports that have no data because there wouldn't be anything to show in the option item. @@ -1925,7 +1925,7 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, iouR // Include the currently viewed report. If we excluded the currently viewed report, then there // would be no way to highlight it in the options list and it would be confusing to users because they lose // a sense of context. - if (report.reportID === reportIDFromRoute) { + if (report.reportID === currentReportId) { return true; } diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index a41249ebfa3d..10ed2669f096 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -117,15 +117,15 @@ function setIsSidebarLoadedReady() { } /** - * @param {String} reportIDFromRoute + * @param {String} currentReportId * @returns {String[]} An array of reportIDs sorted in the proper order */ -function getOrderedReportIDs(reportIDFromRoute) { +function getOrderedReportIDs(currentReportId) { const isInGSDMode = priorityMode === CONST.PRIORITY_MODE.GSD; const isInDefaultMode = !isInGSDMode; // Filter out all the reports that shouldn't be displayed - const reportsToDisplay = _.filter(allReports, (report) => ReportUtils.shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, allReports, betas, policies)); + const reportsToDisplay = _.filter(allReports, (report) => ReportUtils.shouldReportBeInOptionList(report, currentReportId, isInGSDMode, allReports, betas, policies)); if (_.isEmpty(reportsToDisplay)) { // Display Concierge chat report when there is no report to be displayed const conciergeChatReport = _.find(allReports, ReportUtils.isConciergeChatReport); diff --git a/src/pages/home/sidebar/SidebarLinks.js b/src/pages/home/sidebar/SidebarLinks.js index fdd2567c2c90..5d2e3ea9ea47 100644 --- a/src/pages/home/sidebar/SidebarLinks.js +++ b/src/pages/home/sidebar/SidebarLinks.js @@ -74,9 +74,6 @@ const propTypes = { accountID: PropTypes.number, }), - /** Current reportID from the route in react navigation state object */ - reportIDFromRoute: PropTypes.string, - /** Whether we are viewing below the responsive breakpoint */ isSmallScreenWidth: PropTypes.bool.isRequired, @@ -95,7 +92,6 @@ const defaultProps = { currentUserPersonalDetails: { avatar: '', }, - reportIDFromRoute: '', priorityMode: CONST.PRIORITY_MODE.DEFAULT, }; @@ -157,7 +153,7 @@ class SidebarLinks extends React.Component { render() { const isLoading = _.isEmpty(this.props.personalDetails) || _.isEmpty(this.props.chatReports); - const optionListItems = SidebarUtils.getOrderedReportIDs(this.props.reportIDFromRoute); + const optionListItems = SidebarUtils.getOrderedReportIDs(this.props.currentReportId); const skeletonPlaceholder = ; diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js index 462e0d88906f..18622166d4bf 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js @@ -59,7 +59,6 @@ class BaseSidebarScreen extends Component { insets={insets} onAvatarClick={this.navigateToSettings} isSmallScreenWidth={this.props.isSmallScreenWidth} - reportIDFromRoute={this.props.reportIDFromRoute} onLayout={this.props.onLayout} /> diff --git a/src/pages/home/sidebar/SidebarScreen/sidebarPropTypes.js b/src/pages/home/sidebar/SidebarScreen/sidebarPropTypes.js index df2d90f2fb64..5269765dc753 100644 --- a/src/pages/home/sidebar/SidebarScreen/sidebarPropTypes.js +++ b/src/pages/home/sidebar/SidebarScreen/sidebarPropTypes.js @@ -2,9 +2,6 @@ import PropTypes from 'prop-types'; import {windowDimensionsPropTypes} from '../../../../components/withWindowDimensions'; const sidebarPropTypes = { - /** reportID in the current navigation state */ - reportIDFromRoute: PropTypes.string, - /** Callback when onLayout of sidebar is called */ onLayout: PropTypes.func, ...windowDimensionsPropTypes, diff --git a/tests/unit/SidebarOrderTest.js b/tests/unit/SidebarOrderTest.js index 3c3863c411b2..16cbd1c40698 100644 --- a/tests/unit/SidebarOrderTest.js +++ b/tests/unit/SidebarOrderTest.js @@ -145,8 +145,8 @@ describe('Sidebar', () => { }; const report2 = LHNTestUtils.getFakeReport([3, 4], 2); const report3 = LHNTestUtils.getFakeReport([5, 6], 1); - const reportIDFromRoute = report1.reportID; - LHNTestUtils.getDefaultRenderedSidebarLinks(reportIDFromRoute); + const currentReportId = report1.reportID; + LHNTestUtils.getDefaultRenderedSidebarLinks(currentReportId); return ( waitForPromisesToResolve() // When Onyx is updated with the data and the sidebar re-renders @@ -227,8 +227,8 @@ describe('Sidebar', () => { hasDraft: true, }; const report3 = LHNTestUtils.getFakeReport([5, 6], 1); - const reportIDFromRoute = report2.reportID; - LHNTestUtils.getDefaultRenderedSidebarLinks(reportIDFromRoute); + const currentReportId = report2.reportID; + LHNTestUtils.getDefaultRenderedSidebarLinks(currentReportId); return ( waitForPromisesToResolve() @@ -367,9 +367,9 @@ describe('Sidebar', () => { chatReportID: report3.reportID, }; report3.iouReportID = iouReport.reportID; - const reportIDFromRoute = report2.reportID; + const currentReportId = report2.reportID; const currentlyLoggedInUserAccountID = 9; - LHNTestUtils.getDefaultRenderedSidebarLinks(reportIDFromRoute); + LHNTestUtils.getDefaultRenderedSidebarLinks(currentReportId); return ( waitForPromisesToResolve() diff --git a/tests/utils/LHNTestUtils.js b/tests/utils/LHNTestUtils.js index 9dd195c094b8..a6dd710d9522 100644 --- a/tests/utils/LHNTestUtils.js +++ b/tests/utils/LHNTestUtils.js @@ -165,9 +165,9 @@ function getAdvancedFakeReport(isArchived, isUserCreatedPolicyRoom, hasAddWorksp } /** - * @param {String} [reportIDFromRoute] + * @param {String} [currentReportId] */ -function getDefaultRenderedSidebarLinks(reportIDFromRoute = '') { +function getDefaultRenderedSidebarLinks(currentReportId = '') { // An ErrorBoundary needs to be added to the rendering so that any errors that happen while the component // renders are logged to the console. Without an error boundary, Jest only reports the error like "The above error // occurred in your component", except, there is no "above error". It's just swallowed up by Jest somewhere. @@ -196,16 +196,16 @@ function getDefaultRenderedSidebarLinks(reportIDFromRoute = '') { // our app (App.js) is when the react application is wrapped in the context providers render( - + , ); } /** - * @param {String} [reportIDFromRoute] + * @param {String} [currentReportId] * @returns {JSX.Element} */ -function MockedSidebarLinks({reportIDFromRoute}) { +function MockedSidebarLinks({currentReportId}) { return ( ); } MockedSidebarLinks.propTypes = { - reportIDFromRoute: PropTypes.string, + currentReportId: PropTypes.string, }; MockedSidebarLinks.defaultProps = { - reportIDFromRoute: '', + currentReportId: '', }; export {fakePersonalDetails, getDefaultRenderedSidebarLinks, getAdvancedFakeReport, getFakeReport, getFakeReportAction, MockedSidebarLinks};