This commit is contained in:
soupette 2018-04-12 23:45:17 +02:00
parent d3a82618b3
commit 87b5832a51
9 changed files with 76 additions and 18 deletions

View File

@ -6,6 +6,8 @@
import React from 'react';
import { defineMessages, FormattedMessage } from 'react-intl';
import { PropTypes } from 'prop-types';
import { take } from 'lodash';
import LocaleToggle from 'containers/LocaleToggle';
@ -13,15 +15,21 @@ import styles from './styles.scss';
import messages from './messages.json';
defineMessages(messages);
class LeftMenuFooter extends React.Component { // eslint-disable-line react/prefer-stateless-function
render() {
return (
<div className={styles.leftMenuFooter}>
<FormattedMessage {...messages.poweredBy} /> <a href="http://strapi.io" target="_blank">Strapi</a>
<LocaleToggle />
</div>
);
}
function LeftMenuFooter({ version }) { // eslint-disable-line react/prefer-stateless-function
const strapiV = take(`${version.split('.')[0]}${version.split('alpha')[1]}`, 4).join('');
return (
<div className={styles.leftMenuFooter}>
<FormattedMessage {...messages.poweredBy} />
<a href="http://strapi.io" target="_blank"> Strapi</a>
<span>&nbsp;(v{strapiV})</span>
<LocaleToggle />
</div>
);
}
LeftMenuFooter.propTypes = {
version: PropTypes.string.isRequired,
};
export default LeftMenuFooter;

View File

@ -8,6 +8,7 @@ import {
GET_GA_STATUS_SUCCEEDED,
GET_LAYOUT,
GET_LAYOUT_SUCCEEDED,
GET_STRAPI_VERSION_SUCCEEDED,
} from './constants';
export function getGaStatus() {
@ -35,3 +36,10 @@ export function getLayoutSucceeded(layout) {
layout,
};
}
export function getStrapiVersionSucceeded(strapiVersion) {
return {
type: GET_STRAPI_VERSION_SUCCEEDED,
strapiVersion,
};
}

View File

@ -8,3 +8,4 @@ export const GET_GA_STATUS = 'app/Admin/GET_GA_STATUS';
export const GET_GA_STATUS_SUCCEEDED = 'app/Admin/GET_GA_STATUS_SUCCEEDED';
export const GET_LAYOUT = 'app/Admin/GET_LAYOUT';
export const GET_LAYOUT_SUCCEEDED = 'app/Admin/GET_LAYOUT_SUCCEEDED';
export const GET_STRAPI_VERSION_SUCCEEDED = 'app/Admin/GET_STRAPI_VERSION_SUCCEEDED';

View File

@ -137,13 +137,19 @@ export class AdminPage extends React.Component { // eslint-disable-line react/pr
showLeftMenu = () => !includes(this.props.location.pathname, 'users-permissions/auth/');
render() {
const leftMenu = this.showLeftMenu() ? <LeftMenu plugins={this.props.plugins} layout={this.props.adminPage.layout} /> : '';
const { adminPage } = this.props;
const header = this.showLeftMenu() ? <Header /> : '';
const style = this.showLeftMenu() ? {} : { width: '100%' };
return (
<div className={styles.adminPage}>
{leftMenu}
{this.showLeftMenu() && (
<LeftMenu
plugins={this.props.plugins}
layout={adminPage.layout}
version={adminPage.strapiVersion}
/>
)}
{ auth.getToken() && this.props.hasUserPlugin && this.isUrlProtected(this.props) ? (
<Logout />
) : ''}

View File

@ -6,11 +6,16 @@
import { fromJS, Map } from 'immutable';
import { GET_GA_STATUS_SUCCEEDED, GET_LAYOUT_SUCCEEDED } from './constants';
import {
GET_GA_STATUS_SUCCEEDED,
GET_LAYOUT_SUCCEEDED,
GET_STRAPI_VERSION_SUCCEEDED,
} from './constants';
const initialState = fromJS({
allowGa: true,
layout: Map({}),
strapiVersion: '3.0.0-alpha',
});
function adminPageReducer(state = initialState, action) {
@ -19,6 +24,8 @@ function adminPageReducer(state = initialState, action) {
return state.update('allowGa', () => action.allowGa);
case GET_LAYOUT_SUCCEEDED:
return state.update('layout', () => Map(action.layout));
case GET_STRAPI_VERSION_SUCCEEDED:
return state.update('strapiVersion', () => action.strapiVersion);
default:
return state;
}

View File

@ -1,13 +1,21 @@
import { fork, call, put, takeLatest } from 'redux-saga/effects';
import request from 'utils/request';
import { getGaStatusSucceeded, getLayoutSucceeded } from './actions';
import {
getGaStatusSucceeded,
getLayoutSucceeded,
getStrapiVersionSucceeded,
} from './actions';
import { GET_GA_STATUS, GET_LAYOUT } from './constants';
function* getGaStatus() {
try {
const response = yield call(request, '/admin/gaConfig', { method: 'GET' });
yield put(getGaStatusSucceeded(response.allowGa));
const [allowGa, strapiVersion] = yield [
call(request, '/admin/gaConfig', { method: 'GET' }),
call(request, '/admin/strapiVersion', { method: 'GET' }),
];
yield put(getGaStatusSucceeded(allowGa));
yield put(getStrapiVersionSucceeded(strapiVersion.strapiVersion));
} catch(err) {
strapi.notification.error('notification.error');
}

View File

@ -18,16 +18,21 @@ export class LeftMenu extends React.Component { // eslint-disable-line react/pre
render() {
return (
<div className={styles.leftMenu}>
<LeftMenuHeader></LeftMenuHeader>
<LeftMenuLinkContainer {...this.props}></LeftMenuLinkContainer>
<LeftMenuFooter plugins={this.props.plugins}></LeftMenuFooter>
<LeftMenuHeader />
<LeftMenuLinkContainer {...this.props} />
<LeftMenuFooter plugins={this.props.plugins} version={this.props.version} />
</div>
);
}
}
LeftMenu.defaultProps = {
version: '3.0.0-alpha',
};
LeftMenu.propTypes = {
plugins: PropTypes.object.isRequired,
version: PropTypes.string,
};
function mapDispatchToProps(dispatch) {

View File

@ -20,6 +20,12 @@
"handler": "Admin.getGaConfig",
"policies": []
},
{
"method": "GET",
"path": "/strapiVersion",
"handler": "Admin.getStrapiVersion",
"policies": []
},
{
"method": "GET",
"path": "/layout",

View File

@ -17,6 +17,15 @@ module.exports = {
}
},
getStrapiVersion: async ctx => {
try {
const strapiVersion = _.get(strapi.config, 'info.strapi', null);
return ctx.send({ strapiVersion });
} catch(err) {
return ctx.badRequest(null, [{ messages: [{ id: 'The version is not available' }] }]);
}
},
getGaConfig: async ctx => {
try {
const allowGa = _.get(strapi.config, 'info.customs.allowGa', true);