Skip to content

Commit

Permalink
Fix/console warnings (#9)
Browse files Browse the repository at this point in the history
* Remove unused scripts from index.html

- Remove ONS JS & Jquery

* Fix key error in SummaryTable

* Fix role in reducer and node server

- Add 'role' back into login reducer
- Fix role returns in utils/auth.js
- Add role return into checkToken route in the node server

* Fix console warnings

- Unused imports etc.

* Fix propTypes errors

- Mostly related to the value prop

* Fix propType errors for ShowConfetti

* Add fix for IndustryCode inputs

- Use encoded square brackets

* Add fixes for industry code & refs bugs

- Fix use of industry code conversion
- Fix max number of refs not showing (bug in reduce function)
  • Loading branch information
ONS-Tom authored Nov 14, 2017
1 parent a8a5bfc commit 00270e5
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 27 deletions.
3 changes: 0 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,4 @@
To create a production bundle, use `npm run build`.
-->
</body>
<script src="https://cdn.ons.gov.uk/sixteens/1f354a7/js/main.js"></script>
<!-- There is an error in the script above, r.doubleTapToGo is not a function -->
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</html>
6 changes: 5 additions & 1 deletion server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ app.post('/checkToken', (req, res) => {
if (sessions[accessToken]) {
logger.info('Valid token');
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ username: sessions[accessToken].username, accessToken }));
res.send(JSON.stringify({
username: sessions[accessToken].username,
accessToken,
role: sessions[accessToken].role
}));
} else {
logger.info('Invalid token');
res.sendStatus(401);
Expand Down
1 change: 1 addition & 0 deletions src/actions/LoginActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export function checkAuth(username, token) {
dispatch(setUserState({
username: data.username,
accessToken: data.newAccessToken,
role: data.role,
}));
sessionStorage.setItem('accessToken', data.newAccessToken);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/CheckBoxInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CheckBoxInput.propTypes = {
id: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
onChangeFilter: PropTypes.func.isRequired,
value: PropTypes.string.isRequired,
value: PropTypes.bool.isRequired,
};

export default CheckBoxInput;
7 changes: 5 additions & 2 deletions src/components/ChildRefTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class ChildRefTable extends React.Component {
this.setState({ error: false, errorMessage: '' });
}
render() {
const business = this.props.row.original;
const description = (industryCodeDescription[business.industryCode] === undefined)
? 'No industry code description found' : industryCodeDescription[business.industryCode];
return (
<div style={{ padding: '20px' }}>
<ReactTable
Expand All @@ -66,13 +69,13 @@ class ChildRefTable extends React.Component {
accessor: 'payeRefs',
},
]}
defaultPageSize={1}
pageSize={this.state.data.length}
loading={this.state.isLoading}
className="-striped -highlight"
showPaginationTop={false}
showPaginationBottom={false}
/>
<h3>Industry Code: {industryCodeDescription[this.state.data.industryCode]}</h3>
<h4>Industry Code [{business.industryCode}]: {description}</h4>
<ErrorModal
show={this.state.error}
message={this.state.errorMessage}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Confetti.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ShowConfetti extends React.Component {
return (
<div>
{(this.state.count < (this.props.seconds / 0.25) && this.props.showConfetti) &&
<Confetti opacity={this.state.opacity} width={`${window.innerWidth}px`} height={`${window.innerHeight}px`} />
<Confetti opacity={this.state.opacity} width={window.innerWidth-100} height={window.innerHeight} />
}
</div>
);
Expand Down
2 changes: 0 additions & 2 deletions src/components/RangeForm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Button } from 'registers-react-library';
import Select from 'react-select';
import 'react-select/dist/react-select.min.css';
import { employmentBands, legalStatusBands, turnoverBands, tradingStatusBands } from '../utils/convertBands';
import TextInput from './TextInput';
import CheckBoxInput from './CheckBoxInput';
Expand Down
6 changes: 5 additions & 1 deletion src/components/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ const SelectInput = ({ id, label, bands, onChange, value }) => {
);
};

SelectInput.defaultProps = {
value: '',
};

SelectInput.propTypes = {
id: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
bands: PropTypes.object.isRequired,
value: PropTypes.string.isRequired,
value: PropTypes.string,
};

export default SelectInput;
6 changes: 5 additions & 1 deletion src/components/SelectMultipleInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ class SelectMultipleInput extends React.Component {
}
}

SelectMultipleInput.defaultProps = {
value: undefined,
};

SelectMultipleInput.propTypes = {
id: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
bands: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
value: PropTypes.array.isRequired,
value: PropTypes.array,
};

export default SelectMultipleInput;
2 changes: 1 addition & 1 deletion src/components/SummaryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const SummaryTable = ({ title, items }) => {
{
items.map((item) => {
return (
<div className="summary__items">
<div key={item.key} className="summary__items">
<div className="summary__question" id="">
{item.key}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ class TextInput extends React.Component {

TextInput.defaultProps = {
autoFocus: false,
value: '',
};

TextInput.propTypes = {
id: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
autoFocus: PropTypes.bool.isRequired,
value: PropTypes.string.isRequired,
value: PropTypes.string,
};

export default TextInput;
6 changes: 5 additions & 1 deletion src/components/TextInputInline.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ class TextInputInline extends React.Component {
}
}

TextInputInline.defaultProps = {
value: undefined,
};

TextInputInline.propTypes = {
onChange: PropTypes.func.isRequired,
autoFocus: PropTypes.bool.isRequired,
id: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
placeholderMin: PropTypes.string.isRequired,
placeholderMax: PropTypes.string.isRequired,
value: PropTypes.arr,
value: PropTypes.array,
};

export default TextInputInline;
8 changes: 4 additions & 4 deletions src/utils/auth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @flow

import config from '../config/api-urls';
import base64 from 'base-64';

const { AUTH_URL } = config;

Expand Down Expand Up @@ -35,10 +34,11 @@ const auth = {
const loginName: string = json.username;
const accessToken: string = json.accessToken;
const showConfetti: string = json.showConfetti;
const role: string = json.role;
// const role: string = json.role;
// sessionStorage.setItem('token', token);
// Send auth request to save token username pair
callback(true, { username: loginName, accessToken, showConfetti });
callback(true, { username: loginName, accessToken, showConfetti, role });
});
}
return callback(false, { message: 'Unable to login.' });
Expand All @@ -59,9 +59,9 @@ const auth = {
return response.json().then((json) => {
const newAccessToken: string = json.accessToken;
const username: string = json.username;
// const role: string = json.role;
const role: string = json.role;
// Send auth request to save token username pair
callback(true, { username, newAccessToken });
callback(true, { username, newAccessToken, role });
});
}
return callback(false);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/formQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function formRangeQuery(query) {
const queryArr = Object.keys(query).map(param => {
if (param === 'IndustryCode') {
// ES format: IndustryCode:[${min} TO ${max}]
return `${param}${SEPERATOR}[${query[param][0]} TO ${query[param][1]}]`;
return `${param}${SEPERATOR}%5B1${query[param][0]} TO ${query[param][1]}%5D`;
} else if (param === 'PostCode') {
// ES format: PostCode:(${postCode})
return `${param}${SEPERATOR}(${query[param]})`;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/helperMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ export function getLegalStatusDescription(status: string) {
}

export function maxSize(...args) {
return args.reduce((a, b) => (a > b ? a.length : b.length), 0);
return args.reduce((a, b) => (b.length > a ? b.length : a), 0);
}

export function formatData(business: {}) {
const largestRef = maxSize(business.vatRefs, business.payeRefs);
const formattedData = [];
for (let i = 0; i <= largestRef; i += 1) {
for (let i = 0; i <= largestRef - 1; i += 1) {
if (i === 0) {
formattedData.push({
companyNo: business.companyNo,
Expand Down
2 changes: 0 additions & 2 deletions src/views/Match.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import { TitleAndDescription, BreadCrumb } from 'registers-react-library';
import { connect } from 'react-redux';
import ReactTable from 'react-table';
import 'react-table/react-table.css';
import { matchSearch, setQuery, setResults } from '../actions/ApiActions';
import { SET_MATCH_QUERY, SET_MATCH_RESULTS } from '../constants/ApiConstants';
import ErrorModal from '../components/ErrorModal';
Expand Down
3 changes: 0 additions & 3 deletions src/views/UBRNLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import { SET_UBRN_QUERY, SET_UBRN_RESULTS } from '../constants/ApiConstants';
import ErrorModal from '../components/ErrorModal';
import UBRNForm from '../components/UBRNForm';
import { validateUBRNSearch } from '../utils/validation';
import config from '../config/validation';
import ResultsTable from '../components/ResultsTable';

const { UBRN } = config;

class UBRNLookup extends React.Component {
constructor(props) {
super(props);
Expand Down

0 comments on commit 00270e5

Please sign in to comment.