Skip to content

Commit 42dd409

Browse files
Initial geospatial component
1 parent 09776f5 commit 42dd409

14 files changed

Lines changed: 1162 additions & 7 deletions

File tree

package-lock.json

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

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@
7575
},
7676
"license": "SEE LICENSE IN LICENSE",
7777
"dependencies": {
78-
"@defra/forms-model": "^3.0.622",
78+
"@defra/forms-model": "^3.0.624",
7979
"@defra/hapi-tracing": "^1.29.0",
8080
"@defra/interactive-map": "^0.0.4-alpha",
8181
"@elastic/ecs-pino-format": "^1.5.0",
8282
"@hapi/boom": "^10.0.1",
83+
"@hapi/bourne": "^3.0.0",
8384
"@hapi/catbox": "^12.1.1",
8485
"@hapi/catbox-memory": "^6.0.2",
8586
"@hapi/catbox-redis": "^7.0.2",
@@ -91,6 +92,8 @@
9192
"@hapi/vision": "^7.0.3",
9293
"@hapi/wreck": "^18.1.0",
9394
"@hapi/yar": "^11.0.3",
95+
"@turf/centroid": "^7.3.4",
96+
"@turf/helpers": "^7.3.4",
9497
"@types/humanize-duration": "^3.27.4",
9598
"accessible-autocomplete": "^3.0.1",
9699
"atob": "^2.1.2",

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import {
1212
} from '~/src/server/plugins/engine/types/index.js'
1313
import {
1414
type ErrorMessageTemplateList,
15+
type Feature,
1516
type FileState,
1617
type FormPayload,
1718
type FormState,
1819
type FormStateValue,
1920
type FormSubmissionError,
2021
type FormSubmissionState,
2122
type FormValue,
23+
type GeospatialState,
2224
type RepeatItemState,
2325
type RepeatListState,
2426
type UploadState
@@ -303,9 +305,36 @@ export function isUploadState(value?: unknown): value is UploadState {
303305
return value.every(isUploadValue)
304306
}
305307

308+
/**
309+
* Check for geospatial state
310+
*/
311+
export function isGeospatialState(value?: unknown): value is GeospatialState {
312+
if (!Array.isArray(value)) {
313+
return false
314+
}
315+
316+
// Skip checks when empty
317+
if (!value.length) {
318+
return true
319+
}
320+
321+
return value.every(isGeospatialValue)
322+
}
323+
306324
/**
307325
* Check for upload state value
308326
*/
309327
export function isUploadValue(value?: unknown): value is FileState {
310328
return isFormState(value) && typeof value.uploadId === 'string'
311329
}
330+
331+
/**
332+
* Check for geospatial state value
333+
*/
334+
export function isGeospatialValue(value?: unknown): value is Feature {
335+
return (
336+
isFormState(value) &&
337+
typeof value.type === 'string' &&
338+
value.type === 'Feature'
339+
)
340+
}

0 commit comments

Comments
 (0)