Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -95,7 +92,6 @@ const defaultProps = {
currentUserPersonalDetails: {
avatar: '',
},
reportIDFromRoute: '',
Comment thread
StevenKKC marked this conversation as resolved.
priorityMode: CONST.PRIORITY_MODE.DEFAULT,
};

Expand Down Expand Up @@ -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 = <OptionsListSkeletonView shouldAnimate />;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
/>
</View>
Expand Down
3 changes: 0 additions & 3 deletions src/pages/home/sidebar/SidebarScreen/sidebarPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/SidebarOrderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions tests/utils/LHNTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -196,16 +196,16 @@ function getDefaultRenderedSidebarLinks(reportIDFromRoute = '') {
// our app (App.js) is when the react application is wrapped in the context providers
render(
<ErrorBoundary>
<MockedSidebarLinks reportIDFromRoute={reportIDFromRoute} />
<MockedSidebarLinks currentReportId={currentReportId} />
</ErrorBoundary>,
);
}

/**
* @param {String} [reportIDFromRoute]
* @param {String} [currentReportId]
* @returns {JSX.Element}
*/
function MockedSidebarLinks({reportIDFromRoute}) {
function MockedSidebarLinks({currentReportId}) {
return (
<ComposeProviders components={[OnyxProvider, LocaleContextProvider]}>
<SidebarLinks
Expand All @@ -217,18 +217,18 @@ function MockedSidebarLinks({reportIDFromRoute}) {
bottom: 0,
}}
isSmallScreenWidth={false}
reportIDFromRoute={reportIDFromRoute}
currentReportId={currentReportId}
/>
</ComposeProviders>
);
}

MockedSidebarLinks.propTypes = {
reportIDFromRoute: PropTypes.string,
currentReportId: PropTypes.string,
};

MockedSidebarLinks.defaultProps = {
reportIDFromRoute: '',
currentReportId: '',
};

export {fakePersonalDetails, getDefaultRenderedSidebarLinks, getAdvancedFakeReport, getFakeReport, getFakeReportAction, MockedSidebarLinks};