diff --git a/src/actions/serverInfo.ts b/src/actions/serverInfo.ts index b08caa25c0b655919a28d47f10424db513acc6b4..ba8ca041451373d7b6f521ccecd7806c275f720c 100644 --- a/src/actions/serverInfo.ts +++ b/src/actions/serverInfo.ts @@ -1,22 +1,17 @@ import * as Constants from 'constants/serverInfo'; -import {InfoService} from 'service/InfoService'; import {log} from 'utilities/debug'; +import {InfoService} from 'service/InfoService'; +import {ServerInfo} from 'model/serverinfo.model'; -function serverInfoRequest() { - return (dispatch, getState) => { - const token = getState().login.access_token; - - return InfoService.getServerInfo(token) - .then((data) => dispatch(getServerInfo(data))) - .catch((error) => log('Error', error)); - }; -} +export const serverInfoRequest = () => (dispatch, getState): Promise => { + const token = getState().login.access_token; -function getServerInfo(info) { - return { - type: Constants.GET_SERVER_INFO, - info, - }; -} + return InfoService.getServerInfo(token) + .then((data) => dispatch(getServerInfo(data))) + .catch((error) => log('Error', error)); +}; -export {serverInfoRequest, getServerInfo}; +const getServerInfo = (info: ServerInfo) => ({ + type: Constants.GET_SERVER_INFO, + payload: { info }, +}); diff --git a/src/constants/apiURLS.ts b/src/constants/apiURLS.ts index 99bb2371a5660f21157a9891830496f89380334a..d6d037fa1e186b778306f7119e34637fb510d4a3 100644 --- a/src/constants/apiURLS.ts +++ b/src/constants/apiURLS.ts @@ -9,7 +9,7 @@ export const VERIFY_GOOGLE_TOKEN_URL = `${API_ROOT}/google/verify-token`; export const APIv0_BASE_URL = `${API_ROOT}/api/v0`; export const APIv1_BASE_URL = `${API_ROOT}/api/v1`; -export const SERVER_INFO_URL = `${APIv0_BASE_URL}/info/version`; +export const SERVER_INFO_URL = `${APIv1_BASE_URL}/info/version`; // Me API const ME_API = `${APIv0_BASE_URL}/me`; diff --git a/src/model/serverinfo.model.ts b/src/model/serverinfo.model.ts index 6045944c6e372f8dc5fca0f3135f26bb83fcc051..3210607ba8a78ec14da48ae33ce99c91e1f35b7f 100644 --- a/src/model/serverinfo.model.ts +++ b/src/model/serverinfo.model.ts @@ -4,6 +4,14 @@ class ServerInfo { public revision: string; public hostName: string; + public cdnServers: string; + public accessionCount: number; + public datasetCount: number; + public subsetCount: number; + public instituteCount: number; + public descriptorCount: number; + public partnerCount: number; + public constructor(obj?) { if (obj !== null && obj !== undefined) { Object.keys(obj).forEach((p) => this[p] = obj[p]); diff --git a/src/reducers/serverInfo.ts b/src/reducers/serverInfo.ts index 58c900a238d004d758959224ccb623106e6a1483..3db6cbc9bd17304c67afe4910aad22af352ddbc8 100644 --- a/src/reducers/serverInfo.ts +++ b/src/reducers/serverInfo.ts @@ -1,18 +1,16 @@ import {GET_SERVER_INFO} from 'constants/serverInfo'; -import {ServerInfo} from 'model/serverinfo.model'; +import {IReducerAction} from 'model/common.model'; const INITIAL_STATE = {}; -function serverInfo(state = INITIAL_STATE, action: { type?: string, info?: ServerInfo } = { type: '' }) { - const {type, info} = action; +export default function serverInfo(state = INITIAL_STATE, action: IReducerAction = {type: ''}) { - switch (type) { - case GET_SERVER_INFO: + switch (action.type) { + case GET_SERVER_INFO: { + const {info} = action.payload; return {...info}; - + } default: return state; } } - -export default serverInfo; diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 8bdd6514d6e48e5125aaf20133d890c331923f5b..3258e7ddd717740b47d5f6ab9967f9418e973484 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -6,6 +6,7 @@ import {logoutRequest, loginAppRequest} from 'actions/login'; import {setAppMounted} from 'actions/appMounted'; import {updateHistory} from 'actions/history'; import { listCrops } from 'actions/crop'; +import { serverInfoRequest } from 'actions/serverInfo'; import { withRouter } from 'react-router-dom'; @@ -31,12 +32,15 @@ interface IAppProps extends React.ClassAttributes { updateHistory: (path: string) => void; crops: Crop[]; listCrops: () => void; + serverInfo: any; + serverInfoRequest: any; } class App extends React.Component { public static needs = [ () => listCrops(), + () => serverInfoRequest(), ]; public constructor(props: any) { @@ -44,10 +48,14 @@ class App extends React.Component { } public componentWillMount() { - const { crops, listCrops } = this.props; + const { crops, listCrops, serverInfo, serverInfoRequest } = this.props; if (!crops || crops.length === 0) { listCrops(); } + if (! serverInfo || ! serverInfo.revision) { + console.log('Requesting server info because we have:', serverInfo); + serverInfoRequest(); + } } public componentWillReceiveProps(nextProps) { @@ -74,6 +82,7 @@ class App extends React.Component { const mapStateToProps = (state) => ({ crops: state.crop.list, + serverInfo: state.serverInfo, // accessToken: state.login.access_token, }); @@ -83,6 +92,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({ setAppMounted, updateHistory, listCrops, + serverInfoRequest, }, dispatch); export default withRouter(connect(mapStateToProps, mapDispatchToProps)(App)); diff --git a/src/ui/common/Number.tsx b/src/ui/common/Number.tsx index 6023466b5b869ec0eb2d94ff1f1a9ecabdefc8a3..dab6e0229ef0552d8334d8682d900e05716534ed 100644 --- a/src/ui/common/Number.tsx +++ b/src/ui/common/Number.tsx @@ -5,7 +5,7 @@ import * as React from 'react'; export default function Number({ value, }: { value: number }) { - if (value !== null) { + if (typeof value === 'number') { return { value.toLocaleString() }; } else { return ; diff --git a/src/ui/pages/welcome/index.tsx b/src/ui/pages/welcome/index.tsx index d41fa09ea7ba60204b598432379a1966d16dc961..fc0661d43b0865927fbc737c4781e7d2e160474b 100644 --- a/src/ui/pages/welcome/index.tsx +++ b/src/ui/pages/welcome/index.tsx @@ -7,6 +7,7 @@ import { translate } from 'react-i18next'; import { navigateTo } from 'actions/navigation'; import ContentHeader from 'ui/common/heading/ContentHeader'; +import Number from 'ui/common/Number'; import Grid from '@material-ui/core/Grid'; import Markdown from 'ui/catalog/markdown'; import { Link } from 'react-router-dom'; @@ -121,6 +122,9 @@ const styles = (theme) => ({ fontSize: '2.143rem', fontWeight: 'bold' as 'bold', color: '#fff', + [theme.breakpoints.down('md')]: { + fontSize: '1.4rem', + }, }, aboutBox: { position: 'relative' as 'relative', @@ -219,7 +223,7 @@ class WelcomePage extends React.Component { } public render() { - const { classes, t } = this.props; + const { classes, t, serverInfo } = this.props; const Stats = ({children}) => (
@@ -290,7 +294,7 @@ class WelcomePage extends React.Component { - 3.8M + { t('stats.Accessions') } @@ -298,7 +302,7 @@ class WelcomePage extends React.Component { - A few + { t('stats.Phenotypic datasets') } @@ -306,7 +310,7 @@ class WelcomePage extends React.Component { - 700+ + { t('stats.Descriptors') } @@ -314,7 +318,7 @@ class WelcomePage extends React.Component { - Some + { t('stats.Partners') } @@ -428,8 +432,12 @@ The Catalog of datasets enables genbanks around the World to share information o } } +const mapStateToProps = (state) => ({ + serverInfo: state.serverInfo, +}); + const mapDispatchToProps = (dispatch) => bindActionCreators({ navigateTo, }, dispatch); -export default translate()(connect(null, mapDispatchToProps)(withStyles(styles)(WelcomePage))); +export default translate()(connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(WelcomePage)));