From d43898e0eb9428c345508de8e06809be512bd2e4 Mon Sep 17 00:00:00 2001 From: Florian Cassayre Date: Wed, 7 Oct 2020 11:04:35 +0200 Subject: [PATCH] global: environment labeling --- .env | 1 + src/lib/authentication/pages/Login/Login.js | 4 ++ .../EnvironmentLabel/EnvironmentLabel.js | 64 ++++++++++++++++++ src/lib/components/EnvironmentLabel/index.js | 1 + src/lib/components/ILSMenu/ILSMenu.js | 65 ++++++++++++------- .../components/backoffice/Sidebar/Sidebar.js | 14 +++- src/lib/config/defaultConfig.js | 22 +++++++ 7 files changed, 146 insertions(+), 25 deletions(-) create mode 100644 src/lib/components/EnvironmentLabel/EnvironmentLabel.js create mode 100644 src/lib/components/EnvironmentLabel/index.js diff --git a/.env b/.env index 4c8528470..2d8efdb03 100644 --- a/.env +++ b/.env @@ -3,3 +3,4 @@ REACT_APP_INVENIO_VERSION=1.0.0a13 REACT_APP_INVENIO_UI_URL=https://localhost:5000 REACT_APP_INVENIO_REST_ENDPOINTS_BASE_URL=https://localhost:5000/api REACT_APP_OVERLAY_VERSION= +REACT_APP_ENV_NAME=dev diff --git a/src/lib/authentication/pages/Login/Login.js b/src/lib/authentication/pages/Login/Login.js index bad2140d8..479febdbb 100644 --- a/src/lib/authentication/pages/Login/Login.js +++ b/src/lib/authentication/pages/Login/Login.js @@ -1,4 +1,5 @@ import { parseParams } from '@authentication/utils'; +import { EnvironmentLabel } from '@components/EnvironmentLabel'; import { Notifications } from '@components/Notifications'; import { invenioConfig } from '@config'; import { goTo } from '@history'; @@ -154,6 +155,9 @@ const LoginLayout = ({ }} > + + + {showLogo && invenioConfig.APP.LOGO_SRC && ( )} diff --git a/src/lib/components/EnvironmentLabel/EnvironmentLabel.js b/src/lib/components/EnvironmentLabel/EnvironmentLabel.js new file mode 100644 index 000000000..c6dea2d09 --- /dev/null +++ b/src/lib/components/EnvironmentLabel/EnvironmentLabel.js @@ -0,0 +1,64 @@ +import { invenioConfig } from '@config'; +import React from 'react'; +import PropTypes from 'prop-types'; +import Overridable from 'react-overridable'; +import { Icon, Label } from 'semantic-ui-react'; +import _get from 'lodash/get'; + +const EnvironmentLabelLayout = ({ + text, + icon, + color, + pointing, + ...uiProps +}) => { + return ( + + ); +}; + +EnvironmentLabelLayout.propTypes = { + text: PropTypes.string.isRequired, + icon: PropTypes.string.isRequired, + color: PropTypes.string.isRequired, + pointing: PropTypes.string.isRequired, +}; + +const EnvironmentLabelComponent = ({ pointing, ...uiProps }) => { + const environment = process.env.REACT_APP_ENV_NAME; + const environmentConfig = invenioConfig.APP.environments.find( + env => env.name === environment + ); + const display = _get(environmentConfig, 'display'); + if (display) { + return ( + + ); + } else { + return null; + } +}; + +EnvironmentLabelComponent.propTypes = { + pointing: PropTypes.string.isRequired, +}; + +export const EnvironmentLabel = Overridable.component( + 'EnvironmentLabel', + EnvironmentLabelComponent +); diff --git a/src/lib/components/EnvironmentLabel/index.js b/src/lib/components/EnvironmentLabel/index.js new file mode 100644 index 000000000..511113cf7 --- /dev/null +++ b/src/lib/components/EnvironmentLabel/index.js @@ -0,0 +1 @@ +export { EnvironmentLabel } from './EnvironmentLabel'; diff --git a/src/lib/components/ILSMenu/ILSMenu.js b/src/lib/components/ILSMenu/ILSMenu.js index c2ee56cb6..d6779d162 100644 --- a/src/lib/components/ILSMenu/ILSMenu.js +++ b/src/lib/components/ILSMenu/ILSMenu.js @@ -1,5 +1,6 @@ import { RedirectToLoginButton } from '@authentication/components/RedirectToLoginButton'; import { authenticationService } from '@authentication/services/AuthenticationService'; +import { EnvironmentLabel } from '@components/EnvironmentLabel'; import { invenioConfig } from '@config'; import { BackOfficeRoutes, FrontSiteRoutes } from '@routes/urls'; import PropTypes from 'prop-types'; @@ -92,18 +93,26 @@ class ILSMenu extends Component { > - +
+ +
+
+ +
@@ -123,18 +132,26 @@ class ILSMenu extends Component { > - - {invenioConfig.APP.LOGO_SRC && ( - - Logo - - )} - +
+ + {invenioConfig.APP.LOGO_SRC && ( + + Logo + + )} + +
+
+ +
diff --git a/src/lib/components/backoffice/Sidebar/Sidebar.js b/src/lib/components/backoffice/Sidebar/Sidebar.js index 5682fa848..ecc2bd13a 100644 --- a/src/lib/components/backoffice/Sidebar/Sidebar.js +++ b/src/lib/components/backoffice/Sidebar/Sidebar.js @@ -1,5 +1,6 @@ import { AuthenticationGuard } from '@authentication/components/AuthenticationGuard'; import { authenticationService } from '@authentication/services/AuthenticationService'; +import { EnvironmentLabel } from '@components/EnvironmentLabel'; import { AcquisitionRoutes, BackOfficeRoutes, @@ -10,7 +11,15 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; import Overridable from 'react-overridable'; import { Link } from 'react-router-dom'; -import { Divider, Header, Icon, Label, List, Menu } from 'semantic-ui-react'; +import { + Container, + Divider, + Header, + Icon, + Label, + List, + Menu, +} from 'semantic-ui-react'; import AdminMenu from './AdminMenu'; class Sidebar extends Component { @@ -43,6 +52,9 @@ class Sidebar extends Component { return ( <> + + +
diff --git a/src/lib/config/defaultConfig.js b/src/lib/config/defaultConfig.js index c5a3b7c5d..0b2503925 100644 --- a/src/lib/config/defaultConfig.js +++ b/src/lib/config/defaultConfig.js @@ -38,6 +38,28 @@ export const APP_CONFIG = { { name: 'contact', route: '/contact', apiURL: '2' }, ], supportEmail: 'info@inveniosoftware.org', + environments: [ + { + name: 'dev', + display: { + text: 'Dev environment', + color: 'blue', + icon: 'code', + }, + }, + { + name: 'qa', + display: { + text: 'QA environment', + color: 'teal', + icon: 'camera', + }, + }, + { + name: 'production', + display: null, + }, + ], }; export const RECORDS_CONFIG = {