From bc922deb23a72d6ca1bf4c39efd1d7366baa9a84 Mon Sep 17 00:00:00 2001 From: Tayane Fernandes Date: Tue, 7 Feb 2017 17:39:09 -0200 Subject: [#922] Refactoring react folder structure with @anikarni --- web-ui/.jshintignore | 5 +- web-ui/app/account_recovery.html | 12 -- web-ui/app/js/account_recovery.js | 18 --- web-ui/app/js/account_recovery/i18n.js | 39 ----- web-ui/app/js/account_recovery/page.js | 28 ---- web-ui/app/scss/account_recovery/page.scss | 176 ---------------------- web-ui/config/alias-webpack.js | 1 + web-ui/config/copy-webpack.js | 2 +- web-ui/karma.conf.js | 2 +- web-ui/package.json | 3 +- web-ui/src/account_recovery/account_recovery.html | 12 ++ web-ui/src/account_recovery/account_recovery.js | 18 +++ web-ui/src/account_recovery/page.js | 28 ++++ web-ui/src/account_recovery/page.scss | 176 ++++++++++++++++++++++ web-ui/src/i18n.js | 39 +++++ web-ui/test/jasmine.json | 9 -- web-ui/test/spec/account_recovery/page.spec.js | 12 -- web-ui/test/test-main.js | 2 +- web-ui/test/unit/account_recovery/page.spec.js | 12 ++ web-ui/webpack.config.js | 2 +- web-ui/webpack.production.config.js | 2 +- 21 files changed, 295 insertions(+), 303 deletions(-) delete mode 100644 web-ui/app/account_recovery.html delete mode 100644 web-ui/app/js/account_recovery.js delete mode 100644 web-ui/app/js/account_recovery/i18n.js delete mode 100644 web-ui/app/js/account_recovery/page.js delete mode 100644 web-ui/app/scss/account_recovery/page.scss create mode 100644 web-ui/src/account_recovery/account_recovery.html create mode 100644 web-ui/src/account_recovery/account_recovery.js create mode 100644 web-ui/src/account_recovery/page.js create mode 100644 web-ui/src/account_recovery/page.scss create mode 100644 web-ui/src/i18n.js delete mode 100644 web-ui/test/jasmine.json delete mode 100644 web-ui/test/spec/account_recovery/page.spec.js create mode 100644 web-ui/test/unit/account_recovery/page.spec.js diff --git a/web-ui/.jshintignore b/web-ui/.jshintignore index df04d870..b28da15f 100644 --- a/web-ui/.jshintignore +++ b/web-ui/.jshintignore @@ -2,6 +2,5 @@ app/node_modules app/bower_components app/js/lib app/js/generated -app/js/account_recovery.js -app/js/account_recovery -test/spec/account_recovery +src/ +test/unit diff --git a/web-ui/app/account_recovery.html b/web-ui/app/account_recovery.html deleted file mode 100644 index bd451ebc..00000000 --- a/web-ui/app/account_recovery.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Pixelated Account Recovery - - -
- - - diff --git a/web-ui/app/js/account_recovery.js b/web-ui/app/js/account_recovery.js deleted file mode 100644 index cd01378d..00000000 --- a/web-ui/app/js/account_recovery.js +++ /dev/null @@ -1,18 +0,0 @@ -import React from 'react' -import { render } from 'react-dom' -import a11y from 'react-a11y' -import { I18nextProvider } from 'react-i18next' - -import Page from 'js/account_recovery/page' -import i18n from 'js/account_recovery/i18n' - -import 'font-awesome/scss/font-awesome.scss' - -if(process.env.NODE_ENV === 'development') a11y(React); - -render( - - - , - document.getElementById('root') -); diff --git a/web-ui/app/js/account_recovery/i18n.js b/web-ui/app/js/account_recovery/i18n.js deleted file mode 100644 index 9c6ad550..00000000 --- a/web-ui/app/js/account_recovery/i18n.js +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2017 ThoughtWorks, Inc. - * - * Pixelated is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Pixelated is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Pixelated. If not, see . - */ -import i18n from 'i18next' -import i18nBackend from 'i18nextXHRBackend' -import i18nDetector from 'i18nextBrowserLanguageDetector' - -const detector = new i18nDetector(); -const detect = detector.detect.bind(detector); - -detector.detect = function(detectionOrder) { - let result = detect(detectionOrder); - return result.replace('-', '_'); -}; - -i18n - .use(i18nBackend) - .use(detector) - .init({ - fallbackLng: 'en_US', - backend: { - loadPath: 'assets/locales/{{lng}}/{{ns}}.json' - } - }); - -export default i18n; diff --git a/web-ui/app/js/account_recovery/page.js b/web-ui/app/js/account_recovery/page.js deleted file mode 100644 index a94c2c45..00000000 --- a/web-ui/app/js/account_recovery/page.js +++ /dev/null @@ -1,28 +0,0 @@ -import React from 'react' -import { translate } from 'react-i18next' - -import 'scss/account_recovery/page.scss' - -export const Page = ({ t }) => ( -
- {t('backup-account.image-description')}/ -
-

{t('backup-account.title')}

-

{t('backup-account.paragraph1')}

-

{t('backup-account.paragraph2')}

-
- - -
- - -
-
-) - -export default translate('', { wait: true })(Page) diff --git a/web-ui/app/scss/account_recovery/page.scss b/web-ui/app/scss/account_recovery/page.scss deleted file mode 100644 index 8bba1b5a..00000000 --- a/web-ui/app/scss/account_recovery/page.scss +++ /dev/null @@ -1,176 +0,0 @@ -@import "../vendor/reset"; -@import "../base/colors"; -@import "../base/fonts"; - -html { - min-height: 100%; -} - -body { - font-family: "Open Sans", "Microsoft YaHei", "Hiragino Sans GB", "Hiragino Sans GB W3", "微软雅黑", "Helvetica Neue", Arial, sans-serif; - background: $dark_blue; /* For browsers that do not support gradients */ - background: -webkit-linear-gradient(left top, $dark_blue, $middle_blue); /* For Safari 5.1 to 6.0 */ - background: -o-linear-gradient(bottom right, $dark_blue, $middle_blue); /* For Opera 11.1 to 12.0 */ - background: -moz-linear-gradient(bottom right, $dark_blue, $middle_blue); /* For Firefox 3.6 to 15 */ - background: linear-gradient(to bottom right, $dark_blue, $middle_blue); /* Standard syntax */ - color: $dark_grey_text; - min-height: 100%; -} - -h1 { - font-size: 1.3em; - font-weight: 600; -} - -p { - -webkit-margin-before: 0.5em; - -webkit-margin-after: 0.5em; - margin-before: 0.5em; - margin-after: 0.5em; -} - -a { - text-decoration: none; - color: $dark_blue; - font-style: italic; - - .fa { - font-size: 1.6em; - position: relative; - top: 3px; - margin-right: 0.3em; - } - -} - -.field-group { - position:relative; - margin: 1.5em 0; - width: 100%; - - label { - font-size: 0.9em; - margin-bottom: 10px; - display: inline-block; - } - - input { - display: block; - border: none; - border-bottom: solid 1px #4da3b6; - width: 100%; - height: auto; - padding: 0.3em 0px; - } - - input:focus { - outline:none; - border-width: 2px; - } - - input:focus ~ .animated-label, input:valid ~ .animated-label { - top:-12px; - left: 0; - font-size:0.7em; - color:#4da3b6; - } - - .animated-label { - color:#999; - position:absolute; - pointer-events:none; - left: 6px; - top:10px; - transition:0.2s ease all; - -moz-transition:0.2s ease all; - -webkit-transition:0.2s ease all; - } -} - - -button { - background: $dark_blue; - padding: 0.8em; - color: $white; - text-align: center; - border: none; - border-radius: 2px; - font-weight: 300; - width: 100%; - margin-bottom: 1em; -} - -.container { - background: $white; - width: 84%; - margin: 3% auto; - padding: 6% 5%; - - -webkit-display: flex; - display: flex; - -webkit-align-items: flex-start; - align-items: flex-start; - -webkit-flex-direction: column; - flex-direction: column; -} - -img { - width: 50%; - -webkit-align-self: center; - align-self: center; -} - -@media only screen and (min-width : 500px) { - body { - font-size: 1.3em; - } - - form { - display: flex; - -webkit-display: flex; - -webkit-flex-direction: column; - flex-direction: column; - - .field-group, button, div { - width: 70%; - -webkit-align-self: center; - align-self: center; - } - } -} - -@media only screen and (min-width : 960px) { - .container{ - width: 60%; - padding: 3%; - -webkit-align-items: flex-start; - align-items: flex-start; - -webkit-flex-direction: row; - flex-direction: row; - max-width: 700px; - } - - form { - margin-left: 2.5em; - - .field-group, button, div { - width: 300px; - -webkit-align-self: flex-start; - align-self: flex-start; - } - - .field-group { - margin-top: 3em; - font-size: 1em; - } - } - - img { - width: 300px; - } - - button { - font-size: 0.8em; - margin-bottom: 1em; - } -} diff --git a/web-ui/config/alias-webpack.js b/web-ui/config/alias-webpack.js index 43b23836..d316bb2d 100644 --- a/web-ui/config/alias-webpack.js +++ b/web-ui/config/alias-webpack.js @@ -7,6 +7,7 @@ module.exports = { 'flight': path.join(__dirname, '../app/bower_components/flight'), 'found': path.join(__dirname, '../app/bower_components/foundation'), 'js': path.join(__dirname, '../app/js'), + 'src': path.join(__dirname, '../src'), 'scss': path.join(__dirname, '../app/scss'), 'mail_list': path.join(__dirname, '../app/js/mail_list'), 'page': path.join(__dirname, '../app/js/page'), diff --git a/web-ui/config/copy-webpack.js b/web-ui/config/copy-webpack.js index a2567be6..8e9f9dd3 100644 --- a/web-ui/config/copy-webpack.js +++ b/web-ui/config/copy-webpack.js @@ -4,7 +4,7 @@ module.exports = new CopyWebpackPlugin([ { context: 'app/', from: '404.html' }, { context: 'app/', from: 'index.html' }, { context: 'app/', from: 'sandbox.html' }, - { context: 'app/', from: 'account_recovery.html' }, + { context: 'src/account_recovery/', from: 'account_recovery.html' }, { context: 'app/', from: 'css/*' }, { context: 'app/', from: 'fonts/*' }, { context: 'app/', from: 'locales/**/*' }, diff --git a/web-ui/karma.conf.js b/web-ui/karma.conf.js index d10667e9..2895dc42 100644 --- a/web-ui/karma.conf.js +++ b/web-ui/karma.conf.js @@ -68,7 +68,7 @@ module.exports = function (config) { reporters: ['dots', 'junit', 'coverage'], preprocessors: { - 'app/js/!(lib|account_recovery)/**/*.js': ['coverage'] + 'app/js/!(lib)/**/*.js': ['coverage'] }, // enable / disable watching file and executing tests whenever any file changes diff --git a/web-ui/package.json b/web-ui/package.json index ff4201c0..dba34e97 100644 --- a/web-ui/package.json +++ b/web-ui/package.json @@ -65,7 +65,8 @@ }, "scripts": { "test": "npm run jshint --silent && npm run build-statics --silent && npm run mocha-test && npm run karma-test", - "mocha-test": "mocha-webpack --webpack-config webpack.test.config.js \"test/spec/account_recovery/**/*.spec.js\"", + "mocha-test": "mocha-webpack --webpack-config webpack.test.config.js \"test/unit/**/*.spec.js\"", + "mocha-watch": "mocha-webpack --watch --webpack-config webpack.test.config.js \"test/unit/**/*.spec.js\"", "karma-test": "karma start --single-run $GRUNT_OPTS", "debug": "npm run build && karma start --browsers Chrome $GRUNT_OPTS", "watch": "npm run compass-watch & npm run handlebars-watch & npm run build-js-watch", diff --git a/web-ui/src/account_recovery/account_recovery.html b/web-ui/src/account_recovery/account_recovery.html new file mode 100644 index 00000000..bd451ebc --- /dev/null +++ b/web-ui/src/account_recovery/account_recovery.html @@ -0,0 +1,12 @@ + + + + + + Pixelated Account Recovery + + +
+ + + diff --git a/web-ui/src/account_recovery/account_recovery.js b/web-ui/src/account_recovery/account_recovery.js new file mode 100644 index 00000000..f2421bfc --- /dev/null +++ b/web-ui/src/account_recovery/account_recovery.js @@ -0,0 +1,18 @@ +import React from 'react' +import { render } from 'react-dom' +import a11y from 'react-a11y' +import { I18nextProvider } from 'react-i18next' + +import Page from './page' +import i18n from '../i18n' + +import 'font-awesome/scss/font-awesome.scss' + +if(process.env.NODE_ENV === 'development') a11y(React); + +render( + + + , + document.getElementById('root') +); diff --git a/web-ui/src/account_recovery/page.js b/web-ui/src/account_recovery/page.js new file mode 100644 index 00000000..a02d307c --- /dev/null +++ b/web-ui/src/account_recovery/page.js @@ -0,0 +1,28 @@ +import React from 'react' +import { translate } from 'react-i18next' + +import './page.scss' + +export const Page = ({ t }) => ( +
+ {t('backup-account.image-description')}/ +
+

{t('backup-account.title')}

+

{t('backup-account.paragraph1')}

+

{t('backup-account.paragraph2')}

+
+ + +
+ + +
+
+) + +export default translate('', { wait: true })(Page) diff --git a/web-ui/src/account_recovery/page.scss b/web-ui/src/account_recovery/page.scss new file mode 100644 index 00000000..e7b1504e --- /dev/null +++ b/web-ui/src/account_recovery/page.scss @@ -0,0 +1,176 @@ +@import "~scss/vendor/reset"; +@import "~scss/base/colors"; +@import "~scss/base/fonts"; + +html { + min-height: 100%; +} + +body { + font-family: "Open Sans", "Microsoft YaHei", "Hiragino Sans GB", "Hiragino Sans GB W3", "微软雅黑", "Helvetica Neue", Arial, sans-serif; + background: $dark_blue; /* For browsers that do not support gradients */ + background: -webkit-linear-gradient(left top, $dark_blue, $middle_blue); /* For Safari 5.1 to 6.0 */ + background: -o-linear-gradient(bottom right, $dark_blue, $middle_blue); /* For Opera 11.1 to 12.0 */ + background: -moz-linear-gradient(bottom right, $dark_blue, $middle_blue); /* For Firefox 3.6 to 15 */ + background: linear-gradient(to bottom right, $dark_blue, $middle_blue); /* Standard syntax */ + color: $dark_grey_text; + min-height: 100%; +} + +h1 { + font-size: 1.3em; + font-weight: 600; +} + +p { + -webkit-margin-before: 0.5em; + -webkit-margin-after: 0.5em; + margin-before: 0.5em; + margin-after: 0.5em; +} + +a { + text-decoration: none; + color: $dark_blue; + font-style: italic; + + .fa { + font-size: 1.6em; + position: relative; + top: 3px; + margin-right: 0.3em; + } + +} + +.field-group { + position:relative; + margin: 1.5em 0; + width: 100%; + + label { + font-size: 0.9em; + margin-bottom: 10px; + display: inline-block; + } + + input { + display: block; + border: none; + border-bottom: solid 1px #4da3b6; + width: 100%; + height: auto; + padding: 0.3em 0px; + } + + input:focus { + outline:none; + border-width: 2px; + } + + input:focus ~ .animated-label, input:valid ~ .animated-label { + top:-12px; + left: 0; + font-size:0.7em; + color:#4da3b6; + } + + .animated-label { + color:#999; + position:absolute; + pointer-events:none; + left: 6px; + top:10px; + transition:0.2s ease all; + -moz-transition:0.2s ease all; + -webkit-transition:0.2s ease all; + } +} + + +button { + background: $dark_blue; + padding: 0.8em; + color: $white; + text-align: center; + border: none; + border-radius: 2px; + font-weight: 300; + width: 100%; + margin-bottom: 1em; +} + +.container { + background: $white; + width: 84%; + // margin: 3% auto; + padding: 6% 5%; + + -webkit-display: flex; + display: flex; + -webkit-align-items: flex-start; + align-items: flex-start; + -webkit-flex-direction: column; + flex-direction: column; +} + +img { + width: 50%; + -webkit-align-self: center; + align-self: center; +} + +@media only screen and (min-width : 500px) { + body { + font-size: 1.3em; + } + + form { + display: flex; + -webkit-display: flex; + -webkit-flex-direction: column; + flex-direction: column; + + .field-group, button, div { + flex-basis: 70%; + -webkit-align-self: center; + align-self: center; + } + } +} + +@media only screen and (min-width : 960px) { + .container{ + width: 60%; + padding: 3%; + -webkit-align-items: flex-start; + align-items: flex-start; + -webkit-flex-direction: row; + flex-direction: row; + max-width: 700px; + } + + form { + margin-left: 2.5em; + + .field-group, button, div { + width: 300px; + -webkit-align-self: flex-start; + align-self: flex-start; + } + + .field-group { + margin-top: 3em; + font-size: 1em; + } + } + + img { + width: 300px; + } + + button { + font-size: 0.8em; + margin-bottom: 1em; + } +} diff --git a/web-ui/src/i18n.js b/web-ui/src/i18n.js new file mode 100644 index 00000000..9c6ad550 --- /dev/null +++ b/web-ui/src/i18n.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see . + */ +import i18n from 'i18next' +import i18nBackend from 'i18nextXHRBackend' +import i18nDetector from 'i18nextBrowserLanguageDetector' + +const detector = new i18nDetector(); +const detect = detector.detect.bind(detector); + +detector.detect = function(detectionOrder) { + let result = detect(detectionOrder); + return result.replace('-', '_'); +}; + +i18n + .use(i18nBackend) + .use(detector) + .init({ + fallbackLng: 'en_US', + backend: { + loadPath: 'assets/locales/{{lng}}/{{ns}}.json' + } + }); + +export default i18n; diff --git a/web-ui/test/jasmine.json b/web-ui/test/jasmine.json deleted file mode 100644 index 969304b6..00000000 --- a/web-ui/test/jasmine.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "spec_dir": "test/spec/account_recovery/", - "spec_files": [ - "**/*[sS]pec.js" - ], - "helpers": [ - "helpers/**/*.js" - ] -} diff --git a/web-ui/test/spec/account_recovery/page.spec.js b/web-ui/test/spec/account_recovery/page.spec.js deleted file mode 100644 index 3e19f244..00000000 --- a/web-ui/test/spec/account_recovery/page.spec.js +++ /dev/null @@ -1,12 +0,0 @@ -import {shallow} from 'enzyme' -import expect from 'expect' -import React from 'react' -import { Page } from '../../../app/js/account_recovery/page' - -describe('Page', () => { - it('renders backup email page title', () => { - const mockT = key => key; - const page = shallow(); - expect(page.find('h1').text()).toEqual('backup-account.title'); - }); -}); diff --git a/web-ui/test/test-main.js b/web-ui/test/test-main.js index b7dc430f..4396993f 100644 --- a/web-ui/test/test-main.js +++ b/web-ui/test/test-main.js @@ -1,7 +1,7 @@ var tests = Object.keys(window.__karma__.files).filter(function (file) { 'use strict'; - return !(/account_recovery/.test(file)) && (/\.spec\.js$/.test(file)); + return (/\.spec\.js$/.test(file)); }); beforeEach(function() { diff --git a/web-ui/test/unit/account_recovery/page.spec.js b/web-ui/test/unit/account_recovery/page.spec.js new file mode 100644 index 00000000..151f09e1 --- /dev/null +++ b/web-ui/test/unit/account_recovery/page.spec.js @@ -0,0 +1,12 @@ +import { shallow } from 'enzyme' +import expect from 'expect' +import React from 'react' +import { Page } from 'src/account_recovery/page' + +describe('Page', () => { + it('renders backup email page title', () => { + const mockT = key => key; + const page = shallow(); + expect(page.find('h1').text()).toEqual('backup-account.title'); + }); +}); diff --git a/web-ui/webpack.config.js b/web-ui/webpack.config.js index 5886154a..9171b8f5 100644 --- a/web-ui/webpack.config.js +++ b/web-ui/webpack.config.js @@ -7,7 +7,7 @@ var aliases = require('./config/alias-webpack'); module.exports = { entry: { app: './app/js/index.js', - account_recovery: './app/js/account_recovery.js', + account_recovery: './src/account_recovery/account_recovery.js', sandbox: './app/js/sandbox.js' }, node: { fs: 'empty' }, diff --git a/web-ui/webpack.production.config.js b/web-ui/webpack.production.config.js index cf8ab8ff..6948d78e 100644 --- a/web-ui/webpack.production.config.js +++ b/web-ui/webpack.production.config.js @@ -7,7 +7,7 @@ var aliases = require('./config/alias-webpack'); module.exports = { entry: { app: './app/js/index.js', - account_recovery: './app/js/account_recovery.js', + account_recovery: './src/account_recovery/index.js', sandbox: './app/js/sandbox.js' }, node: { fs: 'empty' }, -- cgit v1.2.3