diff --git a/src/entity-search/EntityList.jsx b/src/entity-search/EntityList.jsx index b19aeff0..1d629a31 100644 --- a/src/entity-search/EntityList.jsx +++ b/src/entity-search/EntityList.jsx @@ -29,7 +29,7 @@ EntityList.propTypes = { PropTypes.shape({ id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, heading: PropTypes.string.isRequired, - meta: PropTypes.object.isRequired, + meta: PropTypes.array.isRequired, data: PropTypes.object.isRequired, }) ).isRequired, diff --git a/src/entity-search/EntityListItem.jsx b/src/entity-search/EntityListItem.jsx index b8339b88..1abdccb9 100644 --- a/src/entity-search/EntityListItem.jsx +++ b/src/entity-search/EntityListItem.jsx @@ -26,7 +26,7 @@ const StyledEntity = styled('div')` isClickable && ` cursor: pointer; - + h3 { color: ${LINK_COLOUR}; } @@ -34,7 +34,7 @@ const StyledEntity = styled('div')` &:hover { border: 1px solid ${LINK_HOVER_COLOUR}; background-color: ${GREY_4}; - + & > h3 { color: ${LINK_HOVER_COLOUR}; } @@ -57,12 +57,6 @@ const StyledInsetText = styled(InsetText)` ` const EntityListItem = ({ id, onEntityClick, data, text, heading, meta }) => { - const metaAsArray = isEmpty(meta) - ? null - : Object.keys(meta).map((key) => ({ - label: key, - value: meta[key], - })) return ( { > {heading && {heading}} - {!isEmpty(meta) && } + {!isEmpty(meta) && } {text && {text}} @@ -88,7 +82,7 @@ EntityListItem.propTypes = { data: PropTypes.shape({}), text: PropTypes.node, heading: PropTypes.string, - meta: PropTypes.shape({}), + meta: PropTypes.array, } EntityListItem.defaultProps = { @@ -96,7 +90,7 @@ EntityListItem.defaultProps = { onEntityClick: null, data: {}, heading: null, - meta: null, + meta: [], } export default EntityListItem diff --git a/src/entity-search/__tests__/EntityList.test.jsx b/src/entity-search/__tests__/EntityList.test.jsx index 03f9e3d9..f4687ec2 100644 --- a/src/entity-search/__tests__/EntityList.test.jsx +++ b/src/entity-search/__tests__/EntityList.test.jsx @@ -10,7 +10,7 @@ const entitiesFixture = [ id: '1', name: 'Non-clickable entity', heading: 'some heading', - meta: {}, + meta: [], data: {}, canHandleClick: false, }, @@ -18,7 +18,7 @@ const entitiesFixture = [ id: '2', name: 'Clickable entity', heading: 'some heading', - meta: {}, + meta: [], data: { some: 'data' }, canHandleClick: true, }, diff --git a/src/entity-search/__tests__/EntityListItem.test.jsx b/src/entity-search/__tests__/EntityListItem.test.jsx index 06403bf2..71ecd4a2 100644 --- a/src/entity-search/__tests__/EntityListItem.test.jsx +++ b/src/entity-search/__tests__/EntityListItem.test.jsx @@ -147,12 +147,7 @@ describe('EntityListItem', () => { }) describe('when the "meta" prop was passed', () => { - const meta = { - some: 'meta', - and: 'more meta', - } - - const expectedMeta = [ + const meta = [ { label: 'some', value: 'meta', @@ -169,7 +164,7 @@ describe('EntityListItem', () => { test('should render "Metadata" component', () => { const metaList = wrapper.find(Metadata) - expect(metaList.prop('rows')).toEqual(expectedMeta) + expect(metaList.prop('rows')).toEqual(meta) }) }) }) diff --git a/src/entity-search/__tests__/__snapshots__/useDnbSearch.test.jsx.snap b/src/entity-search/__tests__/__snapshots__/useDnbSearch.test.jsx.snap index aa076444..9aed25cf 100644 --- a/src/entity-search/__tests__/__snapshots__/useDnbSearch.test.jsx.snap +++ b/src/entity-search/__tests__/__snapshots__/useDnbSearch.test.jsx.snap @@ -47,9 +47,12 @@ Array [ }, "heading": "Some other company", "id": "219999999", - "meta": Object { - "Address": "123 ABC Road, Brighton, BN2 9QB", - }, + "meta": Array [ + Object { + "label": "Location at", + "value": "123 ABC Road, Brighton, BN2 9QB", + }, + ], }, ] `; @@ -111,9 +114,16 @@ Array [ }, "heading": "Some company name", "id": "12345678", - "meta": Object { - "Address": "123 Fake Street, Brighton, BN1 4SE", - }, + "meta": Array [ + Object { + "label": "Trading name(s)", + "value": "Some trading name", + }, + Object { + "label": "Location at", + "value": "123 Fake Street, Brighton, BN1 4SE", + }, + ], }, Object { "data": Object { @@ -160,9 +170,12 @@ Array [ }, "heading": "Some other company", "id": "219999999", - "meta": Object { - "Address": "123 ABC Road, Brighton, BN2 9QB", - }, + "meta": Array [ + Object { + "label": "Location at", + "value": "123 ABC Road, Brighton, BN2 9QB", + }, + ], }, Object { "data": Object { @@ -197,9 +210,12 @@ Array [ }, "heading": "Dissolvex", "id": "219999996", - "meta": Object { - "Address": "20 New Fake Road, Bristol, B11 9QC", - }, + "meta": Array [ + Object { + "label": "Location at", + "value": "20 New Fake Road, Bristol, B11 9QC", + }, + ], }, ] `; @@ -260,9 +276,16 @@ Object { }, "heading": "Some company name", "id": "12345678", - "meta": Object { - "Address": "123 Fake Street, Brighton, BN1 4SE", - }, + "meta": Array [ + Object { + "label": "Trading name(s)", + "value": "Some trading name", + }, + Object { + "label": "Location at", + "value": "123 Fake Street, Brighton, BN1 4SE", + }, + ], } `; @@ -312,9 +335,12 @@ Object { }, "heading": "Some other company", "id": "219999999", - "meta": Object { - "Address": "123 ABC Road, Brighton, BN2 9QB", - }, + "meta": Array [ + Object { + "label": "Location at", + "value": "123 ABC Road, Brighton, BN2 9QB", + }, + ], } `; @@ -352,8 +378,11 @@ Object { }, "heading": "Dissolvex", "id": "219999996", - "meta": Object { - "Address": "20 New Fake Road, Bristol, B11 9QC", - }, + "meta": Array [ + Object { + "label": "Location at", + "value": "20 New Fake Road, Bristol, B11 9QC", + }, + ], } `; diff --git a/src/entity-search/useDnbSearch.jsx b/src/entity-search/useDnbSearch.jsx index 8620d642..45bc9799 100644 --- a/src/entity-search/useDnbSearch.jsx +++ b/src/entity-search/useDnbSearch.jsx @@ -1,7 +1,29 @@ /* eslint-disable camelcase */ import axios from 'axios' -import { compact } from 'lodash' +import { compact, isEmpty } from 'lodash' + +function getTradingNames(dnb_company) { + return isEmpty(dnb_company.trading_names) + ? null + : { + label: 'Trading name(s)', + value: dnb_company.trading_names.join(', '), + } +} + +function getAddress(dnb_company) { + return { + label: 'Location at', + value: compact([ + dnb_company.address_line_1, + dnb_company.address_line_2, + dnb_company.address_town, + dnb_company.address_county, + dnb_company.address_postcode, + ]).join(', '), + } +} function useDnbSearch(apiEndpoint) { function transformCompanyRecord(record) { @@ -10,15 +32,7 @@ function useDnbSearch(apiEndpoint) { return { id: dnb_company.duns_number, heading: dnb_company.primary_name, - meta: { - Address: compact([ - dnb_company.address_line_1, - dnb_company.address_line_2, - dnb_company.address_town, - dnb_company.address_county, - dnb_company.address_postcode, - ]).join(', '), - }, + meta: compact([getTradingNames(dnb_company), getAddress(dnb_company)]), data: record, } }