Skip to content

Commit 937a503

Browse files
Update Geospatial field summary display
1 parent 7559a5e commit 937a503

5 files changed

Lines changed: 12 additions & 21 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('GeospatialField', () => {
151151
const answer1 = getAnswer(field, state1)
152152
const answer2 = getAnswer(field, state2)
153153

154-
expect(answer1).toBe('My farm house:<br>SJ 61896 71377<br>')
154+
expect(answer1).toBe('Added 1 feature')
155155
expect(answer2).toBe('')
156156
})
157157

@@ -162,9 +162,7 @@ describe('GeospatialField', () => {
162162
const answer1 = getAnswer(field, state1)
163163
const answer2 = getAnswer(field, state2)
164164

165-
expect(answer1).toBe(
166-
`My farm house:<br>SJ 61896 71377<br>Main gas line:<br>SJ 62022 71500 to SJ 61904 71391<br>My Pony Paddock:<br>SJ 61829 71378<br>My farm house #2:<br>SJ 61894 71483<br>`
167-
)
165+
expect(answer1).toBe('Added 4 features')
168166
expect(answer2).toBe('')
169167
})
170168

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
isGeospatialState
88
} from '~/src/server/plugins/engine/components/FormComponent.js'
99
import { geospatialSchema } from '~/src/server/plugins/engine/components/helpers/geospatial.js'
10-
import { getGridRef } from '~/src/server/plugins/engine/components/helpers/gridref.js'
1110
import { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'
1211
import {
1312
type ErrorMessageTemplateList,
@@ -57,11 +56,9 @@ export class GeospatialField extends FormComponent {
5756
return ''
5857
}
5958

60-
return features
61-
.map((feature) => {
62-
return `${feature.properties.description}:\n${getGridRef(feature)}\n`
63-
})
64-
.join('\n')
59+
const unit = features.length === 1 ? 'feature' : 'features'
60+
61+
return `Added ${features.length} ${unit}`
6562
}
6663

6764
getDisplayStringFromState(state: FormSubmissionState) {
@@ -72,8 +69,8 @@ export class GeospatialField extends FormComponent {
7269

7370
getContextValueFromFormValue(
7471
features: GeospatialState | undefined
75-
): string[] | null {
76-
return features?.map(({ id }) => id) ?? null
72+
): string | null {
73+
return features ? JSON.stringify(features) : null
7774
}
7875

7976
getContextValueFromState(state: FormSubmissionState) {

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ describe('Location field formatting', () => {
240240
}
241241

242242
const answer = getAnswer(field, state, { format: 'email' })
243-
expect(answer).toBe(
244-
'My farm house:\nSJ 61896 71377\n\nMain gas line:\nSJ 62022 71500 to SJ 61904 71391\n\nMy Pony Paddock:\nSJ 61829 71378\n\nMy farm house #2:\nSJ 61894 71483\n\n'
245-
)
243+
expect(answer).toBe('Added 4 features\n')
246244
})
247245

248246
it('formats for data output', () => {
@@ -251,7 +249,7 @@ describe('Location field formatting', () => {
251249
}
252250

253251
const answer = getAnswer(field, state, { format: 'data' })
254-
expect(answer).toBe('a,b,c,d')
252+
expect(answer).toBe(JSON.stringify(validState))
255253
})
256254

257255
it('formats for summary display', () => {
@@ -260,9 +258,7 @@ describe('Location field formatting', () => {
260258
}
261259

262260
const answer = getAnswer(field, state, { format: 'summary' })
263-
expect(answer).toBe(
264-
'My farm house:<br>SJ 61896 71377<br>Main gas line:<br>SJ 62022 71500 to SJ 61904 71391<br>My Pony Paddock:<br>SJ 61829 71378<br>My farm house #2:<br>SJ 61894 71483<br>'
265-
)
261+
expect(answer).toBe('Added 4 features')
266262
})
267263
})
268264

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ export function getAnswer(
240240
field instanceof Components.MultilineTextField ||
241241
field instanceof Components.UkAddressField ||
242242
field instanceof Components.EastingNorthingField ||
243-
field instanceof Components.LatLongField ||
244-
field instanceof Components.GeospatialField
243+
field instanceof Components.LatLongField
245244
) {
246245
return markdown
247246
.parse(getAnswerMarkdown(field, state), { async: false })

src/server/plugins/engine/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ export type RichFormValue =
567567
| UkAddressState
568568
| EastingNorthingState
569569
| LatLongState
570+
| GeospatialState
570571

571572
export interface FormAdapterSubmissionMessageData {
572573
main: Record<string, RichFormValue | null>

0 commit comments

Comments
 (0)