Bug 1498150 - Hide networklocations form in ConnectPage behind pref;r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 24 Oct 2018 09:27:55 +0000
changeset 491086 a9c39ecb125c5b6d3586f45cdca93547f863dfc2
parent 491085 0fe678bdcf595a848a25f423825ac6387bd19f1b
child 491087 7e0caa46aba1915115b4a5dffe08633f9d213e79
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersdaisuke
bugs1498150
milestone65.0a1
Bug 1498150 - Hide networklocations form in ConnectPage behind pref;r=daisuke Differential Revision: https://phabricator.services.mozilla.com/D9122
devtools/client/aboutdebugging-new/src/components/App.js
devtools/client/aboutdebugging-new/src/components/connect/ConnectPage.js
devtools/client/aboutdebugging-new/src/create-store.js
devtools/client/aboutdebugging-new/src/reducers/ui-state.js
devtools/client/aboutdebugging-new/test/browser/head.js
--- a/devtools/client/aboutdebugging-new/src/components/App.js
+++ b/devtools/client/aboutdebugging-new/src/components/App.js
@@ -23,41 +23,44 @@ class App extends PureComponent {
   static get propTypes() {
     return {
       adbAddonStatus: PropTypes.string,
       // The "dispatch" helper is forwarded to the App component via connect.
       // From that point, components are responsible for forwarding the dispatch
       // property to all components who need to dispatch actions.
       dispatch: PropTypes.func.isRequired,
       fluentBundles: PropTypes.arrayOf(PropTypes.object).isRequired,
+      networkEnabled: PropTypes.bool.isRequired,
       networkLocations: PropTypes.arrayOf(PropTypes.string).isRequired,
       networkRuntimes: PropTypes.arrayOf(Types.runtime).isRequired,
       selectedPage: PropTypes.string,
       usbRuntimes: PropTypes.arrayOf(Types.runtime).isRequired,
     };
   }
 
   getSelectedPageComponent() {
     const {
       adbAddonStatus,
       dispatch,
+      networkEnabled,
       networkLocations,
       selectedPage,
     } = this.props;
 
     if (!selectedPage) {
       // No page selected.
       return null;
     }
 
     switch (selectedPage) {
       case PAGES.CONNECT:
         return ConnectPage({
           adbAddonStatus,
           dispatch,
+          networkEnabled,
           networkLocations,
         });
       default:
         // All pages except for the CONNECT page are RUNTIME pages.
         return RuntimePage({ dispatch });
     }
   }
 
@@ -92,16 +95,17 @@ class App extends PureComponent {
       )
     );
   }
 }
 
 const mapStateToProps = state => {
   return {
     adbAddonStatus: state.ui.adbAddonStatus,
+    networkEnabled: state.ui.networkEnabled,
     networkLocations: state.ui.networkLocations,
     networkRuntimes: state.runtimes.networkRuntimes,
     selectedPage: state.ui.selectedPage,
     usbRuntimes: state.runtimes.usbRuntimes,
   };
 };
 
 const mapDispatchToProps = dispatch => ({
--- a/devtools/client/aboutdebugging-new/src/components/connect/ConnectPage.js
+++ b/devtools/client/aboutdebugging-new/src/components/connect/ConnectPage.js
@@ -30,16 +30,17 @@ const GLOBE_ICON_SRC = "chrome://devtool
 
 class ConnectPage extends PureComponent {
   static get propTypes() {
     return {
       adbAddonStatus: PropTypes.string,
       dispatch: PropTypes.func.isRequired,
       // Provided by wrapping the component with FluentReact.withLocalization.
       getString: PropTypes.func.isRequired,
+      networkEnabled: PropTypes.bool.isRequired,
       networkLocations: PropTypes.arrayOf(PropTypes.string).isRequired,
     };
   }
 
   renderWifi() {
     const { getString } = this.props;
     return Localized(
       {
@@ -148,17 +149,22 @@ class ConnectPage extends PureComponent 
           )
         ),
         this.renderUsbToggleButton()
       )
     );
   }
 
   renderNetwork() {
-    const { dispatch, networkLocations } = this.props;
+    const { dispatch, networkEnabled, networkLocations } = this.props;
+
+    if (!networkEnabled) {
+      return null;
+    }
+
     return Localized(
       {
         id: "about-debugging-connect-network",
         attrs: { title: true },
       },
       ConnectSection(
         {
           className: "connect-page__network",
--- a/devtools/client/aboutdebugging-new/src/create-store.js
+++ b/devtools/client/aboutdebugging-new/src/create-store.js
@@ -1,28 +1,33 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+const Services = require("Services");
+
 const { applyMiddleware, createStore } = require("devtools/client/shared/vendor/redux");
 const { thunk } = require("devtools/client/shared/redux/middleware/thunk.js");
 
 const rootReducer = require("./reducers/index");
 const { DebugTargetsState } = require("./reducers/debug-targets-state");
 const { RuntimesState } = require("./reducers/runtimes-state");
 const { UiState } = require("./reducers/ui-state");
 const debugTargetListenerMiddleware = require("./middleware/debug-target-listener");
 const extensionComponentDataMiddleware = require("./middleware/extension-component-data");
 const tabComponentDataMiddleware = require("./middleware/tab-component-data");
 const workerComponentDataMiddleware = require("./middleware/worker-component-data");
 const { getDebugTargetCollapsibilities } = require("./modules/debug-target-collapsibilities");
 const { getNetworkLocations } = require("./modules/network-locations");
 
+// Temporary preference without any default value until network locations are enabled.
+const NETWORK_ENABLED_PREF = "devtools.aboutdebugging.network";
+
 function configureStore() {
   const initialState = {
     debugTargets: new DebugTargetsState(),
     runtimes: new RuntimesState(),
     ui: getUiState(),
   };
 
   const middleware = applyMiddleware(thunk,
@@ -32,12 +37,13 @@ function configureStore() {
                                      workerComponentDataMiddleware);
 
   return createStore(rootReducer, initialState, middleware);
 }
 
 function getUiState() {
   const collapsibilities = getDebugTargetCollapsibilities();
   const locations = getNetworkLocations();
-  return new UiState(locations, collapsibilities);
+  const networkEnabled = Services.prefs.getBoolPref(NETWORK_ENABLED_PREF, false);
+  return new UiState(locations, collapsibilities, networkEnabled);
 }
 
 exports.configureStore = configureStore;
--- a/devtools/client/aboutdebugging-new/src/reducers/ui-state.js
+++ b/devtools/client/aboutdebugging-new/src/reducers/ui-state.js
@@ -6,20 +6,22 @@
 
 const {
   ADB_ADDON_STATUS_UPDATED,
   DEBUG_TARGET_COLLAPSIBILITY_UPDATED,
   NETWORK_LOCATIONS_UPDATED,
   PAGE_SELECTED,
 } = require("../constants");
 
-function UiState(locations = [], debugTargetCollapsibilities = {}) {
+function UiState(locations = [], debugTargetCollapsibilities = {},
+                 networkEnabled = false) {
   return {
     adbAddonStatus: null,
     debugTargetCollapsibilities,
+    networkEnabled,
     networkLocations: locations,
     selectedPage: null,
   };
 }
 
 function uiReducer(state = UiState(), action) {
   switch (action.type) {
     case ADB_ADDON_STATUS_UPDATED: {
--- a/devtools/client/aboutdebugging-new/test/browser/head.js
+++ b/devtools/client/aboutdebugging-new/test/browser/head.js
@@ -29,16 +29,17 @@ registerCleanupFunction(async function()
   await ADB.kill();
 });
 
 /**
  * Enable the new about:debugging panel.
  */
 async function enableNewAboutDebugging() {
   await pushPref("devtools.aboutdebugging.new-enabled", true);
+  await pushPref("devtools.aboutdebugging.network", true);
 }
 
 async function openAboutDebugging(page, win) {
   await enableNewAboutDebugging();
 
   info("opening about:debugging");
   const tab = await addTab("about:debugging", { window: win });
   const browser = tab.linkedBrowser;