Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/json fields update #47

Merged
merged 4 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/components/Business.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ class Business extends React.Component {
render = () => {
const ChildList = withChildSearch(ChildRefList);
const business = this.props.business;
const description = (industryCodeDescription[business.industryCode] === undefined)
? 'No industry code description found' : industryCodeDescription[business.industryCode];
const description = (industryCodeDescription[business.IndustryCode] === undefined)
? 'No industry code description found' : industryCodeDescription[business.IndustryCode];
return (
<div className="search-item-container">
<h3 className="saturn sml-margin">{(this.props.toHighlight !== '') ? getHighlightedText(business, this.props.toHighlight) : business.businessName}</h3>
<h3 className="saturn sml-margin">{(this.props.toHighlight !== '') ? getHighlightedText(business, this.props.toHighlight) : business.BusinessName}</h3>
<table className="mars">
<tbody>
<tr><th className="table-grey-text">UBRN</th><td>{business.id}</td></tr>
<tr><th className="table-grey-text">Post code</th><td>{business.postCode}</td></tr>
<tr><th className="table-grey-text">Industry</th><td>{business.industryCode} – {description}</td></tr>
<tr><th className="table-grey-text">Trading status</th><td>{tradingStatusBands[business.tradingStatus]}</td></tr>
<tr><th className="table-grey-text">Legal status</th><td>{legalStatusBands[business.legalStatus]}</td></tr>
<tr><th className="table-grey-text">Employment band</th><td>{employmentBands[business.employmentBands]}</td></tr>
<tr><th className="table-grey-text">Turnover band</th><td>{turnoverBands[business.turnover]}</td></tr>
<tr><th className="table-grey-text">Post code</th><td>{business.PostCode}</td></tr>
<tr><th className="table-grey-text">Industry</th><td>{business.IndustryCode} – {description}</td></tr>
<tr><th className="table-grey-text">Trading status</th><td>{tradingStatusBands[business.TradingStatus]}</td></tr>
<tr><th className="table-grey-text">Legal status</th><td>{legalStatusBands[business.LegalStatus]}</td></tr>
<tr><th className="table-grey-text">Employment band</th><td>{employmentBands[business.EmploymentBands]}</td></tr>
<tr><th className="table-grey-text">Turnover band</th><td>{turnoverBands[business.Turnover]}</td></tr>
</tbody>
</table>
<ChildList id={business.id} />
Expand Down
23 changes: 11 additions & 12 deletions src/components/ChildRefList.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ChildRefList = (props) => {
const toggle = document.getElementById(`${props.data.id}-toggleLink`);
toggle.style.transform = (toggle.style.transform === 'rotate(-90deg)') ? '' : 'rotate(-90deg)';
props.fetchData();
}
};
return (
<div id="outerExpand" className="guidance js-details">
<a className="mars" style={{ padding: '5px', cursor: 'pointer', backgroundColor: ((props.finishedLoading) ? '#4263c2' : ''), color: ((props.finishedLoading) ? 'white' : '') }} onClick={() => showRefs()}>
Expand All @@ -29,28 +29,27 @@ const ChildRefList = (props) => {
<div className="guidance__content new">
<table>
<tbody>
{(props.data.companyNo !== '') &&
<tr><th className="table-grey-text-reveal">CH</th><td>{props.createChLink(props.data.companyNo)}</td></tr>
}
{ props.data.vatRefs.map(v => {
return (<tr key={v}><th className="table-grey-text-reveal">VAT</th><td>{v}</td></tr>);
}) }
{ props.data.payeRefs.map(p => {
return (<tr key={p}><th className="table-grey-text-reveal">PAYE</th><td>{p}</td></tr>);
}) }
{(props.data.companyNo !== '') &&
<tr><th className="table-grey-text-reveal">CH</th><td>{props.createChLink(props.data.CompanyNo)}</td></tr>
}
{ props.data.VatRefs.map(v => {
return (<tr key={v}><th className="table-grey-text-reveal">VAT</th><td>{v}</td></tr>);
}) }
{ props.data.PayeRefs.map(p => {
return (<tr key={p}><th className="table-grey-text-reveal">PAYE</th><td>{p}</td></tr>);
}) }
</tbody>
</table>
</div>
}
</div>
</div>
);
}
};

ChildRefList.propTypes = {
error: PropTypes.bool.isRequired,
errorMessage: PropTypes.string.isRequired,
closeModal: PropTypes.func.isRequired,
data: PropTypes.object.isRequired,
finishedLoading: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired,
Expand Down
9 changes: 4 additions & 5 deletions src/components/ChildRefTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ class ChildRefTable extends React.Component {
columns={[
{
Header: 'Company Number',
accessor: 'companyNo',
accessor: 'CompanyNo',
Cell: row => (
<a target="_blank" rel="noopener noreferrer" href={`http://data.companieshouse.gov.uk/doc/company/${row.value}`}>{row.value}</a>
),
},
{
Header: 'VAT References',
accessor: 'vatRefs',
accessor: 'VatRefs',
},
{
Header: 'PAYE References',
accessor: 'payeRefs',
accessor: 'PayeRefs',
},
]}
pageSize={formattedData.length}
Expand All @@ -47,7 +47,7 @@ class ChildRefTable extends React.Component {
showPaginationBottom={false}
/>
<br />
<h4>Industry Code [{business.industryCode}]: {description}</h4>
<h4>Industry Code [{business.IndustryCode}]: {description}</h4>
<Panel id="refsErrorPanel" text={this.props.errorMessage} level="error" show={this.props.error} close={null} marginBottom="1rem" />
</div>
);
Expand All @@ -59,7 +59,6 @@ ChildRefTable.propTypes = {
isLoading: PropTypes.bool.isRequired,
error: PropTypes.bool.isRequired,
errorMessage: PropTypes.string.isRequired,
closeModal: PropTypes.func.isRequired,
fetchData: PropTypes.func.isRequired,
finishedLoading: PropTypes.bool.isRequired,
};
Expand Down
30 changes: 15 additions & 15 deletions src/components/ResultsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,45 @@ const ResultsTable = (props) => {
},
{
Header: 'Business Name',
id: 'businessName',
accessor: d => d.businessName,
Cell: row => ((props.toHighlight !== '') ? getHighlightedText({ businessName: row.value, id: row.id }, props.toHighlight) : row.value),
id: 'BusinessName',
accessor: d => d.BusinessName,
Cell: row => ((props.toHighlight !== '') ? getHighlightedText({ BusinessName: row.value, id: row.id }, props.toHighlight) : row.value),
width: 400,
},
{
Header: 'PostCode',
id: 'postCode',
accessor: d => d.postCode,
id: 'PostCode',
accessor: d => d.PostCode,
width: 110,
},
{
Header: 'SIC',
id: 'industryCode',
accessor: d => d.industryCode,
id: 'IndustryCode',
accessor: d => d.IndustryCode,
width: 75,
},
{
Header: 'Legal Status',
id: 'legalStatus',
accessor: d => ((props.convertBands) ? legalStatusBands[d.legalStatus] : d.legalStatus),
id: 'LegalStatus',
accessor: d => ((props.convertBands) ? legalStatusBands[d.LegalStatus] : d.LegalStatus),
width: 150,
},
{
Header: 'Trading Status',
id: 'tradingStatus',
accessor: d => ((props.convertBands) ? tradingStatusBands[d.tradingStatus] : d.tradingStatus),
id: 'TradingStatus',
accessor: d => ((props.convertBands) ? tradingStatusBands[d.TradingStatus] : d.TradingStatus),
width: 150,
},
{
Header: 'Turnover',
id: 'turnover',
accessor: d => ((props.convertBands) ? turnoverBands[d.turnover] : d.turnover),
id: 'Turnover',
accessor: d => ((props.convertBands) ? turnoverBands[d.Turnover] : d.Turnover),
width: 100,
},
{
Header: 'Employment',
id: 'employmentBands',
accessor: d => ((props.convertBands) ? employmentBands[d.employmentBands] : d.employmentBands),
id: 'RmploymentBands',
accessor: d => ((props.convertBands) ? employmentBands[d.EmploymentBands] : d.EmploymentBands),
width: 100,
},
]}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const transformBusiness = (business) => new Promise((resolve) => resolve(pipe(
* @return {string} A string of all the results in CSV format
*/
const formCSV = (header, results) => {
const cols = ['id', 'businessName', 'postCode', 'industryCode', 'legalStatus', 'tradingStatus', 'turnover', 'employmentBands', 'companyNo'];
const cols = ['id', 'BusinessName', 'PostCode', 'IndustryCode', 'LegalStatus', 'TradingStatus', 'Turnover', 'EmploymentBands', 'CompanyNo'];
const rows = results.map(
leu => cols.map(
col => ((leu[col] === undefined) ? '"",' : `"${leu[col]}",`), // Use empty string if no value present
Expand Down
26 changes: 13 additions & 13 deletions src/utils/helperMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const _pipe = (f, g) => (...args) => g(f(...args));
const pipe = (...fns) => fns.reduce(_pipe);

// Below are immutable transformations on a business object to convert the bands
const convertLegalStatus = (x) => ({ ...x, legalStatus: legalStatusBands[x.legalStatus] });
const convertTradingStatus = (x) => ({ ...x, tradingStatus: tradingStatusBands[x.tradingStatus] });
const convertTurnover = (x) => ({ ...x, turnover: turnoverBands[x.turnover] });
const convertEmploymentBands = (x) => ({ ...x, employmentBands: employmentBands[x.employmentBands] });
const convertLegalStatus = (x) => ({ ...x, LegalStatus: legalStatusBands[x.LegalStatus] });
const convertTradingStatus = (x) => ({ ...x, TradingStatus: tradingStatusBands[x.TradingStatus] });
const convertTurnover = (x) => ({ ...x, Turnover: turnoverBands[x.Turnover] });
const convertEmploymentBands = (x) => ({ ...x, EmploymentBands: employmentBands[x.EmploymentBands] });


/**
Expand Down Expand Up @@ -65,19 +65,19 @@ const numberWithCommas = (x) => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',
* @return {Array} - An array with an object for each table row
*/
const formatData = (business) => {
const largestRef = maxSize(business.vatRefs, business.payeRefs, [business.companyNo]);
const largestRef = maxSize(business.VatRefs, business.PayeRefs, [business.CompanyNo]);
return Array.from({ length: largestRef }, (a, b) => {
if (b === 0) {
return {
companyNo: (business.companyNo !== undefined) ? business.companyNo : '',
vatRefs: (business.vatRefs[b] !== undefined) ? business.vatRefs[b] : '',
payeRefs: (business.payeRefs[b] !== undefined) ? business.payeRefs[b] : '',
CompanyNo: (business.CompanyNo !== undefined) ? business.CompanyNo : '',
VatRefs: (business.VatRefs[b] !== undefined) ? business.VatRefs[b] : '',
PayeRefs: (business.PayeRefs[b] !== undefined) ? business.PayeRefs[b] : '',
};
}
return {
companyNo: '',
vatRefs: (business.vatRefs[b] !== undefined) ? business.vatRefs[b] : '',
payeRefs: (business.payeRefs[b] !== undefined) ? business.payeRefs[b] : '',
CompanyNo: '',
VatRefs: (business.VatRefs[b] !== undefined) ? business.VatRefs[b] : '',
PayeRefs: (business.PayeRefs[b] !== undefined) ? business.PayeRefs[b] : '',
};
});
};
Expand Down Expand Up @@ -152,7 +152,7 @@ const formSelectJson = (json) => Object.keys(json).map(key => ({ label: `${key}
const getHighlightedText = (row, higlight) => {
// Split text on higlight term, include term itself into parts, ignore case
try {
const parts = row.businessName.split(new RegExp(`(${higlight})`, 'gi'));
const parts = row.BusinessName.split(new RegExp(`(${higlight})`, 'gi'));
// We can use the array index as a key as we already use the UBRN as part of the key
/* eslint react/no-array-index-key: "off" */
return (
Expand All @@ -168,7 +168,7 @@ const getHighlightedText = (row, higlight) => {
</span>);
} catch (e) {
// Catch the invalid regular expressions
return (<em key={row.id}>{row.businessName}</em>);
return (<em key={row.id}>{row.BusinessName}</em>);
}
};

Expand Down
22 changes: 11 additions & 11 deletions src/utils/requestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ const randomArr = ({ length, lower = 10000, upper = 900000 }) => {
*/
const returnBusiness = () => ({
id: Math.floor(Math.random() * 900000000000) + 100000000000,
businessName: makeId(10),
uPRN: Math.floor(Math.random() * 900000000000) + 100000000000,
industryCode: Math.floor(Math.random() * 90000) + 10000,
legalStatus: Math.floor(Math.random() * 8) + 1,
tradingStatus: ['A', 'C', 'D', 'I'][Math.floor(Math.random() * 4) + 0],
turnover: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'][Math.floor(Math.random() * 9) + 0],
employmentBands: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'][Math.floor(Math.random() * 9) + 0],
postCode: `${makeId(4).toUpperCase()} ${makeId(3).toUpperCase()}`,
companyNo: makeId(8).toUpperCase(),
vatRefs: randomArr({ length: Math.floor(Math.random() * 6) + 0 }),
payeRefs: randomArr({ length: Math.floor(Math.random() * 6) + 0 }),
BusinessName: makeId(10),
UPRN: Math.floor(Math.random() * 900000000000) + 100000000000,
IndustryCode: Math.floor(Math.random() * 90000) + 10000,
LegalStatus: Math.floor(Math.random() * 8) + 1,
TradingStatus: ['A', 'C', 'D', 'I'][Math.floor(Math.random() * 4) + 0],
Turnover: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'][Math.floor(Math.random() * 9) + 0],
EmploymentBands: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'][Math.floor(Math.random() * 9) + 0],
PostCode: `${makeId(4).toUpperCase()} ${makeId(3).toUpperCase()}`,
CompanyNo: makeId(8).toUpperCase(),
VatRefs: randomArr({ length: Math.floor(Math.random() * 6) + 0 }),
PayeRefs: randomArr({ length: Math.floor(Math.random() * 6) + 0 }),
});


Expand Down
34 changes: 17 additions & 17 deletions test/utils-spec/export-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("export.js test suite", () => {
// Check that businessName is present in the data
// We need to remove the padded double qoutes around each bit of data
results.forEach((business, i) => {
expect(business.businessName).toBe(splitCsvNoHeader[i].split(',')[1].replace(/['"]+/g, ''));
expect(business.BusinessName).toBe(splitCsvNoHeader[i].split(',')[1].replace(/['"]+/g, ''));
});

// Do a last check on the length to verify they are the same
Expand All @@ -28,26 +28,26 @@ describe("export.js test suite", () => {
it("converts the bands correctly", () => {
const business = {
id: '020541',
businessName: 'TEST GRILL LTD',
postCode: 'ID80 5QB',
industryCode: '86762',
legalStatus: '2',
tradingStatus: 'A',
turnover: 'A',
employmentBands: 'B',
companyNo: '2953156',
BusinessName: 'TEST GRILL LTD',
PostCode: 'ID80 5QB',
IndustryCode: '86762',
LegalStatus: '2',
TradingStatus: 'A',
Turnover: 'A',
EmploymentBands: 'B',
CompanyNo: '2953156',
}

const expected = [{
id: '020541',
businessName: 'TEST GRILL LTD',
postCode: 'ID80 5QB',
industryCode: '86762',
legalStatus: 'Sole Proprietor',
tradingStatus: 'Active',
turnover: '0-99',
employmentBands: '1',
companyNo: '2953156',
BusinessName: 'TEST GRILL LTD',
PostCode: 'ID80 5QB',
IndustryCode: '86762',
LegalStatus: 'Sole Proprietor',
TradingStatus: 'Active',
Turnover: '0-99',
EmploymentBands: '1',
CompanyNo: '2953156',
}];

Promise.all(convertBands([business])).then(result => {
Expand Down
Loading