Skip to content

Commit

Permalink
Merge pull request #15 from KPMP/develop
Browse files Browse the repository at this point in the history
Prepare for Oct. 2019 release
  • Loading branch information
rlreamy authored Oct 31, 2019
2 parents 95c813b + 7809732 commit 87c936b
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build
build/*
node_modules
node_modules/*
.project
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"name": "libra-web",
"version": "1.0.0",
"version": "1.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"babel-polyfill": "^6.26.0",
"bootstrap-css-only": "^4.3.1",
"history": "^4.9.0",
"axios": "0.19.0",
"babel-polyfill": "6.26.0",
"bootstrap-css-only": "4.3.1",
"history": "4.10.1",
"kpmp-custom-react-scripts": "1.1.2",
"moment": "^2.24.0",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-ga": "^2.5.7",
"react-redux": "^5.1.1",
"react-router-dom": "^5.0.0",
"react-table": "^6.10.0",
"reactstrap": "^7.1.0",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
"moment": "2.24.0",
"prop-types": "15.7.2",
"react": "16.9.0",
"react-dom": "16.9.0",
"react-ga": "2.6.0",
"react-redux": "7.1.1",
"react-router-dom": "5.0.1",
"react-table": "6.10.3",
"reactstrap": "8.0.1",
"redux": "4.0.4",
"redux-thunk": "2.3.0"
},
"devDependencies": {
"node-sass-chokidar": "^1.3.4",
"npm-run-all": "^4.1.5"
"node-sass-chokidar": "1.3.5",
"npm-run-all": "4.1.5"
},
"scripts": {
"start-js": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" crossorigin="use-credentials"/>
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
9 changes: 6 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { Route, Switch, Router } from 'react-router-dom';
import ErrorBoundaryContainer from './components/Error/ErrorBoundaryContainer';
import Oops from './components/Error/Oops';
import PackageDashboardPageContainer from './components/PackageDashboard/PackageDashboardPageContainer';
import PermissionDenied from './components/Error/PermissionDenied';
import NotRegistered from './components/Error/NotRegistered';

const cacheStore = window.sessionStorage.getItem('redux-store');
const initialState = cacheStore ? JSON.parse(cacheStore) : loadedState;
Expand All @@ -28,7 +30,6 @@ const saveState = () => {
);
};

// *** Get a new tracking Id and add it here *** //
const GA_TRACKING_ID = 'UA-124331187-8';

if(process.env.NODE_ENV === 'production') {
Expand Down Expand Up @@ -62,8 +63,10 @@ class App extends Component {
<ErrorBoundaryContainer>
<NavBar />
<Switch>
<Route exact path="/" component={PackageDashboardPageContainer} store={store} />
<Route exact path="/oops" component={Oops} />
<Route exact path="/" component={PackageDashboardPageContainer} store={store} />
<Route exact path="/oops" component={Oops} />
<Route exact path="/permissionDenied" component={PermissionDenied} />
<Route exact path="/notRegistered" component={NotRegistered} />
</Switch>
<NavFooter />
</ErrorBoundaryContainer>
Expand Down
58 changes: 35 additions & 23 deletions src/actions/Error/errorActions.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
//import Api from '../../helpers/Api';

//const api = Api.getInstance();

export const handleError = () => {
return dispatch => {
window.location.href = '/oops';
};
};

export const sendMessageToBackend = error => {
let errorMessage = { error: error.message, stackTrace: error.stack };
console.log(errorMessage);
handleError();

// Uncomment this section once you have an api to send errors to
// return (dispatch) => {
// api.post('/api/v1/error', errorMessage)
// .then(res=> {
// dispatch(handleError());
// });
// };
};
import Api from '../../helpers/Api';

const api = Api.getInstance();

export const handleError = (statusCode) => {
return (dispatch) => {
if (statusCode === 404) {
window.location.href = "/notRegistered";
} else if (statusCode === 403) {
window.location.href = "/permissionDenied"
} else {
window.location.href = "/oops";
}
}
};

export const sendMessageToBackend = (error) => {

if (error.response && error.response.status && error.response.status >= 400) {
return (dispatch) => {
let href = window.location.href;
if (!href.includes("/oops") && !href.includes("/permissionDenied") && !href.includes("/notRegistered")) {
dispatch(handleError(error.response.status));
}
}
} else {
let errorMessage = { error: error.message , stackTrace: error.stack }
return (dispatch) => {
api.post('/api/v1/error', errorMessage)
.then(res=> {
dispatch(handleError(error.response.status));
});
};
}
}
4 changes: 2 additions & 2 deletions src/actions/Packages/packageActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import actionNames from '../actionNames';
import Api from '../../helpers/Api';
import { handleError } from '../Error/errorActions';
import { sendMessageToBackend } from '../Error/errorActions';

const api = Api.getInstance();

Expand All @@ -11,7 +11,7 @@ export const getPackages = () => {
dispatch(setPackages(res.data));
})
.catch(err => {
dispatch(handleError("Unable to connect to the Data Lake: " + err));
dispatch(sendMessageToBackend(err));
});
};
}
Expand Down
27 changes: 27 additions & 0 deletions src/components/Error/NotRegistered.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { Component } from 'react';
import { Col, Row } from 'reactstrap';

class NotRegistered extends Component {

render() {
return (
<article className="container justify-content-center pt-3">
<Row >
<Col xs={12} className="error-header pb-3">
We're sorry. You are not authorized to access this application.
</Col>
</Row>
<Row>
<Col xs={12}>
<div className="alert alert-danger">
You must be a registered user in order to use this KPMP application. If you would like to register or believe you received this page in error, please contact: &nbsp;
<a href="mailto:[email protected]">[email protected]</a>
</div>
</Col>
</Row>
</article>
);
}
}

export default NotRegistered;
27 changes: 27 additions & 0 deletions src/components/Error/PermissionDenied.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { Component } from 'react';
import { Col, Row } from 'reactstrap';

class PermissionDenied extends Component {

render() {
return (
<article className="container justify-content-center pt-3">
<Row >
<Col xs={12} className="error-header pb-3">
We're sorry. You are not authorized to access this application.
</Col>
</Row>
<Row>
<Col xs={12}>
<div className="alert alert-danger">
Your account does not have permission to use this KPMP application. If you believe you received this page in error, please contact: &nbsp;
<a href="mailto:[email protected]">[email protected]</a>
</div>
</Col>
</Row>
</article>
);
}
}

export default PermissionDenied;
26 changes: 20 additions & 6 deletions src/components/PackageDashboard/PackageTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ import ReactTable from 'react-table';
import ReactGA from 'react-ga';
import PropTypes from 'prop-types';
import Moment from 'moment';
import stateMap from './stateMap';

const PACKAGE_ID_LABEL = "Package ID";
const PACKAGE_TYPE_LABEL = "Package Type";
const SUBMITTER_LABEL = "Submitter";
const TIS_NAME_LABEL = "TIS Name";
const DATE_SUBMITTED_LABEL = "Date Submitted";
const PACKAGE_STATE_LABEL = "Package State";

const PACKAGE_ID = "packageId";
const PACKAGE_ID = "_id";
const SUBMITTER_ID = "displayName";
const SUBMITTER_FIRST_NAME = "firstName";
const SUBMITTER_LAST_NAME = "lastName";
const PACKAGE_TYPE_ID = "packageType";
const TIS_NAME_ID = "tisName";
const DATE_SUBMITTED_ID = "createdAt";
const DATE_FORMAT = "YYYY-MM-DD, h:mm a z";
const PACKAGE_INFO_PROPERTY = "packageInfo";
const PACKAGE_STATE_ID = "state";

// package id, submitter, package type, tis name, date submitted
class PackageTable extends Component {
Expand All @@ -44,32 +48,42 @@ class PackageTable extends Component {
{
Header: PACKAGE_ID_LABEL,
id: PACKAGE_ID,
accessor: (row) => row[PACKAGE_ID]
accessor: (row) => row[PACKAGE_INFO_PROPERTY][PACKAGE_ID]
},
{
Header: PACKAGE_TYPE_LABEL,
id: PACKAGE_TYPE_ID,
accessor: (row) => row[PACKAGE_TYPE_ID]
accessor: (row) => row[PACKAGE_INFO_PROPERTY][PACKAGE_TYPE_ID]
},
{
Header: SUBMITTER_LABEL,
id: SUBMITTER_ID,
accessor: (row) => row.submitter && row.submitter[SUBMITTER_ID] ? row.submitter[SUBMITTER_ID] : row.submitter[SUBMITTER_FIRST_NAME] + " " + row.submitter[SUBMITTER_LAST_NAME]
accessor: (row) => row[PACKAGE_INFO_PROPERTY].submitter && row[PACKAGE_INFO_PROPERTY].submitter[SUBMITTER_ID] ? row[PACKAGE_INFO_PROPERTY].submitter[SUBMITTER_ID] : row[PACKAGE_INFO_PROPERTY].submitter[SUBMITTER_FIRST_NAME] + " " + row[PACKAGE_INFO_PROPERTY].submitter[SUBMITTER_LAST_NAME]
},
{
Header: TIS_NAME_LABEL,
id: TIS_NAME_ID,
accessor: (row) => row[TIS_NAME_ID]
accessor: (row) => row[PACKAGE_INFO_PROPERTY][TIS_NAME_ID]
},
{
Header: DATE_SUBMITTED_LABEL,
id: DATE_SUBMITTED_ID,
accessor: (row) => {

return new Moment(row[DATE_SUBMITTED_ID])
return new Moment(row[PACKAGE_INFO_PROPERTY][DATE_SUBMITTED_ID])
.local()
.format(DATE_FORMAT)
}
},
{
Header: PACKAGE_STATE_LABEL,
id: PACKAGE_STATE_ID,
accessor: (row) => {
if (row.state && row.state[PACKAGE_STATE_ID]) {
return stateMap.has(row.state[PACKAGE_STATE_ID]) ? stateMap.get(row.state[PACKAGE_STATE_ID]) : row.state[PACKAGE_STATE_ID];
}
return ""
}
}
];
}
Expand Down
10 changes: 10 additions & 0 deletions src/components/PackageDashboard/stateMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const stateMap = new Map(
[
["METADATA_RECEIVED", "Waiting for files"],
["UPLOAD_SUCCEEDED", "Ready for review"],
["FILES_RECEIVED", "Finishing upload"],
["UPLOAD_STARTED", "Upload started"]
]
);

export default stateMap;
2 changes: 1 addition & 1 deletion src/helpers/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class Api {

constructor() {
this.axios = axios.create({
timeout: 10000,
timeout: 15000,
});
}

Expand Down

0 comments on commit 87c936b

Please sign in to comment.