From 142fe0b61622415d34c7c4dea0fdb4ca4c332daa Mon Sep 17 00:00:00 2001 From: Alex Eng Date: Tue, 21 Jun 2016 15:55:10 +1000 Subject: [PATCH] fix(glossary): handle empty glossary (#1216) doc(frontend): Update readme.md for frontend and styleguide https://zanata.atlassian.net/browse/ZNTA-1183 --- frontend/README.md | 26 ++++++++++++++----- frontend/src/main/web/README.md | 22 ---------------- .../src/components/OverlayTrigger/index.jsx | 25 ++++++++++-------- .../src/main/web/src/reducers/glossary.js | 13 ++++++---- 4 files changed, 42 insertions(+), 44 deletions(-) delete mode 100644 frontend/src/main/web/README.md diff --git a/frontend/README.md b/frontend/README.md index 6e9c536aaa..b64dedf662 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -2,17 +2,25 @@ This module contains: User profile page, Glossary page, and Zanata side menu bar. -## To run in dev mode (need http://localhost:8080/zanata to run separately): +## To run/setup in nodeJS -Navigate to frontend/src/main/web and run +Navigate to `frontend/src/main/web`, run `npm install` -```npm install``` +### To run in dev mode http://localhost:8000 (a HTTP server to serve index.html with webpack produced bundle.js) -to install all dependencies. To start +- need http://localhost:8080/zanata to run separately +`npm start` -```npm start``` +### Production Build -## To build it just run +`npm run build` + +### Run styleguide + +`npm run styleguide-build` follow by `npm run styleguide-server` + + +## To generate a jar dependency ```mvn install``` @@ -37,3 +45,9 @@ If you activate profile ```-DnpmOffline``` the cache-min option will become 9999 Currently this module has been "shrinkwrapped" which means its npm module dependencies has been fixed to certain version. If you want to add or upgrade an individual version, you will need to consult [npm shrinkwrap documentation](https://docs.npmjs.com/cli/shrinkwrap#building-shrinkwrapped-packages) for detail instruction. Since we use maven to copy our source to target/ then run npm from maven, you will need to run above commands under target/ then copy the new npm-shrinkwrap.json file back to src/. + + +## Documentation + +For extensive details on each part of the front-end see the +[documentation](./src/main/web/docs). diff --git a/frontend/src/main/web/README.md b/frontend/src/main/web/README.md deleted file mode 100644 index 01cd61f6bc..0000000000 --- a/frontend/src/main/web/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# React Front-end - -## Setup - -`npm install` - -## Options - -### Production Build - -`npm run build` - -### Development Server - -#### (a HTTP server to serve index.html with webpack produced bundle.js) - -`npm start` - -## Documentation - -For extensive details on each part of the front-end see the -[documentation](./docs). diff --git a/frontend/src/main/web/src/components/OverlayTrigger/index.jsx b/frontend/src/main/web/src/components/OverlayTrigger/index.jsx index 7889855e7b..c3e806d86d 100644 --- a/frontend/src/main/web/src/components/OverlayTrigger/index.jsx +++ b/frontend/src/main/web/src/components/OverlayTrigger/index.jsx @@ -7,23 +7,26 @@ import callWithSameArgs from '../../utils/callWithSameArgs' import Overlay from '../Overlay' class OverlayTrigger extends Component { - state = { - isOverlayShown: this.props.defaultOverlayShown + constructor () { + super() + this.state = { + isOverlayShown: this.props.defaultOverlayShown + } } - show = () => { + show () { this.setState({ isOverlayShown: true }) } - hide = () => { + hide () { this.setState({ isOverlayShown: false }) } - toggle = () => { + toggle () { if (this.state.isOverlayShown) { this.hide() } else { @@ -36,17 +39,17 @@ class OverlayTrigger extends Component { * without resetting up all context. * See https://github.com/react-component/dialog/issues/10 */ - renderOverlay = () => { + renderOverlay () { ReactDOM.unstable_renderSubtreeIntoContainer( this, this._overlay, this._mountNode ) } - getOverlayTarget = () => { + getOverlayTarget () { return ReactDOM.findDOMNode(this) } - getOverlay = () => { + getOverlay () { const overlayProps = { ...pick(this.props, Object.keys(Overlay.propTypes)), show: this.state.isOverlayShown, @@ -72,7 +75,7 @@ class OverlayTrigger extends Component { ) } - handleDelayedShow = () => { + handleDelayedShow () { if (this.hoverHideTimeoutHandle !== undefined) { clearTimeout(this.hoverHideTimeoutHandle) this.hoverHideTimeoutHandle = undefined @@ -97,7 +100,7 @@ class OverlayTrigger extends Component { }, delay) } - handleDelayedHide = () => { + handleDelayedHide () { if (this._hoverShowDelay !== undefined) { clearTimeout(this._hoverShowDelay) this._hoverShowDelay = undefined @@ -126,7 +129,7 @@ class OverlayTrigger extends Component { // https://github.com/facebook/react/issues/4251 // for cases when the trigger is disabled and mouseOut/Over can // cause flicker moving from one child element to another. - handleMouseOverOut = (handler, e) => { + handleMouseOverOut (handler, e) { let target = e.currentTarget let related = e.relatedTarget || e.nativeEvent.toElement diff --git a/frontend/src/main/web/src/reducers/glossary.js b/frontend/src/main/web/src/reducers/glossary.js index 910623b203..e1d026deb7 100644 --- a/frontend/src/main/web/src/reducers/glossary.js +++ b/frontend/src/main/web/src/reducers/glossary.js @@ -239,15 +239,18 @@ const glossary = handleActions({ } }, [GLOSSARY_STATS_SUCCESS]: (state, action) => { + const transLocales = isEmpty(action.payload.transLocale) + ? [] + : action.payload.transLocale.map(result => ({ + value: result.locale.localeId, + label: result.locale.displayName, + count: result.numberOfTerms + })) return ({ ...state, stats: { srcLocale: action.payload.srcLocale, - transLocales: action.payload.transLocale.map(result => ({ - value: result.locale.localeId, - label: result.locale.displayName, - count: result.numberOfTerms - })) + transLocales: transLocales }, statsLoading: false })