diff --git a/package-lock.json b/package-lock.json index f7b1cd487..82878829d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,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", @@ -3553,9 +3553,9 @@ } }, "node_modules/@defra/interactive-map": { - "version": "0.0.11-alpha", - "resolved": "https://registry.npmjs.org/@defra/interactive-map/-/interactive-map-0.0.11-alpha.tgz", - "integrity": "sha512-j1Eq/DUqMpHr/PSHaZRUrRJ7fupvoNUMJEZzUKplcQQHTPW0CjWyo/ZFzNNFocl2QEHmtyhp7CLzapYu+sgCYw==", + "version": "0.0.17-alpha", + "resolved": "https://registry.npmjs.org/@defra/interactive-map/-/interactive-map-0.0.17-alpha.tgz", + "integrity": "sha512-x2hBKeaXl2sN5HBZpnrym/3lNU1aWsChgAOS34DwAzfEhGl3pNgB34ZxOVXxdfLTaVkhVU7jEU4rB6GnnKA8Og==", "dependencies": { "@babel/runtime": "^7.28.6", "@docusaurus/theme-common": "^3.9.2", @@ -3572,13 +3572,13 @@ "@turf/polygon-to-line": "^7.3.3", "accessible-autocomplete": "^3.0.1", "govuk-frontend": "^5.13.0", - "maplibre-gl": "^5.15.0", + "maplibre-gl": "^5.21.1", "polygon-splitter": "^0.0.11", "preact": "^10.27.2", "tslib": "^2.8.1" }, "peerDependencies": { - "@arcgis/core": "^4.34.8" + "@arcgis/core": "^5.0.9" }, "peerDependenciesMeta": { "@arcgis/core": { @@ -7216,19 +7216,6 @@ "integrity": "sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==", "license": "MIT" }, - "node_modules/@mapbox/geojson-rewind": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/@mapbox/geojson-rewind/-/geojson-rewind-0.5.2.tgz", - "integrity": "sha512-tJaT+RbYGJYStt7wI3cq4Nl4SXxG8W7JDG5DMJu97V25RnbNg3QtQtf+KD+VLjNpWKYsRvXDNmNrBgEETr1ifA==", - "license": "ISC", - "dependencies": { - "get-stream": "^6.0.1", - "minimist": "^1.2.6" - }, - "bin": { - "geojson-rewind": "geojson-rewind" - } - }, "node_modules/@mapbox/jsonlint-lines-primitives": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@mapbox/jsonlint-lines-primitives/-/jsonlint-lines-primitives-2.0.2.tgz", @@ -7276,15 +7263,18 @@ } }, "node_modules/@maplibre/geojson-vt": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/@maplibre/geojson-vt/-/geojson-vt-5.0.4.tgz", - "integrity": "sha512-KGg9sma45S+stfH9vPCJk1J0lSDLWZgCT9Y8u8qWZJyjFlP8MNP1WGTxIMYJZjDvVT3PDn05kN1C95Sut1HpgQ==", - "license": "ISC" + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/@maplibre/geojson-vt/-/geojson-vt-6.0.4.tgz", + "integrity": "sha512-HYv3POhMRCdhP3UPPATM/hfcy6/WuVIf5FKboH8u/ZuFMTnAIcSVlq5nfOqroLokd925w2QtE7YwquFOIacwVQ==", + "license": "ISC", + "dependencies": { + "kdbush": "^4.0.2" + } }, "node_modules/@maplibre/maplibre-gl-style-spec": { - "version": "24.6.0", - "resolved": "https://registry.npmjs.org/@maplibre/maplibre-gl-style-spec/-/maplibre-gl-style-spec-24.6.0.tgz", - "integrity": "sha512-+lxMYE+DvInshwVrqSQ3CkW9YRwVlRXeDzfthVOa1c9pwK5d7YgCwhgFwlSmjJLvTXn4gL8EvPUGT620sk2Pzg==", + "version": "24.7.0", + "resolved": "https://registry.npmjs.org/@maplibre/maplibre-gl-style-spec/-/maplibre-gl-style-spec-24.7.0.tgz", + "integrity": "sha512-Ed7rcKYU5iELfablg9Mj+TVCsXsPBgdMyXPRAxb2v7oWg9YJnpQdZ5msDs1LESu/mtXy3Z48Vdppv2t/x5kAhw==", "license": "ISC", "dependencies": { "@mapbox/jsonlint-lines-primitives": "~2.0.2", @@ -7302,9 +7292,9 @@ } }, "node_modules/@maplibre/mlt": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/@maplibre/mlt/-/mlt-1.1.6.tgz", - "integrity": "sha512-rgtY3x65lrrfXycLf6/T22ZnjTg5WgIOsptOIoCaMZy4O4UAKTyZlYY0h6v8le721pTptF94U65yMDQkug+URw==", + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/@maplibre/mlt/-/mlt-1.1.8.tgz", + "integrity": "sha512-8vtfYGidr1rNkv5IwIoU2lfe3Oy+Wa8HluzQYcQi9cveU9K3pweAal/poQj4GJ0K/EW4bTQp2wVAs09g2yDRZg==", "license": "(MIT OR Apache-2.0)", "dependencies": { "@mapbox/point-geometry": "^1.1.0" @@ -7325,6 +7315,12 @@ "supercluster": "^8.0.1" } }, + "node_modules/@maplibre/vt-pbf/node_modules/@maplibre/geojson-vt": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/@maplibre/geojson-vt/-/geojson-vt-5.0.4.tgz", + "integrity": "sha512-KGg9sma45S+stfH9vPCJk1J0lSDLWZgCT9Y8u8qWZJyjFlP8MNP1WGTxIMYJZjDvVT3PDn05kN1C95Sut1HpgQ==", + "license": "ISC" + }, "node_modules/@mdx-js/mdx": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/@mdx-js/mdx/-/mdx-3.1.1.tgz", @@ -23152,24 +23148,22 @@ } }, "node_modules/maplibre-gl": { - "version": "5.19.0", - "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-5.19.0.tgz", - "integrity": "sha512-REhYUN8gNP3HlcIZS6QU2uy8iovl31cXsrNDkCcqWSQbCkcpdYLczqDz5PVIwNH42UQNyvukjes/RoHPDrOUmQ==", + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-5.21.1.tgz", + "integrity": "sha512-zto1RTnFkOpOO1bm93ElCXF1huey2N4LvXaGLMFcYAu9txh0OhGIdX1q3LZLkrMKgMxMeYduaQo+DVNzg098fg==", "license": "BSD-3-Clause", "dependencies": { - "@mapbox/geojson-rewind": "^0.5.2", "@mapbox/jsonlint-lines-primitives": "^2.0.2", "@mapbox/point-geometry": "^1.1.0", "@mapbox/tiny-sdf": "^2.0.7", "@mapbox/unitbezier": "^0.0.1", "@mapbox/vector-tile": "^2.0.4", "@mapbox/whoots-js": "^3.1.0", - "@maplibre/geojson-vt": "^5.0.4", - "@maplibre/maplibre-gl-style-spec": "^24.4.1", - "@maplibre/mlt": "^1.1.6", - "@maplibre/vt-pbf": "^4.2.1", + "@maplibre/geojson-vt": "^6.0.4", + "@maplibre/maplibre-gl-style-spec": "^24.7.0", + "@maplibre/mlt": "^1.1.8", + "@maplibre/vt-pbf": "^4.3.0", "@types/geojson": "^7946.0.16", - "@types/supercluster": "^7.1.3", "earcut": "^3.0.2", "gl-matrix": "^3.4.4", "kdbush": "^4.0.2", @@ -23177,7 +23171,6 @@ "pbf": "^4.0.1", "potpack": "^2.1.0", "quickselect": "^3.0.0", - "supercluster": "^8.0.1", "tinyqueue": "^3.0.0" }, "engines": { diff --git a/package.json b/package.json index 141eba31a..c21681b77 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/client/javascripts/geospatial-map.js b/src/client/javascripts/geospatial-map.js index f580d96c5..ec8ec3215 100644 --- a/src/client/javascripts/geospatial-map.js +++ b/src/client/javascripts/geospatial-map.js @@ -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 @@ -245,7 +245,7 @@ function createFeatureHTML(feature, index, mapId, readonly) {
${typeDescriptions[feature.geometry.type]}
-
Center grid reference
+
Centre grid reference
${feature.properties.centroidGridReference}
diff --git a/src/client/javascripts/location-map.js b/src/client/javascripts/location-map.js index 91864be01..9900dd1c8 100644 --- a/src/client/javascripts/location-map.js +++ b/src/client/javascripts/location-map.js @@ -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 diff --git a/src/client/javascripts/map.js b/src/client/javascripts/map.js index 37137d4a4..2f37d7fce 100644 --- a/src/client/javascripts/map.js +++ b/src/client/javascripts/map.js @@ -239,6 +239,18 @@ export function makeTileRequestTransformer(apiPath) { } } +/** + * 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) + return new Request(url.toString(), request.options) +} + /** * Create a Defra map instance * @param {string} mapId - the map id @@ -310,6 +322,7 @@ export function createMap(mapId, initConfig, mapsConfig) { }), interactPlugin, defra.searchPlugin({ + transformRequest: transformGeocodeRequest, osNamesURL: `${apiPath}/geocode-proxy?query={query}`, width: '300px', showMarker: false diff --git a/src/server/plugins/engine/components/GeospatialField.test.ts b/src/server/plugins/engine/components/GeospatialField.test.ts index 5950cab5f..647695871 100644 --- a/src/server/plugins/engine/components/GeospatialField.test.ts +++ b/src/server/plugins/engine/components/GeospatialField.test.ts @@ -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' }) ]) }) @@ -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' }) ]) }) diff --git a/src/server/plugins/engine/components/GeospatialField.ts b/src/server/plugins/engine/components/GeospatialField.ts index 7dcad2296..59538c22d 100644 --- a/src/server/plugins/engine/components/GeospatialField.ts +++ b/src/server/plugins/engine/components/GeospatialField.ts @@ -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) } diff --git a/src/server/plugins/engine/components/helpers/geospatial.test.js b/src/server/plugins/engine/components/helpers/geospatial.test.js index 3079217c3..8b77fa648 100644 --- a/src/server/plugins/engine/components/helpers/geospatial.test.js +++ b/src/server/plugins/engine/components/helpers/geospatial.test.js @@ -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([]) }) }) diff --git a/src/server/plugins/engine/components/helpers/geospatial.ts b/src/server/plugins/engine/components/helpers/geospatial.ts index a9bbeeb57..5f043aef9 100644 --- a/src/server/plugins/engine/components/helpers/geospatial.ts +++ b/src/server/plugins/engine/components/helpers/geospatial.ts @@ -20,7 +20,7 @@ const Joi = JoiBase.extend({ if (typeof value === 'string') { if (value.trim() === '') { return { - value: undefined + value: [] } } diff --git a/test/client/javascripts/map.test.js b/test/client/javascripts/map.test.js index a31e93815..554528280 100644 --- a/test/client/javascripts/map.test.js +++ b/test/client/javascripts/map.test.js @@ -3,7 +3,8 @@ import { getCentroidGridRef, getCoordinateGridRef, initMaps, - makeTileRequestTransformer + makeTileRequestTransformer, + transformGeocodeRequest } from '~/src/client/javascripts/map.js' describe('Maps Client JS', () => { @@ -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) + }) + }) })