Skip to content

Commit

Permalink
Merge pull request #837 from uktrade/develop
Browse files Browse the repository at this point in the history
FE release 2.3
  • Loading branch information
jim68000 authored Oct 27, 2017
2 parents 223c8e9 + 2e85b12 commit d1c2809
Show file tree
Hide file tree
Showing 142 changed files with 3,363 additions and 1,745 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
QA_USER_PASSWORD: secretSquiR3L
REDIS_HOST: localhost
TZ: "/usr/share/zoneinfo/Europe/London"
LOG_LEVEL: debug
- &docker_redis
image: redis:3.2.10
- &docker_elasticsearch
Expand Down Expand Up @@ -133,7 +134,7 @@ jobs:
name: Split tests for parallelisation and then run acceptance tests
command: |
# split .features for parallelisation
FEATURES="$(circleci tests glob "test/acceptance/features/**/*.feature" | circleci tests split --split-by=timings --timings-type=filename)"
FEATURES="$(circleci tests glob "test/acceptance/features/**/*.feature" | circleci tests split --split-by=filesize)"
# move groups of .features to folder
mkdir -p ~/data-hub-frontend/test/acceptance/features_${CIRCLE_NODE_INDEX}
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ This file expects the following environment variables:
| ZEN_SERVICE | Zendesk service ID |
| SENTRY_DSN | Sentry DSN (optional) |
| WEBPACK_ENV | Optionally select the webpack configuration variation to use, the default will correctly pick a production or development config based on NODE_ENV. Valid values include `prod`, `develop` and `docker` |
| OMIS_ARCHIVED_DOCUMENTS_BASE_URL | The base URL for the OMIS archived document store. Holds archived quotes and deliverables |

Either set these variables manually or why not look at [autoenv](https://github.com/kennethreitz/autoenv).
To start the server just:
Expand Down Expand Up @@ -339,14 +340,14 @@ You can tell `nightwatch.js` not to run a feature by adding the tag `@ignore`.


## Continuous Integration
Data hub uses [CircleCI](https://circleci.com/) for continuous integration.
Data hub uses [CircleCI](https://circleci.com/) for continuous integration.

### Base docker image
The acceptance tests `user_acceptance_tests` job uses the docker image `ukti/docker-data-hub-base` as a base for running a selenium server and data hub frontend
The acceptance tests `user_acceptance_tests` job uses the docker image `ukti/docker-data-hub-base` as a base for running a selenium server and data hub frontend
Details can be found in the [GitHub](https://github.com/uktrade/docker-data-hub-base) and [docker](https://hub.docker.com/r/ukti/docker-data-hub-base/) repositories.

### Data hub backend docker image
The acceptance tests `user_acceptance_tests` job on circleCi uses its own version of [uktrade/data-hub-leeloo](https://github.com/uktrade/data-hub-leeloo).
The acceptance tests `user_acceptance_tests` job on circleCi uses its own version of [uktrade/data-hub-leeloo](https://github.com/uktrade/data-hub-leeloo).
The `uktrade/data-hub-leeloo` docker image and tags that is used is automatically built via a Docker hub automated job. Details can be found [https://hub.docker.com/r/ukti/data-hub-leeloo](https://hub.docker.com/r/ukti/data-hub-leeloo).

- `user_acceptance_tests` job uses `ukti/data-hub-leeloo:latest`
Expand All @@ -358,7 +359,7 @@ CircleCI has been configured to show you a summary report of what has failed on
- `lint_code`
- `user_acceptance_tests`

When acceptance tests fail you can also have a look at the `Nightwatch.js` html report found in the jobs artifacts folder.
When acceptance tests fail you can also have a look at the `Nightwatch.js` html report found in the jobs artifacts folder.
This can be accessed by logging in to [CircleCI](https://circleci.com/)

## Deployment
Expand Down
2 changes: 2 additions & 0 deletions assets/stylesheets/components/_meta-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

@include media(tablet) {
display: inline-block;
vertical-align: top;

& + & {
margin-left: $default-spacing-unit * 2;
Expand Down Expand Up @@ -102,5 +103,6 @@

.c-meta-list__item + .c-meta-list__item {
margin-left: 0;
margin-top: $default-spacing-unit / 2;
}
}
5 changes: 5 additions & 0 deletions assets/stylesheets/elements/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ table {
text-align: right;
}
}


.table__cell--plain {
border-bottom: 0;
}
10 changes: 10 additions & 0 deletions assets/stylesheets/objects/_list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@
list-style: disc outside;
padding-left: 1em;
}

.list-spaced {
* + & {
margin-top: $default-spacing-unit * 2;
}

li + li {
margin-top: $default-spacing-unit / 2;
}
}
2 changes: 2 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const config = {
mediumDateFormat: 'D MMM YYYY',
mediumDateTimeFormat: 'D MMM YYYY, h:mma',
paginationMaxResults: 10000,
performanceDashboardsUrl: process.env.PERFORMANCE_DASHBOARDS_URL || 'https://mi.exportwins.service.trade.gov.uk',
omisArchivedDocumentsBaseUrl: process.env.OMIS_ARCHIVED_DOCUMENTS_BASE_URL,
}

module.exports = config
9 changes: 7 additions & 2 deletions config/nunjucks/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require('moment-duration-format')
const dateFns = require('date-fns')
const Case = require('case')
const numeral = require('numeral')
const queryString = require('query-string')
const {
assign,
concat,
Expand Down Expand Up @@ -52,8 +53,6 @@ function pluralise (string, count, pluralisedWord) {
}

const filters = {
stringify: JSON.stringify,
sentenceCase: Case.sentence,
lowerCase,
kebabCase,
assign,
Expand All @@ -73,6 +72,12 @@ const filters = {
isPlainObject,
isString,
pluralise,
stringify: JSON.stringify,
sentenceCase: Case.sentence,

encodeQueryString (value) {
return encodeURIComponent(queryString.stringify(value))
},

assignCopy (...args) {
return assign({}, ...args)
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "data-hub-frontend",
"version": "2.2.1",
"version": "2.3.0",
"description": "Data Hub Frontend",
"main": "src/server.js",
"repository": {
"type": "git",
"url": "https://github.com/uktrade/data-hub-frontend"
},
"dependencies": {
"asyncro": "^2.0.1",
"autoprefixer": "^7.1.1",
"axios": "^0.16.2",
"babel-core": "^6.23.1",
Expand Down Expand Up @@ -116,7 +115,7 @@
"test:acceptance": "nightwatch --config test/acceptance/nightwatch.conf.js --env default --skiptags ignore",
"coverage": "nyc --reporter=html --reporter=text --reporter=lcov npm run test:unit",
"circle:unit": "nyc --reporter=lcov npm run test:unit -- --reporter mocha-circleci-reporter && codeclimate-test-reporter < coverage/lcov.info",
"circle:acceptance": "nightwatch --config test/acceptance/nightwatch.conf.js --env circleci --skiptags ignore",
"circle:acceptance": "nightwatch --config test/acceptance/nightwatch.conf.js --verbose --env circleci --skiptags ignore",
"heroku-postbuild": "npm rebuild && npm run build"
},
"pre-commit": [
Expand Down
16 changes: 8 additions & 8 deletions src/apps/companies/controllers/add.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const { map } = require('asyncro')
const { assign } = require('lodash')
const queryString = require('query-string')

const logger = require('../../../../config/logger')
const { ukOtherCompanyOptions, foreignOtherCompanyOptions } = require('../options')
const { buildUkOtherCompanyOptions, buildForeignOtherCompanyOptions } = require('../options')
const { getCHCompany } = require('../repos')
const { isBlank } = require('../../../lib/controller-utils')
const { searchLimitedCompanies } = require('../../search/services')
const { transformApiResponseToSearchCollection } = require('../../search/transformers')
const { transformCompaniesHouseCompanyToListItem } = require('../../companies/transformers')
const { companyDetailsLabels, companyTypeOptions } = require('../labels')

function getAddStepOne (req, res, next) {
function getAddStepOne (req, res) {
const ukOtherCompanyOptions = buildUkOtherCompanyOptions()
const foreignOtherCompanyOptions = buildForeignOtherCompanyOptions()

res.render('companies/views/add-step-1.njk', {
ukOtherCompanyOptions,
foreignOtherCompanyOptions,
Expand Down Expand Up @@ -47,7 +49,6 @@ function postAddStepOne (req, res, next) {
let params
switch (req.body.business_type) {
case 'ltd':
case 'ltdchild':
params = {
business_type: req.body.business_type,
country: 'uk',
Expand Down Expand Up @@ -92,19 +93,18 @@ async function getAddStepTwo (req, res, next) {
token,
searchTerm,
})
.then(response => response.results.filter(x => x.company_number))
.then(async (results) => {
.then(async (response) => {
// TODO: Remove the need to make another call to the API to get the companies house details.
// The search API should return companies house companies and their relevant information
return map(results, async (result) => {
return Promise.all(response.results.map(async (result) => {
try {
result.companies_house_data = await getCHCompany(token, result.company_number)
result.url = `/companies/add/${result.company_number}`
} catch (error) {
logger.error(error)
}
return result
})
}))
})
.then((results) => {
return {
Expand Down
38 changes: 38 additions & 0 deletions src/apps/companies/controllers/orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { search } = require('../../search/services')
const { transformApiResponseToCollection } = require('../../transformers')
const { transformOrderToListItem } = require('../../omis/transformers')

async function renderOrders (req, res, next) {
const token = req.session.token
const page = req.query.page || 1
const { id, name } = res.locals.company

try {
const results = await search({
token,
page,
searchEntity: 'order',
requestBody: {
company: id,
},
isAggregation: false,
})
.then(transformApiResponseToCollection(
{ query: req.query },
transformOrderToListItem,
))

res
.breadcrumb(name, `/companies/${id}`)
.breadcrumb('Orders (OMIS)')
.render('companies/views/orders', {
results,
})
} catch (error) {
next(error)
}
}

module.exports = {
renderOrders,
}
1 change: 0 additions & 1 deletion src/apps/companies/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const chDetailsLabels = {
}
const companyTypeOptions = {
ltd: 'UK private or public limited company',
ltdchild: 'Child of a UK private or public limited company',
ukother: 'Other type of UK organisation',
foreign: 'Foreign organisation',
}
Expand Down
16 changes: 13 additions & 3 deletions src/apps/companies/middleware/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { transformObjectToOption } = require('../../transformers')
const chDetailsDisplayOrder = ['name', 'company_number', 'registered_address', 'business_type', 'company_status', 'incorporation_date', 'sic_code']

function populateForm (req, res, next) {
const countryQueryParam = get(req.query, 'country')
const headquarterOptions = metadataRepository.headquarterOptions
.map(transformObjectToOption)
.map(option => {
Expand All @@ -29,12 +30,21 @@ function populateForm (req, res, next) {

if (get(req.query, 'business_type')) {
const businessType = find(metadataRepository.businessTypeOptions, (type) => {
return type.name.toLowerCase() === req.query.business_type.toLowerCase()
return type.id === req.query.business_type
})

res.locals.form.state.business_type = get(businessType, 'id')
}

if (countryQueryParam && countryQueryParam === 'uk') {
const ukCountryOption = find(metadataRepository.countryOptions.map(transformObjectToOption), (option) => {
return option.label === 'United Kingdom'
})

res.locals.form.state.registered_address_country = ukCountryOption.value
res.locals.form.state.trading_address_country = ukCountryOption.value
}

res.locals.formData = assign({}, res.locals.form.state, req.body)

if (!get(res.locals, 'formData.headquarter_type')) {
Expand All @@ -50,8 +60,8 @@ function populateForm (req, res, next) {
employeeOptions: metadataRepository.employeeOptions.map(transformObjectToOption),
turnoverOptions: metadataRepository.turnoverOptions.map(transformObjectToOption),
countryOptions: metadataRepository.countryOptions.map(transformObjectToOption),
businessType: req.query.business_type || get(res.locals, 'company.business_type.name'),
showTradingAddress: get(res.locals, 'form.state.trading_address_country'),
businessType: req.query.business_type || get(res.locals, 'company.business_type.id'),
showTradingAddress: get(res.locals, 'form.state.trading_address_1'),
})

next()
Expand Down
50 changes: 38 additions & 12 deletions src/apps/companies/options.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
const ukOtherCompanyOptions = [
const { filter, map } = require('lodash')
const { sentence } = require('case')

const metadataRepository = require('../../lib/metadata')
const ukOtherBusinessTypeNames = [
'Charity',
'Government department',
'Government Dept',
'Intermediary',
'Limited partnership',
'Partnership',
'Sole trader',
].map(item => {
return {
value: item,
label: item,
}
})
'Sole Trader',
]
const foreignOtherBusinessTypeNames = [
'Company',
...ukOtherBusinessTypeNames,
]

/**
* extract businessOptions from metadata by name and build an options list with
* @param requestedProperties
* @param metaDataOptions
* @returns {{label: String, id: String}[]}
*/
const buildBusinessTypeOptions = (requestedProperties, metaDataOptions) => {
return map(filter(metaDataOptions, (option) => {
return requestedProperties.indexOf(option.name) >= 0
}), (option) => {
return {
value: option.id,
label: sentence(option.name.replace('Dept', 'department'), []),
}
})
}

const foreignOtherCompanyOptions = [{ value: 'Company', label: 'Company' }, ...ukOtherCompanyOptions]
const buildUkOtherCompanyOptions = () => {
return buildBusinessTypeOptions(ukOtherBusinessTypeNames, metadataRepository.businessTypeOptions)
}

const buildForeignOtherCompanyOptions = () => {
return buildBusinessTypeOptions(foreignOtherBusinessTypeNames, metadataRepository.businessTypeOptions)
}

module.exports = {
ukOtherCompanyOptions,
foreignOtherCompanyOptions,
buildUkOtherCompanyOptions,
buildForeignOtherCompanyOptions,
}
3 changes: 3 additions & 0 deletions src/apps/companies/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { renderCompanyList } = require('./controllers/list')
const { renderForm } = require('./controllers/edit')
const { renderDetails } = require('./controllers/view')
const { renderInvestments } = require('./controllers/investments')
const { renderOrders } = require('./controllers/orders')
const { renderAuditLog } = require('./controllers/audit')
const { renderInteractions } = require('./controllers/interactions')
const { renderCompaniesHouseCompany } = require('./controllers/companies-house')
Expand Down Expand Up @@ -32,6 +33,7 @@ const LOCAL_NAV = [
{ path: 'interactions', label: 'Interactions' },
{ path: 'exports', label: 'Export' },
{ path: 'investments', label: 'Investment' },
{ path: 'orders', label: 'Orders (OMIS)' },
{ path: 'audit', label: 'Audit history' },
]
const DEFAULT_COLLECTION_QUERY = {
Expand Down Expand Up @@ -78,6 +80,7 @@ router.get('/:companyId/contacts', renderContacts)
router.get('/:companyId/interactions', setInteractionsReturnUrl, getInteractionCollection, renderInteractions)
router.get('/:companyId/exports', renderExports)
router.get('/:companyId/investments', renderInvestments)
router.get('/:companyId/orders', renderOrders)
router.get('/:companyId/audit', renderAuditLog)

router.use('/:companyId', setInteractionsReturnUrl, setInteractionsEntityName, interactionsRouter)
Expand Down
Loading

0 comments on commit d1c2809

Please sign in to comment.