From 8a0e9fb05b59b51d3b41bd6ad973124d6f00d24a Mon Sep 17 00:00:00 2001 From: "Jana E. Beck" Date: Wed, 10 Feb 2016 18:29:36 -0800 Subject: [PATCH] remove os from the state tree since it never changes --- docs/state/ExampleStateTree.md | 2 -- docs/state/StateTreeGlossary.md | 4 ---- entry.js | 13 +++++++++--- lib/containers/App.js | 3 +-- lib/containers/root/Root.dev.js | 2 +- lib/containers/root/Root.prod.js | 2 +- lib/redux/actions/async.js | 26 ++++++++---------------- lib/redux/actions/sync.js | 8 -------- test/browser/redux/actions/async.test.js | 18 +++------------- test/browser/redux/actions/sync.test.js | 18 ---------------- 10 files changed, 24 insertions(+), 72 deletions(-) diff --git a/docs/state/ExampleStateTree.md b/docs/state/ExampleStateTree.md index 894600b635..ed846b2109 100644 --- a/docs/state/ExampleStateTree.md +++ b/docs/state/ExampleStateTree.md @@ -148,7 +148,6 @@ The JSON that follows on this page represents a snapshot of the Tidepool Uploade } }, "dropdown": true, - "os": "mac", "page": "MAIN", "unsupported": false, "blipUrls": { @@ -156,7 +155,6 @@ The JSON that follows on this page represents a snapshot of the Tidepool Uploade "signUp": "http://localhost:3000/signup", "viewDataLink": "http://localhost:3000/patients/4a86ec44ff/data" }, - "version": "0.245.0", "working": { "checkingVersion": false, "fetchingUserInfo": false, diff --git a/docs/state/StateTreeGlossary.md b/docs/state/StateTreeGlossary.md index 9809de77b4..d3ee1a42db 100644 --- a/docs/state/StateTreeGlossary.md +++ b/docs/state/StateTreeGlossary.md @@ -100,10 +100,6 @@ The properties of each "device" in `devices` should be fairly self-explanatory. *The Tidepool Uploader inclues a dropdown menu, which is accessible after logging in by clicking on the area where the logged-in user's name is displayed in the upper-right corner. The property `dropdown` in the state tree encodes whether this menu is currently in its open (dropped-down) state (`true`) or closed and hidden (`false`).* -#### `os` - -*The property `os` encodes the operating system environment the Tidepool Uploader is running inside. This value is determined at runtime as part of the app initialization step through the `chrome.runtime.getPlatformInfo` function.* - #### `page` *The property `page` encodes the current "page" of the application that is active. Possible values are, for example, `SETTINGS` for the device selection "page" and `MAIN` for the main upload interface shown in [the app snapshot](./ExampleStateTree.md).* diff --git a/entry.js b/entry.js index 3ad166fb2c..6162f438cc 100644 --- a/entry.js +++ b/entry.js @@ -15,8 +15,11 @@ * == BSD2 LICENSE == */ +/* global chrome */ + require('./styles/main.less'); +var _ = require('lodash'); var React = require('react'); var ReactDOM = require('react-dom'); window.React = React; @@ -25,6 +28,10 @@ window.DEBUG = config.DEBUG; // Important: need to require App after setting `window.DEBUG` to enable logging var Root = require('./lib/containers/root/Root'); -window.app = ReactDOM.render( - React.createElement(Root), document.getElementById('app') -); +chrome.runtime.getPlatformInfo(function (platformInfo) { + if (!_.isEmpty(platformInfo.os)) { + ReactDOM.render( + React.createElement(Root, {os: platformInfo.os}), document.getElementById('app') + ); + } +}); diff --git a/lib/containers/App.js b/lib/containers/App.js index 0eeab07f44..315d7d1a4e 100644 --- a/lib/containers/App.js +++ b/lib/containers/App.js @@ -57,7 +57,7 @@ export default class App extends Component { this.log = bows('App'); this.handleClickChooseDevices = this.handleClickChooseDevices.bind(this); this.handleDismissDropdown = this.handleDismissDropdown.bind(this); - this.props.async.doAppInit(config, { + this.props.async.doAppInit(Object.assign({}, config, {os: props.os}), { api: props.api, carelink, device, @@ -313,7 +313,6 @@ export default connect( dropdown: state.dropdown, loggedInUser: state.loggedInUser, loginErrorMessage: state.loginErrorMessage, - os: state.os, page: state.page, targetUsersForUpload: state.targetUsersForUpload, unsupported: state.unsupported, diff --git a/lib/containers/root/Root.dev.js b/lib/containers/root/Root.dev.js index 5fa29d739a..94e9c589d4 100644 --- a/lib/containers/root/Root.dev.js +++ b/lib/containers/root/Root.dev.js @@ -30,7 +30,7 @@ export default class Root extends Component { return (
- +
diff --git a/lib/containers/root/Root.prod.js b/lib/containers/root/Root.prod.js index ea55dde3a1..d26188c122 100644 --- a/lib/containers/root/Root.prod.js +++ b/lib/containers/root/Root.prod.js @@ -28,7 +28,7 @@ export default class Root extends Component { render() { return ( - + ); } diff --git a/lib/redux/actions/async.js b/lib/redux/actions/async.js index 2f0d117da9..8adf424998 100644 --- a/lib/redux/actions/async.js +++ b/lib/redux/actions/async.js @@ -39,35 +39,26 @@ let daysForCareLink = null; * ASYNCHRONOUS ACTION CREATORS */ -export function doAppInit(config, servicesToInit) { +export function doAppInit(opts, servicesToInit) { return (dispatch, getState) => { services = servicesToInit; - versionInfo.semver = config.version; - versionInfo.name = config.namedVersion; - daysForCareLink = config.DEFAULT_CARELINK_DAYS; + versionInfo.semver = opts.version; + versionInfo.name = opts.namedVersion; + daysForCareLink = opts.DEFAULT_CARELINK_DAYS; const { api, carelink, device, localStore, log } = services; dispatch(syncActions.initRequest()); + dispatch(syncActions.hideUnavailableDevices(opts.os)); function initializeLocalStore(cb) { log('Initializing local store.'); localStore.init(localStore.getInitialState(), () => { cb(); }); } - function getOs(cb) { - if (typeof chrome !== 'undefined') { - chrome.runtime.getPlatformInfo((platformInfo) => { - dispatch(syncActions.setOs(platformInfo.os)); - log('Retrieved operating system info:', platformInfo.os); - dispatch(syncActions.hideUnavailableDevices(platformInfo.os)); - cb(); - }); - } - } function initializeDevice(cb) { log('Initializing device'); device.init({ api, - version: config.namedVersion + version: opts.namedVersion }, cb); } function initializeCareLink(cb) { @@ -80,7 +71,7 @@ export function doAppInit(config, servicesToInit) { } function setApiHosts(cb) { log('Setting all api hosts'); - api.setHosts(_.pick(config, ['API_URL', 'UPLOAD_URL', 'BLIP_URL'])); + api.setHosts(_.pick(opts, ['API_URL', 'UPLOAD_URL', 'BLIP_URL'])); dispatch(syncActions.setForgotPasswordUrl(api.makeBlipUrl(paths.FORGOT_PASSWORD))); dispatch(syncActions.setSignUpUrl(api.makeBlipUrl(paths.SIGNUP))); cb(); @@ -88,7 +79,6 @@ export function doAppInit(config, servicesToInit) { async.series([ initializeLocalStore, - getOs, initializeDevice, initializeCareLink, initializeApi, @@ -97,7 +87,7 @@ export function doAppInit(config, servicesToInit) { if (err) { return dispatch(syncActions.initFailure(err)); } - let session = results[4]; + let session = results[3]; if (session === undefined) { dispatch(syncActions.setPage(pages.LOGIN)); dispatch(syncActions.initSuccess()); diff --git a/lib/redux/actions/sync.js b/lib/redux/actions/sync.js index b1bc61265e..97f01b38fe 100644 --- a/lib/redux/actions/sync.js +++ b/lib/redux/actions/sync.js @@ -88,14 +88,6 @@ export function setForgotPasswordUrl(url) { }; } -export function setOs(os) { - return { - type: actionTypes.SET_OS, - payload: { os }, - meta: {source: actionSources[actionTypes.SET_OS]} - }; -} - export function setPage(page, actionSource = actionSources[actionTypes.SET_PAGE]) { return { type: actionTypes.SET_PAGE, diff --git a/test/browser/redux/actions/async.test.js b/test/browser/redux/actions/async.test.js index a7e1403111..ad9af32c6a 100644 --- a/test/browser/redux/actions/async.test.js +++ b/test/browser/redux/actions/async.test.js @@ -57,6 +57,7 @@ describe('Asynchronous Actions', () => { describe('doAppInit [no session token in local storage]', () => { it('should dispatch SET_VERSION, INIT_APP_REQUEST, SET_OS, HIDE_UNAVAILABLE_DEVICES, SET_FORGOT_PASSWORD_URL, SET_SIGNUP_URL, SET_PAGE, INIT_APP_SUCCESS, VERSION_CHECK_REQUEST, VERSION_CHECK_SUCCESS actions', (done) => { const config = { + os: 'test', version: '0.100.0', API_URL: 'http://www.acme.com' }; @@ -88,11 +89,6 @@ describe('Asynchronous Actions', () => { type: actionTypes.INIT_APP_REQUEST, meta: {source: actionSources[actionTypes.INIT_APP_REQUEST]} }, - { - type: actionTypes.SET_OS, - payload: {os: 'test'}, - meta: {source: actionSources[actionTypes.SET_OS]} - }, { type: actionTypes.HIDE_UNAVAILABLE_DEVICES, payload: {os: 'test'}, @@ -137,6 +133,7 @@ describe('Asynchronous Actions', () => { describe('doAppInit [with session token in local storage]', () => { it('should dispatch SET_VERSION, INIT_APP_REQUEST, SET_OS, HIDE_UNAVAILABLE_DEVICES, SET_FORGOT_PASSWORD_URL, SET_SIGNUP_URL, INIT_APP_SUCCESS, VERSION_CHECK_REQUEST, VERSION_CHECK_SUCCESS, SET_USER_INFO_FROM_TOKEN, SET_BLIP_VIEW_DATA_URL, RETRIEVING_USERS_TARGETS, SET_PAGE actions', (done) => { const config = { + os: 'test', version: '0.100.0', API_URL: 'http://www.acme.com' }; @@ -174,11 +171,6 @@ describe('Asynchronous Actions', () => { type: actionTypes.INIT_APP_REQUEST, meta: {source: actionSources[actionTypes.INIT_APP_REQUEST]} }, - { - type: actionTypes.SET_OS, - payload: {os: 'test'}, - meta: {source: actionSources[actionTypes.SET_OS]} - }, { type: actionTypes.HIDE_UNAVAILABLE_DEVICES, payload: {os: 'test'}, @@ -240,6 +232,7 @@ describe('Asynchronous Actions', () => { describe('doAppInit [with error in api init]', () => { it('should dispatch SET_VERSION, INIT_APP_REQUEST, SET_OS, HIDE_UNAVAILABLE_DEVICES, INIT_APP_FAILURE actions', (done) => { const config = { + os: 'test', version: '0.100.0', API_URL: 'http://www.acme.com/' }; @@ -268,11 +261,6 @@ describe('Asynchronous Actions', () => { type: actionTypes.INIT_APP_REQUEST, meta: {source: actionSources[actionTypes.INIT_APP_REQUEST]} }, - { - type: actionTypes.SET_OS, - payload: {os: 'test'}, - meta: {source: actionSources[actionTypes.SET_OS]} - }, { type: actionTypes.HIDE_UNAVAILABLE_DEVICES, payload: {os: 'test'}, diff --git a/test/browser/redux/actions/sync.test.js b/test/browser/redux/actions/sync.test.js index 091bcb157f..44b9f4bbe2 100644 --- a/test/browser/redux/actions/sync.test.js +++ b/test/browser/redux/actions/sync.test.js @@ -158,24 +158,6 @@ describe('Synchronous Actions', () => { }); }); - describe('setOs', () => { - const OS = 'mac'; - it('should be an FSA', () => { - let action = syncActions.setOs(OS); - - expect(isFSA(action)).to.be.true; - }); - - it('should create an action to set the operating system', () => { - const expectedAction = { - type: actionTypes.SET_OS, - payload: {os: OS}, - meta: {source: actionSources[actionTypes.SET_OS]} - }; - expect(syncActions.setOs(OS)).to.deep.equal(expectedAction); - }); - }); - describe('setPage', () => { const PAGE = 'FOO'; it('should be an FSA', () => {