Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #296 from uktrade/feature/trading-names
Browse files Browse the repository at this point in the history
feat: Add D&B trading names to D&B company search results
  • Loading branch information
paulgain authored Apr 28, 2020
2 parents e82da5b + 527f43d commit 38e2f8c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/entity-search/EntityList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 5 additions & 11 deletions src/entity-search/EntityListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const StyledEntity = styled('div')`
isClickable &&
`
cursor: pointer;
h3 {
color: ${LINK_COLOUR};
}
&:hover {
border: 1px solid ${LINK_HOVER_COLOUR};
background-color: ${GREY_4};
& > h3 {
color: ${LINK_HOVER_COLOUR};
}
Expand All @@ -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 (
<StyledEntity
key={`entity_${id}`}
Expand All @@ -75,7 +69,7 @@ const EntityListItem = ({ id, onEntityClick, data, text, heading, meta }) => {
>
{heading && <StyledHeading>{heading}</StyledHeading>}

{!isEmpty(meta) && <Metadata rows={metaAsArray} />}
{!isEmpty(meta) && <Metadata rows={meta} />}

{text && <StyledInsetText>{text}</StyledInsetText>}
</StyledEntity>
Expand All @@ -88,15 +82,15 @@ EntityListItem.propTypes = {
data: PropTypes.shape({}),
text: PropTypes.node,
heading: PropTypes.string,
meta: PropTypes.shape({}),
meta: PropTypes.array,
}

EntityListItem.defaultProps = {
text: null,
onEntityClick: null,
data: {},
heading: null,
meta: null,
meta: [],
}

export default EntityListItem
4 changes: 2 additions & 2 deletions src/entity-search/__tests__/EntityList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const entitiesFixture = [
id: '1',
name: 'Non-clickable entity',
heading: 'some heading',
meta: {},
meta: [],
data: {},
canHandleClick: false,
},
{
id: '2',
name: 'Clickable entity',
heading: 'some heading',
meta: {},
meta: [],
data: { some: 'data' },
canHandleClick: true,
},
Expand Down
9 changes: 2 additions & 7 deletions src/entity-search/__tests__/EntityListItem.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
},
]
`;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
},
],
},
]
`;
Expand Down Expand Up @@ -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",
},
],
}
`;

Expand Down Expand Up @@ -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",
},
],
}
`;

Expand Down Expand Up @@ -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",
},
],
}
`;
34 changes: 24 additions & 10 deletions src/entity-search/useDnbSearch.jsx
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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,
}
}
Expand Down

0 comments on commit 38e2f8c

Please sign in to comment.