From 7dd391df12cfb6330f4d1c491991e438f5dc3735 Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 13 Jun 2018 21:00:01 +0200 Subject: [PATCH] Fix storybook and provide __STORYBOOK_ENV__ global --- .eslintrc | 1 + flow-defs/globals.js | 1 + src/globals.js | 7 ++++++- src/renderer/createStore.js | 6 ++++-- src/renderer/init.js | 9 ++------- webpack/plugins.js | 3 ++- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.eslintrc b/.eslintrc index 60aa4172..d30945b6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,6 +11,7 @@ "__PRINT_MODE__": false, "__GLOBAL_STYLES__": false, "__APP_VERSION__": false, + "__STORYBOOK_ENV__": false, "__static": false, "window": false, "document": false, diff --git a/flow-defs/globals.js b/flow-defs/globals.js index 5e37fd59..fd239c40 100644 --- a/flow-defs/globals.js +++ b/flow-defs/globals.js @@ -8,6 +8,7 @@ declare var __PRINT_MODE__: string declare var __SENTRY_URL__: string declare var __GLOBAL_STYLES__: string declare var __APP_VERSION__: string +declare var __STORYBOOK_ENV__: string declare var __static: string declare var describe: Function declare var test: Function diff --git a/src/globals.js b/src/globals.js index 69bd02d1..c4d9dfd2 100644 --- a/src/globals.js +++ b/src/globals.js @@ -1,8 +1,13 @@ // @flow -const { NODE_ENV } = process.env +const { NODE_ENV, STORYBOOK_ENV } = process.env global.__ENV__ = NODE_ENV === 'development' ? NODE_ENV : 'production' global.__DEV__ = global.__ENV__ === 'development' global.__PROD__ = !global.__DEV__ +global.__STORYBOOK_ENV__ = STORYBOOK_ENV === '1' global.__GLOBAL_STYLES__ = require('./styles/reset') + +if (STORYBOOK_ENV === '1') { + global.__APP_VERSION__ = '1.0.0' +} diff --git a/src/renderer/createStore.js b/src/renderer/createStore.js index 75f46711..f5d6a949 100644 --- a/src/renderer/createStore.js +++ b/src/renderer/createStore.js @@ -6,7 +6,6 @@ import thunk from 'redux-thunk' import createHistory from 'history/createHashHistory' import type { HashHistory } from 'history' import logger from 'middlewares/logger' -import sentry from 'middlewares/sentry' import reducers from 'reducers' type Props = { @@ -20,7 +19,10 @@ export default ({ state, history, dbMiddleware }: Props) => { if (!history) { history = createHistory() } - const middlewares = [routerMiddleware(history), thunk, logger, sentry] + const middlewares = [routerMiddleware(history), thunk, logger] + if (!__STORYBOOK_ENV__) { + middlewares.push(require('middlewares/sentry').default) + } if (dbMiddleware) { middlewares.push(dbMiddleware) } diff --git a/src/renderer/init.js b/src/renderer/init.js index 1806aff1..5b01a2ed 100644 --- a/src/renderer/init.js +++ b/src/renderer/init.js @@ -11,6 +11,8 @@ import moment from 'moment' import createStore from 'renderer/createStore' import events from 'renderer/events' +import { enableGlobalTab, isGlobalTabEnabled } from 'config/global-tab' + import { fetchAccounts } from 'actions/accounts' import { fetchSettings } from 'actions/settings' import { isLocked } from 'reducers/application' @@ -29,15 +31,8 @@ import 'styles/global' const rootNode = document.getElementById('app') -// Github like focus style: -// - focus states are not visible by default -// - first time user hit tab, enable global tab to see focus states -let IS_GLOBAL_TAB_ENABLED = false const TAB_KEY = 9 -export const isGlobalTabEnabled = () => IS_GLOBAL_TAB_ENABLED -export const enableGlobalTab = () => (IS_GLOBAL_TAB_ENABLED = true) - async function init() { if (process.env.LEDGER_RESET_ALL) { await hardReset() diff --git a/webpack/plugins.js b/webpack/plugins.js index e1bfb18d..7dc4536f 100644 --- a/webpack/plugins.js +++ b/webpack/plugins.js @@ -3,7 +3,7 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') const pkg = require('../package.json') require('../src/globals') -const { BUNDLE_ANALYZER, SENTRY_URL } = process.env +const { BUNDLE_ANALYZER, SENTRY_URL, STORYBOOK_ENV } = process.env module.exports = type => { const plugins = [ @@ -13,6 +13,7 @@ module.exports = type => { __DEV__, __PROD__, __SENTRY_URL__: JSON.stringify(SENTRY_URL || null), + __STORYBOOK_ENV__: JSON.stringify(STORYBOOK_ENV), 'process.env.NODE_ENV': JSON.stringify(__ENV__), }), ]