@defra/forms-engine-plugin 4.5.3 → 4.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.public/javascripts/shared.min.js +1 -1
- package/.public/javascripts/shared.min.js.map +1 -1
- package/.server/client/javascripts/geospatial-map.js +4 -4
- package/.server/client/javascripts/geospatial-map.js.map +1 -1
- package/.server/client/javascripts/location-map.js +3 -3
- package/.server/client/javascripts/location-map.js.map +1 -1
- package/.server/client/javascripts/map.d.ts +6 -0
- package/.server/client/javascripts/map.js +13 -0
- package/.server/client/javascripts/map.js.map +1 -1
- package/.server/server/plugins/engine/components/GeospatialField.js +1 -0
- package/.server/server/plugins/engine/components/GeospatialField.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/geospatial.js +1 -1
- package/.server/server/plugins/engine/components/helpers/geospatial.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/geospatial.test.js +6 -1
- package/.server/server/plugins/engine/components/helpers/geospatial.test.js.map +1 -1
- package/package.json +2 -2
- package/src/client/javascripts/geospatial-map.js +4 -4
- package/src/client/javascripts/location-map.js +3 -3
- package/src/client/javascripts/map.js +13 -0
- package/src/server/plugins/engine/components/GeospatialField.test.ts +2 -2
- package/src/server/plugins/engine/components/GeospatialField.ts +2 -0
- package/src/server/plugins/engine/components/helpers/geospatial.test.js +8 -1
- package/src/server/plugins/engine/components/helpers/geospatial.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeospatialField.js","names":["FormComponent","isGeospatialState","geospatialSchema","messageTemplate","GeospatialField","constructor","def","props","options","formSchema","label","required","min","stateSchema","default","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","getDisplayStringFromFormValue","features","length","unit","getDisplayStringFromState","getContextValueFromFormValue","map","id","getContextValueFromState","getViewModel","payload","errors","viewModel","JSON","stringify","getErrors","fieldErrors","forEach","err","href","path","text","Number","getViewErrors","getAllPossibleErrors","staticErrors","advancedSettingsErrors","baseErrors","type","template","selectRequired","format"],"sources":["../../../../../src/server/plugins/engine/components/GeospatialField.ts"],"sourcesContent":["import { type GeospatialFieldComponent } from '@defra/forms-model'\nimport { type ArraySchema } from 'joi'\n\nimport { type ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport {\n FormComponent,\n isGeospatialState\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { geospatialSchema } from '~/src/server/plugins/engine/components/helpers/geospatial.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type GeospatialState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class GeospatialField extends FormComponent {\n declare options: GeospatialFieldComponent['options']\n declare formSchema: ArraySchema<GeospatialState>\n declare stateSchema: ArraySchema<GeospatialState>\n\n constructor(\n def: GeospatialFieldComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { options } = def\n\n let formSchema = geospatialSchema.label(this.label).required()\n\n if (options.required !== false) {\n formSchema = formSchema.min(1)\n }\n\n this.formSchema = formSchema\n this.stateSchema = formSchema.default(null)\n this.options = options\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(features: GeospatialState | undefined): string {\n if (!features?.length) {\n return ''\n }\n\n const unit = features.length === 1 ? 'location' : 'locations'\n\n return `Added ${features.length} ${unit}`\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const features = this.getFormValueFromState(state)\n\n return this.getDisplayStringFromFormValue(features)\n }\n\n getContextValueFromFormValue(\n features: GeospatialState | undefined\n ): string[] | null {\n return features?.map(({ id }) => id) ?? null\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const features = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(features)\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const viewModel = super.getViewModel(payload, errors)\n const value =\n typeof viewModel.value === 'string'\n ? viewModel.value\n : JSON.stringify(viewModel.value, null, 2)\n\n return {\n ...viewModel,\n value\n }\n }\n\n getErrors(errors?: FormSubmissionError[]): FormSubmissionError[] | undefined {\n const fieldErrors = super.getErrors(errors)\n\n fieldErrors?.forEach((err) => {\n if (err.name === 'description') {\n err.href = `#description_${err.path[1]}`\n err.text = `Enter description for location ${Number(err.path[1]) + 1}`\n }\n })\n\n return fieldErrors\n }\n\n getViewErrors(\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getErrors(errors)\n }\n\n isValue(value?: FormStateValue | FormState): value is GeospatialState {\n return isGeospatialState(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n const staticErrors = GeospatialField.getAllPossibleErrors()\n return {\n ...staticErrors,\n advancedSettingsErrors: [...staticErrors.advancedSettingsErrors]\n }\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.selectRequired },\n {\n type: 'array.min',\n template: '{{#title}} must contain at least 1 items'\n },\n { type: 'object.invalidjson', template: messageTemplate.format }\n ],\n advancedSettingsErrors: []\n }\n }\n}\n"],"mappings":"AAIA,SACEA,aAAa,EACbC,iBAAiB;AAEnB,SAASC,gBAAgB;AACzB,SAASC,eAAe;AAWxB,OAAO,MAAMC,eAAe,SAASJ,aAAa,CAAC;EAKjDK,WAAWA,CACTC,GAA6B,EAC7BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC;IAAQ,CAAC,GAAGF,GAAG;IAEvB,IAAIG,UAAU,GAAGP,gBAAgB,CAACQ,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC,CAACC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"GeospatialField.js","names":["FormComponent","isGeospatialState","geospatialSchema","messageTemplate","GeospatialField","constructor","def","props","options","formSchema","label","required","max","min","stateSchema","default","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","getDisplayStringFromFormValue","features","length","unit","getDisplayStringFromState","getContextValueFromFormValue","map","id","getContextValueFromState","getViewModel","payload","errors","viewModel","JSON","stringify","getErrors","fieldErrors","forEach","err","href","path","text","Number","getViewErrors","getAllPossibleErrors","staticErrors","advancedSettingsErrors","baseErrors","type","template","selectRequired","format"],"sources":["../../../../../src/server/plugins/engine/components/GeospatialField.ts"],"sourcesContent":["import { type GeospatialFieldComponent } from '@defra/forms-model'\nimport { type ArraySchema } from 'joi'\n\nimport { type ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport {\n FormComponent,\n isGeospatialState\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { geospatialSchema } from '~/src/server/plugins/engine/components/helpers/geospatial.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type GeospatialState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class GeospatialField extends FormComponent {\n declare options: GeospatialFieldComponent['options']\n declare formSchema: ArraySchema<GeospatialState>\n declare stateSchema: ArraySchema<GeospatialState>\n\n constructor(\n def: GeospatialFieldComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { options } = def\n\n let formSchema = geospatialSchema.label(this.label).required()\n\n formSchema = formSchema.max(50)\n\n if (options.required !== false) {\n formSchema = formSchema.min(1)\n }\n\n this.formSchema = formSchema\n this.stateSchema = formSchema.default(null)\n this.options = options\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(features: GeospatialState | undefined): string {\n if (!features?.length) {\n return ''\n }\n\n const unit = features.length === 1 ? 'location' : 'locations'\n\n return `Added ${features.length} ${unit}`\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const features = this.getFormValueFromState(state)\n\n return this.getDisplayStringFromFormValue(features)\n }\n\n getContextValueFromFormValue(\n features: GeospatialState | undefined\n ): string[] | null {\n return features?.map(({ id }) => id) ?? null\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const features = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(features)\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const viewModel = super.getViewModel(payload, errors)\n const value =\n typeof viewModel.value === 'string'\n ? viewModel.value\n : JSON.stringify(viewModel.value, null, 2)\n\n return {\n ...viewModel,\n value\n }\n }\n\n getErrors(errors?: FormSubmissionError[]): FormSubmissionError[] | undefined {\n const fieldErrors = super.getErrors(errors)\n\n fieldErrors?.forEach((err) => {\n if (err.name === 'description') {\n err.href = `#description_${err.path[1]}`\n err.text = `Enter description for location ${Number(err.path[1]) + 1}`\n }\n })\n\n return fieldErrors\n }\n\n getViewErrors(\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getErrors(errors)\n }\n\n isValue(value?: FormStateValue | FormState): value is GeospatialState {\n return isGeospatialState(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n const staticErrors = GeospatialField.getAllPossibleErrors()\n return {\n ...staticErrors,\n advancedSettingsErrors: [...staticErrors.advancedSettingsErrors]\n }\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.selectRequired },\n {\n type: 'array.min',\n template: '{{#title}} must contain at least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AAC,CAAC,CAAC,GAAG,CAAC,EAAE;MACxE;IACF,CAAC,CAAC;IAEF,OAAOJ,WAAW;EACpB;EAEAO,aAAaA,CACXZ,MAA8B,EACK;IACnC,OAAO,IAAI,CAACI,SAAS,CAACJ,MAAM,CAAC;EAC/B;EAEAb,OAAOA,CAACD,KAAkC,EAA4B;IACpE,OAAOnB,iBAAiB,CAACmB,KAAK,CAAC;EACjC;;EAEA;AACF;AACA;EACE2B,oBAAoBA,CAAA,EAA6B;IAC/C,MAAMC,YAAY,GAAG5C,eAAe,CAAC2C,oBAAoB,CAAC,CAAC;IAC3D,OAAO;MACL,GAAGC,YAAY;MACfC,sBAAsB,EAAE,CAAC,GAAGD,YAAY,CAACC,sBAAsB;IACjE,CAAC;EACH;;EAEA;AACF;AACA;EACE,OAAOF,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLG,UAAU,EAAE,CACV;QAAEC,IAAI,EAAE,UAAU;QAAEC,QAAQ,EAAEjD,eAAe,CAACkD;MAAe,CAAC,EAC9D;QACEF,IAAI,EAAE,WAAW;QACjBC,QAAQ,EAAE;MACZ,CAAC,EACD;QAAED,IAAI,EAAE,oBAAoB;QAAEC,QAAQ,EAAEjD,eAAe,CAACmD;MAAO,CAAC,CACjE;MACDL,sBAAsB,EAAE;IAC1B,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geospatial.js","names":["Bourne","JoiBase","Joi","extend","type","base","array","messages","coerce","from","method","value","helpers","trim","
|
|
1
|
+
{"version":3,"file":"geospatial.js","names":["Bourne","JoiBase","Joi","extend","type","base","array","messages","coerce","from","method","value","helpers","trim","parse","result","errors","error","coordinatesSchema","items","number","required","featurePropertiesSchema","object","keys","description","string","coordinateGridReference","centroidGridReference","featureGeometrySchema","valid","coordinates","when","switch","is","then","min","featureSchema","id","properties","geometry","geospatialSchema","unique"],"sources":["../../../../../../src/server/plugins/engine/components/helpers/geospatial.ts"],"sourcesContent":["import Bourne from '@hapi/bourne'\nimport JoiBase from 'joi'\n\nimport {\n type Coordinates,\n type Feature,\n type FeatureProperties,\n type Geometry\n} from '~/src/server/plugins/engine/types.js'\n\nconst Joi = JoiBase.extend({\n type: 'array',\n base: JoiBase.array(),\n messages: {\n 'object.invalidjson': '{{#label}} must be a valid json array string'\n },\n coerce: {\n from: 'string',\n method(value, helpers) {\n if (typeof value === 'string') {\n if (value.trim() === '') {\n return {\n value: []\n }\n }\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n return { value: Bourne.parse(value) }\n } catch {\n const result = {\n value,\n errors: [helpers.error('object.invalidjson')]\n }\n\n return result\n }\n } else {\n return {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n value\n }\n }\n }\n }\n}) as JoiBase.Root\n\nconst coordinatesSchema = Joi.array<Coordinates[]>()\n .items(Joi.number().required(), Joi.number().required())\n .required()\n\nconst featurePropertiesSchema = Joi.object<FeatureProperties>()\n .keys({\n description: Joi.string().required(),\n coordinateGridReference: Joi.string().required(),\n centroidGridReference: Joi.string().required()\n })\n .required()\n\nconst featureGeometrySchema = Joi.object<Geometry>().keys({\n type: Joi.string().valid('Point', 'LineString', 'Polygon').required(),\n coordinates: Joi.array()\n .when('type', {\n switch: [\n { is: 'Point', then: coordinatesSchema },\n {\n is: 'LineString',\n then: Joi.array().items(coordinatesSchema).min(2)\n },\n {\n is: 'Polygon',\n then: Joi.array().items(Joi.array().items(coordinatesSchema).min(3))\n }\n ]\n })\n .required()\n})\n\nconst featureSchema = Joi.object<Feature>().keys({\n id: Joi.string().required(),\n type: Joi.string().valid('Feature').required(),\n properties: featurePropertiesSchema,\n geometry: featureGeometrySchema\n})\n\nexport const geospatialSchema = Joi.array<Feature[]>()\n .items(featureSchema)\n .unique('id')\n .required()\n\n/**\n * @import { CustomHelpers } from 'joi'\n */\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,cAAc;AACjC,OAAOC,OAAO,MAAM,KAAK;AASzB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,CAAC,CAAC;AAEF,OAAO,MAAMY,gBAAgB,GAAGvC,GAAG,CAACI,KAAK,CAAY,CAAC,CACnDa,KAAK,CAACkB,aAAa,CAAC,CACpBK,MAAM,CAAC,IAAI,CAAC,CACZrB,QAAQ,CAAC,CAAC;;AAEb;AACA;AACA","ignoreList":[]}
|
|
@@ -35,8 +35,13 @@ describe('Geospatial validation helpers', () => {
|
|
|
35
35
|
});
|
|
36
36
|
test('it should validate an empty string', () => {
|
|
37
37
|
const result = geospatialSchema.validate('');
|
|
38
|
+
expect(result.error).toBeUndefined();
|
|
39
|
+
expect(result.value).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
test('it should validate an empty string with errors when required', () => {
|
|
42
|
+
const result = geospatialSchema.min(1).required().validate('');
|
|
38
43
|
expect(result.error).toBeDefined();
|
|
39
|
-
expect(result.value).
|
|
44
|
+
expect(result.value).toEqual([]);
|
|
40
45
|
});
|
|
41
46
|
});
|
|
42
47
|
//# sourceMappingURL=geospatial.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geospatial.test.js","names":["validState","geospatialSchema","describe","test","result","validate","expect","error","toBeUndefined","value","toBeDefined","toHaveLength","JSON","stringify","toBe","toEqual"],"sources":["../../../../../../src/server/plugins/engine/components/helpers/geospatial.test.js"],"sourcesContent":["import { validState } from '~/src/server/plugins/engine/components/helpers/__stubs__/geospatial.js'\nimport { geospatialSchema } from '~/src/server/plugins/engine/components/helpers/geospatial.js'\n\ndescribe('Geospatial validation helpers', () => {\n test('it should not have errors for valid geojson object', () => {\n const result = geospatialSchema.validate(validState)\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBeDefined()\n expect(result.value).toHaveLength(4)\n })\n\n test('it should not have errors for valid geojson string', () => {\n const result = geospatialSchema.validate(JSON.stringify(validState))\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBeDefined()\n expect(result.value).toHaveLength(4)\n })\n\n test('it should have errors for invalid json string', () => {\n const result = geospatialSchema.validate('{')\n\n expect(result.error).toBeDefined()\n expect(result.value).toBe('{')\n })\n\n test('it should have errors for invalid geojson string', () => {\n const result = geospatialSchema.validate('[')\n\n expect(result.error).toBeDefined()\n expect(result.value).toBe('[')\n })\n\n test('it should validate an empty array', () => {\n const result = geospatialSchema.validate('[]')\n\n expect(result.error).toBeUndefined()\n expect(result.value).toEqual([])\n })\n\n test('it should not validate an empty object', () => {\n const result = geospatialSchema.validate('{}')\n\n expect(result.error).toBeDefined()\n expect(result.value).toBeUndefined()\n })\n\n test('it should validate an empty string', () => {\n const result = geospatialSchema.validate('')\n\n expect(result.error).toBeDefined()\n expect(result.value).
|
|
1
|
+
{"version":3,"file":"geospatial.test.js","names":["validState","geospatialSchema","describe","test","result","validate","expect","error","toBeUndefined","value","toBeDefined","toHaveLength","JSON","stringify","toBe","toEqual","min","required"],"sources":["../../../../../../src/server/plugins/engine/components/helpers/geospatial.test.js"],"sourcesContent":["import { validState } from '~/src/server/plugins/engine/components/helpers/__stubs__/geospatial.js'\nimport { geospatialSchema } from '~/src/server/plugins/engine/components/helpers/geospatial.js'\n\ndescribe('Geospatial validation helpers', () => {\n test('it should not have errors for valid geojson object', () => {\n const result = geospatialSchema.validate(validState)\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBeDefined()\n expect(result.value).toHaveLength(4)\n })\n\n test('it should not have errors for valid geojson string', () => {\n const result = geospatialSchema.validate(JSON.stringify(validState))\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBeDefined()\n expect(result.value).toHaveLength(4)\n })\n\n test('it should have errors for invalid json string', () => {\n const result = geospatialSchema.validate('{')\n\n expect(result.error).toBeDefined()\n expect(result.value).toBe('{')\n })\n\n test('it should have errors for invalid geojson string', () => {\n const result = geospatialSchema.validate('[')\n\n expect(result.error).toBeDefined()\n expect(result.value).toBe('[')\n })\n\n test('it should validate an empty array', () => {\n const result = geospatialSchema.validate('[]')\n\n expect(result.error).toBeUndefined()\n expect(result.value).toEqual([])\n })\n\n test('it should not validate an empty object', () => {\n const result = geospatialSchema.validate('{}')\n\n expect(result.error).toBeDefined()\n expect(result.value).toBeUndefined()\n })\n\n test('it should validate an empty string', () => {\n const result = geospatialSchema.validate('')\n\n expect(result.error).toBeUndefined()\n expect(result.value).toEqual([])\n })\n\n test('it should validate an empty string with errors when required', () => {\n const result = geospatialSchema.min(1).required().validate('')\n\n expect(result.error).toBeDefined()\n expect(result.value).toEqual([])\n })\n})\n"],"mappings":"AAAA,SAASA,UAAU;AACnB,SAASC,gBAAgB;AAEzBC,QAAQ,CAAC,+BAA+B,EAAE,MAAM;EAC9CC,IAAI,CAAC,oDAAoD,EAAE,MAAM;IAC/D,MAAMC,MAAM,GAAGH,gBAAgB,CAACI,QAAQ,CAACL,UAAU,CAAC;IAEpDM,MAAM,CAACF,MAAM,CAACG,KAAK,CAAC,CAACC,aAAa,CAAC,CAAC;IACpCF,MAAM,CAACF,MAAM,CAACK,KAAK,CAAC,CAACC,WAAW,CAAC,CAAC;IAClCJ,MAAM,CAACF,MAAM,CAACK,KAAK,CAAC,CAACE,YAAY,CAAC,CAAC,CAAC;EACtC,CAAC,CAAC;EAEFR,IAAI,CAAC,oDAAoD,EAAE,MAAM;IAC/D,MAAMC,MAAM,GAAGH,gBAAgB,CAACI,QAAQ,CAACO,IAAI,CAACC,SAAS,CAACb,UAAU,CAAC,CAAC;IAEpEM,MAAM,CAACF,MAAM,CAACG,KAAK,CAAC,CAACC,aAAa,CAAC,CAAC;IACpCF,MAAM,CAACF,MAAM,CAACK,KAAK,CAAC,CAACC,WAAW,CAAC,CAAC;IAClCJ,MAAM,CAACF,MAAM,CAACK,KAAK,CAAC,CAACE,YAAY,CAAC,CAAC,CAAC;EACtC,CAAC,CAAC;EAEFR,IAAI,CAAC,+CAA+C,EAAE,MAAM;IAC1D,MAAMC,MAAM,GAAGH,gBAAgB,CAACI,QAAQ,CAAC,GAAG,CAAC;IAE7CC,MAAM,CAACF,MAAM,CAACG,KAAK,CAAC,CAACG,WAAW,CAAC,CAA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gB,CAACe,GAAG,CAAC,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC,CAACZ,QAAQ,CAAC,EAAE,CAAC;IAE9DC,MAAM,CAACF,MAAM,CAACG,KAAK,CAAC,CAACG,WAAW,CAAC,CAAC;IAClCJ,MAAM,CAACF,MAAM,CAACK,KAAK,CAAC,CAACM,OAAO,CAAC,EAAE,CAAC;EAClC,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra/forms-engine-plugin",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.4",
|
|
4
4
|
"description": "Defra forms engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"@defra/forms-model": "^3.0.637",
|
|
87
87
|
"@defra/hapi-tracing": "^1.29.0",
|
|
88
|
-
"@defra/interactive-map": "^0.0.
|
|
88
|
+
"@defra/interactive-map": "^0.0.17-alpha",
|
|
89
89
|
"@elastic/ecs-pino-format": "^1.5.0",
|
|
90
90
|
"@hapi/boom": "^10.0.1",
|
|
91
91
|
"@hapi/bourne": "^3.0.0",
|
|
@@ -12,19 +12,19 @@ const helpPanelConfig = {
|
|
|
12
12
|
showLabel: true,
|
|
13
13
|
label: 'How to use this map',
|
|
14
14
|
mobile: {
|
|
15
|
-
slot: '
|
|
15
|
+
slot: 'drawer',
|
|
16
16
|
open: true,
|
|
17
17
|
dismissible: true,
|
|
18
18
|
modal: false
|
|
19
19
|
},
|
|
20
20
|
tablet: {
|
|
21
|
-
slot: '
|
|
21
|
+
slot: 'drawer',
|
|
22
22
|
open: true,
|
|
23
23
|
dismissible: true,
|
|
24
24
|
modal: false
|
|
25
25
|
},
|
|
26
26
|
desktop: {
|
|
27
|
-
slot: '
|
|
27
|
+
slot: 'drawer',
|
|
28
28
|
open: true,
|
|
29
29
|
dismissible: true,
|
|
30
30
|
modal: false
|
|
@@ -245,7 +245,7 @@ function createFeatureHTML(feature, index, mapId, readonly) {
|
|
|
245
245
|
<dd class="govuk-summary-list__value">${typeDescriptions[feature.geometry.type]}</dd>
|
|
246
246
|
</div>
|
|
247
247
|
<div class="govuk-summary-list__row">
|
|
248
|
-
<dt class="govuk-summary-list__key">
|
|
248
|
+
<dt class="govuk-summary-list__key">Centre grid reference</dt>
|
|
249
249
|
<dd class="govuk-summary-list__value">${feature.properties.centroidGridReference}</dd>
|
|
250
250
|
</div>
|
|
251
251
|
<div class="govuk-summary-list__row">
|
|
@@ -447,19 +447,19 @@ export function processLocation(config, location, index) {
|
|
|
447
447
|
showLabel: true,
|
|
448
448
|
label: 'How to use the map',
|
|
449
449
|
mobile: {
|
|
450
|
-
slot: '
|
|
450
|
+
slot: 'drawer',
|
|
451
451
|
open: true,
|
|
452
452
|
dismissible: true,
|
|
453
453
|
modal: false
|
|
454
454
|
},
|
|
455
455
|
tablet: {
|
|
456
|
-
slot: '
|
|
456
|
+
slot: 'drawer',
|
|
457
457
|
open: true,
|
|
458
458
|
dismissible: true,
|
|
459
459
|
modal: false
|
|
460
460
|
},
|
|
461
461
|
desktop: {
|
|
462
|
-
slot: '
|
|
462
|
+
slot: 'drawer',
|
|
463
463
|
open: true,
|
|
464
464
|
dismissible: true,
|
|
465
465
|
modal: false
|
|
@@ -239,6 +239,18 @@ export function makeTileRequestTransformer(apiPath) {
|
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
|
|
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
|
+
|
|
242
254
|
/**
|
|
243
255
|
* Create a Defra map instance
|
|
244
256
|
* @param {string} mapId - the map id
|
|
@@ -310,6 +322,7 @@ export function createMap(mapId, initConfig, mapsConfig) {
|
|
|
310
322
|
}),
|
|
311
323
|
interactPlugin,
|
|
312
324
|
defra.searchPlugin({
|
|
325
|
+
transformRequest: transformGeocodeRequest,
|
|
313
326
|
osNamesURL: `${apiPath}/geocode-proxy?query={query}`,
|
|
314
327
|
width: '300px',
|
|
315
328
|
showMarker: false
|
|
@@ -110,7 +110,7 @@ describe('GeospatialField', () => {
|
|
|
110
110
|
|
|
111
111
|
expect(result.errors).toEqual([
|
|
112
112
|
expect.objectContaining({
|
|
113
|
-
text: '
|
|
113
|
+
text: 'Example geospatial must contain at least 1 items'
|
|
114
114
|
})
|
|
115
115
|
])
|
|
116
116
|
})
|
|
@@ -128,7 +128,7 @@ describe('GeospatialField', () => {
|
|
|
128
128
|
|
|
129
129
|
expect(result.errors).toEqual([
|
|
130
130
|
expect.objectContaining({
|
|
131
|
-
text: '
|
|
131
|
+
text: 'Example geospatial title must contain at least 1 items'
|
|
132
132
|
})
|
|
133
133
|
])
|
|
134
134
|
})
|
|
@@ -49,7 +49,14 @@ describe('Geospatial validation helpers', () => {
|
|
|
49
49
|
test('it should validate an empty string', () => {
|
|
50
50
|
const result = geospatialSchema.validate('')
|
|
51
51
|
|
|
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
|
+
|
|
52
59
|
expect(result.error).toBeDefined()
|
|
53
|
-
expect(result.value).
|
|
60
|
+
expect(result.value).toEqual([])
|
|
54
61
|
})
|
|
55
62
|
})
|