Skip to content
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
71 changes: 32 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"dependencies": {
"@defra/forms-model": "^3.0.637",
"@defra/hapi-tracing": "^1.29.0",
"@defra/interactive-map": "^0.0.11-alpha",
"@defra/interactive-map": "^0.0.17-alpha",
"@elastic/ecs-pino-format": "^1.5.0",
"@hapi/boom": "^10.0.1",
"@hapi/bourne": "^3.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/client/javascripts/geospatial-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ const helpPanelConfig = {
showLabel: true,
label: 'How to use this map',
mobile: {
slot: 'bottom',
slot: 'drawer',
open: true,
dismissible: true,
modal: false
},
tablet: {
slot: 'bottom',
slot: 'drawer',
open: true,
dismissible: true,
modal: false
},
desktop: {
slot: 'bottom',
slot: 'drawer',
open: true,
dismissible: true,
modal: false
Expand Down Expand Up @@ -245,7 +245,7 @@ function createFeatureHTML(feature, index, mapId, readonly) {
<dd class="govuk-summary-list__value">${typeDescriptions[feature.geometry.type]}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Center grid reference</dt>
<dt class="govuk-summary-list__key">Centre grid reference</dt>
<dd class="govuk-summary-list__value">${feature.properties.centroidGridReference}</dd>
</div>
<div class="govuk-summary-list__row">
Expand Down
6 changes: 3 additions & 3 deletions src/client/javascripts/location-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,19 @@ export function processLocation(config, location, index) {
showLabel: true,
label: 'How to use the map',
mobile: {
slot: 'bottom',
slot: 'drawer',
open: true,
dismissible: true,
modal: false
},
tablet: {
slot: 'bottom',
slot: 'drawer',
open: true,
dismissible: true,
modal: false
},
desktop: {
slot: 'bottom',
slot: 'drawer',
open: true,
dismissible: true,
modal: false
Expand Down
13 changes: 13 additions & 0 deletions src/client/javascripts/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@
}
}

/**
* Temporary transform request function to transform geocode requests. Fixed in v0.0.18 of interactive map so this is not needed when we upgrade.
* @param {object} request
* @param {string} request.url
* @param {{ method: 'get' }} request.options
* @returns {Request}
*/
export const transformGeocodeRequest = (request) => {
const url = new URL(request.url, window.location.origin)

Check warning on line 250 in src/client/javascripts/map.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=DEFRA_forms-engine-plugin&issues=AZ1tEZyxaZ8ob9Hy3w8V&open=AZ1tEZyxaZ8ob9Hy3w8V&pullRequest=360
return new Request(url.toString(), request.options)
}

/**
* Create a Defra map instance
* @param {string} mapId - the map id
Expand Down Expand Up @@ -310,6 +322,7 @@
}),
interactPlugin,
defra.searchPlugin({
transformRequest: transformGeocodeRequest,
osNamesURL: `${apiPath}/geocode-proxy?query={query}`,
width: '300px',
showMarker: false
Expand Down
4 changes: 2 additions & 2 deletions src/server/plugins/engine/components/GeospatialField.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('GeospatialField', () => {

expect(result.errors).toEqual([
expect.objectContaining({
text: 'Select example geospatial'
text: 'Example geospatial must contain at least 1 items'
})
])
})
Expand All @@ -128,7 +128,7 @@ describe('GeospatialField', () => {

expect(result.errors).toEqual([
expect.objectContaining({
text: 'Select example geospatial title'
text: 'Example geospatial title must contain at least 1 items'
})
])
})
Expand Down
2 changes: 2 additions & 0 deletions src/server/plugins/engine/components/GeospatialField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class GeospatialField extends FormComponent {

let formSchema = geospatialSchema.label(this.label).required()

formSchema = formSchema.max(50)

if (options.required !== false) {
formSchema = formSchema.min(1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ describe('Geospatial validation helpers', () => {
test('it should validate an empty string', () => {
const result = geospatialSchema.validate('')

expect(result.error).toBeUndefined()
expect(result.value).toEqual([])
})

test('it should validate an empty string with errors when required', () => {
const result = geospatialSchema.min(1).required().validate('')

expect(result.error).toBeDefined()
expect(result.value).toBeUndefined()
expect(result.value).toEqual([])
})
})
2 changes: 1 addition & 1 deletion src/server/plugins/engine/components/helpers/geospatial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Joi = JoiBase.extend({
if (typeof value === 'string') {
if (value.trim() === '') {
return {
value: undefined
value: []
}
}

Expand Down
16 changes: 15 additions & 1 deletion test/client/javascripts/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
getCentroidGridRef,
getCoordinateGridRef,
initMaps,
makeTileRequestTransformer
makeTileRequestTransformer,
transformGeocodeRequest
} from '~/src/client/javascripts/map.js'

describe('Maps Client JS', () => {
Expand Down Expand Up @@ -1468,4 +1469,17 @@ describe('Maps Client JS', () => {
expect(result).toBe('TQ 29472 80890')
})
})

describe('Geocode request transformer - temporarily needed until v0.0.18', () => {
test('it should return centroid gridref for a point feature', () => {
const result = transformGeocodeRequest({
url: '/a/b/c',
options: {
method: 'get'
}
})

expect(result instanceof Request).toBe(true)
})
})
})
Loading