Skip to content

Commit

Permalink
2354 env banner (beyondessential#3192)
Browse files Browse the repository at this point in the history
* add env banner

* Update EnvBanner.js

* change color

* Update EnvBanner.js

* add branch to env

* add env banner to ui components

* add env banner to lesmis, psss and tupaia

* move branch name to component
  • Loading branch information
tcaiger authored Sep 12, 2021
1 parent ccd53fd commit dbde490
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/admin-panel/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, { lazy, Suspense } from 'react';
import { BrowserRouter as Router, Route, Switch, Redirect } from 'react-router-dom';
import { render as renderReactApp } from 'react-dom';
import 'react-table/react-table.css';
import { EnvBanner } from '@tupaia/ui-components';
import AdminPanel from './App';
import { AdminPanelProviders, VizBuilderProviders } from './utilities';
import { Footer, Navbar } from './widgets';
Expand All @@ -15,6 +16,7 @@ const VizBuilder = lazy(() => import('./VizBuilderApp'));
renderReactApp(
<Router>
<Suspense fallback={<div>loading...</div>}>
<EnvBanner />
<Switch>
<Route path="/viz-builder">
<VizBuilderProviders>
Expand Down
2 changes: 1 addition & 1 deletion packages/devops/scripts/ci/deployFrontend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DEPLOYMENT_SSH_URL=$(${DIR}/determineDeploymentSshUrl.sh)
DEPLOYMENT_URL=$DEPLOYMENT_SSH_URL # ssh url will resolve to tupaia web frontend desktop over HTTP
if curl --output /dev/null --silent --head --fail $DEPLOYMENT_URL; then
echo "Deployment for ${CI_BRANCH} exists, updating with latest changes"
ssh -o ServerAliveInterval=15 ubuntu@$DEPLOYMENT_SSH_URL "cd tupaia; yarn workspace @tupaia/${PACKAGE} build"
ssh -o ServerAliveInterval=15 ubuntu@$DEPLOYMENT_SSH_URL "cd tupaia;REACT_APP_BRANCH=${CI_BRANCH} yarn workspace @tupaia/${PACKAGE} build"
else
echo "No deployment exists for ${CI_BRANCH}, cancelling update"
fi
2 changes: 2 additions & 0 deletions packages/lesmis/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import React from 'react';
import { render as renderReactApp } from 'react-dom';
import { ReactQueryDevtools } from 'react-query/devtools';
import { EnvBanner } from '@tupaia/ui-components';
import { App } from './App';
import { AppProviders } from './AppProviders';

const render = () => {
return renderReactApp(
<AppProviders>
<ReactQueryDevtools />
<EnvBanner />
<App />
</AppProviders>,
document.getElementById('root'),
Expand Down
2 changes: 2 additions & 0 deletions packages/psss/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import React from 'react';
import { render as renderReactApp } from 'react-dom';
import { ReactQueryDevtools } from 'react-query-devtools';
import { EnvBanner } from '@tupaia/ui-components';
import App from './App';
import { AppProviders } from './AppProviders';
import { store } from './store/store';
Expand All @@ -13,6 +14,7 @@ const render = () => {
return renderReactApp(
<AppProviders store={store}>
<ReactQueryDevtools />
<EnvBanner />
<App />
</AppProviders>,
document.getElementById('root'),
Expand Down
47 changes: 47 additions & 0 deletions packages/ui-components/src/components/EnvBanner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*
*/
import React from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import GitHubIcon from '@material-ui/icons/GitHub';
import { FlexCenter } from './Layout';

const StyledBanner = styled(FlexCenter)`
background: ${props => props.$color};
color: white;
font-size: 13px;
font-weight: 500;
padding: 12px;
text-align: center;
.MuiSvgIcon-root {
font-size: 16px;
margin-right: 0.4rem;
}
`;

export const EnvBanner = ({ color }) => {
const branch = process.env.REACT_APP_BRANCH;

if (!branch || typeof branch !== 'string' || branch === 'master' || branch === 'main') {
return null;
}

return (
<StyledBanner $color={color}>
<GitHubIcon />
{branch}
</StyledBanner>
);
};

EnvBanner.propTypes = {
color: PropTypes.string,
};

EnvBanner.defaultProps = {
color: '#f39c12',
};
1 change: 1 addition & 0 deletions packages/ui-components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './components/ConfirmDeleteModal';
export * from './components/DataTable';
export * from './components/DateRangePicker';
export * from './components/Dialog';
export * from './components/EnvBanner';
export * from './components/ErrorBoundary';
export * from './components/FetchLoader';
export * from './components/FullPageLoader';
Expand Down
6 changes: 4 additions & 2 deletions packages/web-frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import React, { lazy, Suspense } from 'react';
import { Provider } from 'react-redux';
import { EnvBanner } from '@tupaia/ui-components';

import configureStore from './configureStore';
import { AppStyleProviders } from './AppStyleProviders';
Expand All @@ -19,8 +20,6 @@ const { dispatch } = store;

initHistoryDispatcher(store);

const appType = process.env.REACT_APP_APP_TYPE;

const initApp = () => {
dispatch({
type: FETCH_INITIAL_DATA,
Expand All @@ -29,6 +28,8 @@ const initApp = () => {

initApp();

const appType = process.env.REACT_APP_APP_TYPE;

const App = () => {
let RootScreen = DesktopApp;

Expand All @@ -40,6 +41,7 @@ const App = () => {
<Provider store={store}>
<AppStyleProviders>
<Suspense fallback={null}>
<EnvBanner />
<RootScreen />
</Suspense>
</AppStyleProviders>
Expand Down

0 comments on commit dbde490

Please sign in to comment.