diff --git a/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js b/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js index 382aad6fef84..fafe54572abb 100644 --- a/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js +++ b/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js @@ -6,6 +6,7 @@ import {withOnyx} from 'react-native-onyx'; import FullScreenLoadingIndicator from '../../../components/FullscreenLoadingIndicator'; import ONYXKEYS from '../../../ONYXKEYS'; import SCREENS from '../../../SCREENS'; +import Permissions from '../../Permissions'; // Screens import ReportScreen from '../../../pages/home/ReportScreen'; @@ -18,15 +19,26 @@ const propTypes = { reports: PropTypes.objectOf(PropTypes.shape({ reportID: PropTypes.number, })), + + /** Beta features list */ + betas: PropTypes.arrayOf(PropTypes.string), }; const defaultProps = { reports: {}, + betas: [], }; -const getInitialReportScreenParams = (reports) => { - const last = findLastAccessedReport(reports); +/** + * Get the most recently accessed report for the user + * + * @param {Object} reports + * @param {Boolean} [ignoreDefaultRooms] + * @returns {Object} + */ +const getInitialReportScreenParams = (reports, ignoreDefaultRooms) => { + const last = findLastAccessedReport(reports, ignoreDefaultRooms); // Fallback to empty if for some reason reportID cannot be derived - prevents the app from crashing const reportID = lodashGet(last, 'reportID', ''); @@ -34,7 +46,7 @@ const getInitialReportScreenParams = (reports) => { }; const MainDrawerNavigator = (props) => { - const initialParams = getInitialReportScreenParams(props.reports); + const initialParams = getInitialReportScreenParams(props.reports, !Permissions.canUseDefaultRooms(props.betas)); // Wait until reports are fetched and there is a reportID in initialParams if (!initialParams.reportID) { @@ -67,5 +79,8 @@ export default withOnyx({ reports: { key: ONYXKEYS.COLLECTION.REPORT, }, + betas: { + key: ONYXKEYS.BETAS, + }, })(MainDrawerNavigator); export {getInitialReportScreenParams}; diff --git a/src/libs/reportUtils.js b/src/libs/reportUtils.js index a63041daacc8..3512a79e8f85 100644 --- a/src/libs/reportUtils.js +++ b/src/libs/reportUtils.js @@ -77,17 +77,6 @@ function canDeleteReportAction(reportAction) { && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT; } - -/** - * Given a collection of reports returns the most recently accessed one - * - * @param {Record|Array<{lastVisitedTimestamp, reportID}>} reports - * @returns {Object} - */ -function findLastAccessedReport(reports) { - return _.last(sortReportsByLastVisited(reports)); -} - /** * Whether the provided report is a default room * @param {Object} report @@ -102,6 +91,23 @@ function isDefaultRoom(report) { ], lodashGet(report, ['chatType'], '')); } +/** + * Given a collection of reports returns the most recently accessed one + * + * @param {Record|Array<{lastVisitedTimestamp, reportID}>} reports + * @param {Boolean} [ignoreDefaultRooms] + * @returns {Object} + */ +function findLastAccessedReport(reports, ignoreDefaultRooms) { + let sortedReports = sortReportsByLastVisited(reports); + + if (ignoreDefaultRooms) { + sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report)); + } + + return _.last(sortedReports); +} + /** * Whether the provided report is an archived room * @param {Object} report diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 80b7c359c015..c4cccb52cea7 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -10,6 +10,8 @@ import Navigation from '../../libs/Navigation/Navigation'; import ROUTES from '../../ROUTES'; import {handleInaccessibleReport, updateCurrentlyViewedReportID, addAction} from '../../libs/actions/Report'; import ONYXKEYS from '../../ONYXKEYS'; +import Permissions from '../../libs/Permissions'; +import {isDefaultRoom} from '../../libs/reportUtils'; import ReportActionsView from './report/ReportActionsView'; import ReportActionCompose from './report/ReportActionCompose'; @@ -54,6 +56,9 @@ const propTypes = { /** Array of report actions for this report */ reportActions: PropTypes.objectOf(PropTypes.shape(ReportActionPropTypes)), + + /** Beta features list */ + betas: PropTypes.arrayOf(PropTypes.string), }; const defaultProps = { @@ -67,6 +72,7 @@ const defaultProps = { maxSequenceNumber: 0, hasOutstandingIOU: false, }, + betas: [], }; /** @@ -153,6 +159,10 @@ class ReportScreen extends React.Component { return null; } + if (!Permissions.canUseDefaultRooms(this.props.betas) && isDefaultRoom(this.props.report)) { + return null; + } + const reportID = getReportID(this.props.route); return ( @@ -208,4 +218,7 @@ export default withOnyx({ report: { key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`, }, + betas: { + key: ONYXKEYS.BETAS, + }, })(ReportScreen);