Skip to content

Commit 2c838a4

Browse files
Fix/DF-861 done button double (#360)
* Spelling typo fix * Geospatial field - default an empty string to an empty array for non JS * Add geospatial feature cap of 50 * Change map info slot to "drawer" now "bottom" is deprecated * Add temporary transformGeocodeRequest until fixed in v0.0.18 * Bump interactive-map to v0.0.17-alpha * Fix tests
1 parent 2dd88ac commit 2c838a4

File tree

10 files changed

+81
-52
lines changed

10 files changed

+81
-52
lines changed

package-lock.json

Lines changed: 32 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"dependencies": {
8686
"@defra/forms-model": "^3.0.637",
8787
"@defra/hapi-tracing": "^1.29.0",
88-
"@defra/interactive-map": "^0.0.11-alpha",
88+
"@defra/interactive-map": "^0.0.17-alpha",
8989
"@elastic/ecs-pino-format": "^1.5.0",
9090
"@hapi/boom": "^10.0.1",
9191
"@hapi/bourne": "^3.0.0",

src/client/javascripts/geospatial-map.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ const helpPanelConfig = {
1212
showLabel: true,
1313
label: 'How to use this map',
1414
mobile: {
15-
slot: 'bottom',
15+
slot: 'drawer',
1616
open: true,
1717
dismissible: true,
1818
modal: false
1919
},
2020
tablet: {
21-
slot: 'bottom',
21+
slot: 'drawer',
2222
open: true,
2323
dismissible: true,
2424
modal: false
2525
},
2626
desktop: {
27-
slot: 'bottom',
27+
slot: 'drawer',
2828
open: true,
2929
dismissible: true,
3030
modal: false
@@ -245,7 +245,7 @@ function createFeatureHTML(feature, index, mapId, readonly) {
245245
<dd class="govuk-summary-list__value">${typeDescriptions[feature.geometry.type]}</dd>
246246
</div>
247247
<div class="govuk-summary-list__row">
248-
<dt class="govuk-summary-list__key">Center grid reference</dt>
248+
<dt class="govuk-summary-list__key">Centre grid reference</dt>
249249
<dd class="govuk-summary-list__value">${feature.properties.centroidGridReference}</dd>
250250
</div>
251251
<div class="govuk-summary-list__row">

src/client/javascripts/location-map.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,19 +447,19 @@ export function processLocation(config, location, index) {
447447
showLabel: true,
448448
label: 'How to use the map',
449449
mobile: {
450-
slot: 'bottom',
450+
slot: 'drawer',
451451
open: true,
452452
dismissible: true,
453453
modal: false
454454
},
455455
tablet: {
456-
slot: 'bottom',
456+
slot: 'drawer',
457457
open: true,
458458
dismissible: true,
459459
modal: false
460460
},
461461
desktop: {
462-
slot: 'bottom',
462+
slot: 'drawer',
463463
open: true,
464464
dismissible: true,
465465
modal: false

src/client/javascripts/map.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ export function makeTileRequestTransformer(apiPath) {
239239
}
240240
}
241241

242+
/**
243+
* Temporary transform request function to transform geocode requests. Fixed in v0.0.18 of interactive map so this is not needed when we upgrade.
244+
* @param {object} request
245+
* @param {string} request.url
246+
* @param {{ method: 'get' }} request.options
247+
* @returns {Request}
248+
*/
249+
export const transformGeocodeRequest = (request) => {
250+
const url = new URL(request.url, window.location.origin)
251+
return new Request(url.toString(), request.options)
252+
}
253+
242254
/**
243255
* Create a Defra map instance
244256
* @param {string} mapId - the map id
@@ -310,6 +322,7 @@ export function createMap(mapId, initConfig, mapsConfig) {
310322
}),
311323
interactPlugin,
312324
defra.searchPlugin({
325+
transformRequest: transformGeocodeRequest,
313326
osNamesURL: `${apiPath}/geocode-proxy?query={query}`,
314327
width: '300px',
315328
showMarker: false

src/server/plugins/engine/components/GeospatialField.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('GeospatialField', () => {
110110

111111
expect(result.errors).toEqual([
112112
expect.objectContaining({
113-
text: 'Select example geospatial'
113+
text: 'Example geospatial must contain at least 1 items'
114114
})
115115
])
116116
})
@@ -128,7 +128,7 @@ describe('GeospatialField', () => {
128128

129129
expect(result.errors).toEqual([
130130
expect.objectContaining({
131-
text: 'Select example geospatial title'
131+
text: 'Example geospatial title must contain at least 1 items'
132132
})
133133
])
134134
})

src/server/plugins/engine/components/GeospatialField.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export class GeospatialField extends FormComponent {
3333

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

36+
formSchema = formSchema.max(50)
37+
3638
if (options.required !== false) {
3739
formSchema = formSchema.min(1)
3840
}

src/server/plugins/engine/components/helpers/geospatial.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ describe('Geospatial validation helpers', () => {
4949
test('it should validate an empty string', () => {
5050
const result = geospatialSchema.validate('')
5151

52+
expect(result.error).toBeUndefined()
53+
expect(result.value).toEqual([])
54+
})
55+
56+
test('it should validate an empty string with errors when required', () => {
57+
const result = geospatialSchema.min(1).required().validate('')
58+
5259
expect(result.error).toBeDefined()
53-
expect(result.value).toBeUndefined()
60+
expect(result.value).toEqual([])
5461
})
5562
})

src/server/plugins/engine/components/helpers/geospatial.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Joi = JoiBase.extend({
2020
if (typeof value === 'string') {
2121
if (value.trim() === '') {
2222
return {
23-
value: undefined
23+
value: []
2424
}
2525
}
2626

test/client/javascripts/map.test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
getCentroidGridRef,
44
getCoordinateGridRef,
55
initMaps,
6-
makeTileRequestTransformer
6+
makeTileRequestTransformer,
7+
transformGeocodeRequest
78
} from '~/src/client/javascripts/map.js'
89

910
describe('Maps Client JS', () => {
@@ -1468,4 +1469,17 @@ describe('Maps Client JS', () => {
14681469
expect(result).toBe('TQ 29472 80890')
14691470
})
14701471
})
1472+
1473+
describe('Geocode request transformer - temporarily needed until v0.0.18', () => {
1474+
test('it should return centroid gridref for a point feature', () => {
1475+
const result = transformGeocodeRequest({
1476+
url: '/a/b/c',
1477+
options: {
1478+
method: 'get'
1479+
}
1480+
})
1481+
1482+
expect(result instanceof Request).toBe(true)
1483+
})
1484+
})
14711485
})

0 commit comments

Comments
 (0)