From ee288b1008b4503631ee1b7cf05eb31c440e5e96 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Fri, 17 Sep 2021 18:18:19 -0400 Subject: [PATCH 1/4] Stop loading default chat room as last accessed room for those outside beta --- .../AppNavigator/MainDrawerNavigator.js | 22 ++++++++++++++++--- src/libs/reportUtils.js | 11 ++++++++-- src/pages/home/ReportScreen.js | 3 +++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js b/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js index 382aad6fef84..22dab925dbf9 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,8 @@ const getInitialReportScreenParams = (reports) => { }; const MainDrawerNavigator = (props) => { - const initialParams = getInitialReportScreenParams(props.reports); + const initialParams = getInitialReportScreenParams(props.reports, !Permissions.canUseDefaultRooms(props.betas)); + debugger; // Wait until reports are fetched and there is a reportID in initialParams if (!initialParams.reportID) { @@ -67,5 +80,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..134cbf62652a 100644 --- a/src/libs/reportUtils.js +++ b/src/libs/reportUtils.js @@ -82,10 +82,17 @@ function canDeleteReportAction(reportAction) { * 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) { - return _.last(sortReportsByLastVisited(reports)); +function findLastAccessedReport(reports, ignoreDefaultRooms) { + let sortedReports = sortReportsByLastVisited(reports); + + if (ignoreDefaultRooms) { + sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report)) + } + + return _.last(sortedReports); } /** diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 80b7c359c015..2701a5b0f5ff 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -154,6 +154,9 @@ class ReportScreen extends React.Component { } const reportID = getReportID(this.props.route); + console.log('HEY LOOK AT THIS -------------------------'); + console.log(reportID); + console.log(this.props.report); return ( Date: Mon, 20 Sep 2021 10:46:53 -0400 Subject: [PATCH 2/4] Don't show anything for default rooms users shouldn't be able to access --- src/pages/home/ReportScreen.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 2701a5b0f5ff..bf7b8be7cd85 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,10 +159,10 @@ class ReportScreen extends React.Component { return null; } - const reportID = getReportID(this.props.route); - console.log('HEY LOOK AT THIS -------------------------'); - console.log(reportID); - console.log(this.props.report); + if (!Permissions.canUseDefaultRooms() && isDefaultRoom(this.props.report)) { + return null; + } + return ( `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`, }, + betas: { + key: ONYXKEYS.BETAS, + }, })(ReportScreen); From 9ac5a4186d7d86cd2e6f3091895451385b57b9e1 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Mon, 20 Sep 2021 10:53:12 -0400 Subject: [PATCH 3/4] Clean up style --- .../AppNavigator/MainDrawerNavigator.js | 3 +- src/libs/reportUtils.js | 29 +++++++++---------- src/pages/home/ReportScreen.js | 4 ++- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js b/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js index 22dab925dbf9..fafe54572abb 100644 --- a/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js +++ b/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js @@ -46,8 +46,7 @@ const getInitialReportScreenParams = (reports, ignoreDefaultRooms) => { }; const MainDrawerNavigator = (props) => { - const initialParams = getInitialReportScreenParams(props.reports, !Permissions.canUseDefaultRooms(props.betas)); - debugger; + const initialParams = getInitialReportScreenParams(props.reports, !Permissions.canUseDefaultRooms(props.betas)); // Wait until reports are fetched and there is a reportID in initialParams if (!initialParams.reportID) { diff --git a/src/libs/reportUtils.js b/src/libs/reportUtils.js index 134cbf62652a..3512a79e8f85 100644 --- a/src/libs/reportUtils.js +++ b/src/libs/reportUtils.js @@ -77,6 +77,19 @@ function canDeleteReportAction(reportAction) { && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT; } +/** + * Whether the provided report is a default room + * @param {Object} report + * @param {String} report.chatType + * @returns {Boolean} + */ +function isDefaultRoom(report) { + return _.contains([ + CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, + CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE, + CONST.REPORT.CHAT_TYPE.DOMAIN_ALL, + ], lodashGet(report, ['chatType'], '')); +} /** * Given a collection of reports returns the most recently accessed one @@ -89,26 +102,12 @@ function findLastAccessedReport(reports, ignoreDefaultRooms) { let sortedReports = sortReportsByLastVisited(reports); if (ignoreDefaultRooms) { - sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report)) + sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report)); } return _.last(sortedReports); } -/** - * Whether the provided report is a default room - * @param {Object} report - * @param {String} report.chatType - * @returns {Boolean} - */ -function isDefaultRoom(report) { - return _.contains([ - CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, - CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE, - CONST.REPORT.CHAT_TYPE.DOMAIN_ALL, - ], lodashGet(report, ['chatType'], '')); -} - /** * 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 bf7b8be7cd85..27a2311baf95 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -159,10 +159,12 @@ class ReportScreen extends React.Component { return null; } - if (!Permissions.canUseDefaultRooms() && isDefaultRoom(this.props.report)) { + if (!Permissions.canUseDefaultRooms(this.props.betas) && isDefaultRoom(this.props.report)) { return null; } + const reportID = getReportID(this.props.route); + return ( Date: Mon, 20 Sep 2021 11:14:56 -0400 Subject: [PATCH 4/4] Remove extra whitespace --- src/pages/home/ReportScreen.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 27a2311baf95..c4cccb52cea7 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -164,7 +164,6 @@ class ReportScreen extends React.Component { } const reportID = getReportID(this.props.route); - return (