@defra/forms-engine-plugin 4.23.0 → 5.0.0-alpha.1
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/assets-manifest.json +3 -5
- package/.public/javascripts/im-core.min.js +2 -0
- package/.public/javascripts/im-core.min.js.map +1 -0
- package/.public/javascripts/shared.min.js +1 -1
- package/.public/javascripts/shared.min.js.map +1 -1
- package/.public/javascripts/vendor/@defra.min.js +1 -1
- package/.public/javascripts/vendor/@defra.min.js.map +1 -1
- package/.public/stylesheets/application.min.css +1 -1
- package/.public/stylesheets/application.min.css.map +1 -1
- package/.server/client/javascripts/geospatial-map.js +8 -6
- package/.server/client/javascripts/geospatial-map.js.map +1 -1
- package/.server/client/javascripts/location-map.js +8 -1
- 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 +10 -0
- package/.server/client/javascripts/map.js.map +1 -1
- package/.server/client/javascripts/sssi-dataset.d.ts +34 -0
- package/.server/client/javascripts/sssi-dataset.js +101 -0
- package/.server/client/javascripts/sssi-dataset.js.map +1 -0
- package/.server/client/stylesheets/shared.scss +0 -2
- package/.server/server/forms/register-as-a-unicorn-breeder.yaml +0 -14
- package/.server/server/forms/simple-form.yaml +106 -3
- package/.server/server/plugins/engine/components/AutocompleteField.d.ts +11 -11
- package/.server/server/plugins/engine/components/AutocompleteField.js +2 -2
- package/.server/server/plugins/engine/components/AutocompleteField.js.map +1 -1
- package/.server/server/plugins/engine/components/CheckboxesField.d.ts +3 -2
- package/.server/server/plugins/engine/components/CheckboxesField.js +4 -9
- package/.server/server/plugins/engine/components/CheckboxesField.js.map +1 -1
- package/.server/server/plugins/engine/components/ComponentCollection.d.ts +8 -7
- package/.server/server/plugins/engine/components/ComponentCollection.js +106 -51
- package/.server/server/plugins/engine/components/ComponentCollection.js.map +1 -1
- package/.server/server/plugins/engine/components/DatePartsField.d.ts +8 -6
- package/.server/server/plugins/engine/components/DatePartsField.js +27 -9
- package/.server/server/plugins/engine/components/DatePartsField.js.map +1 -1
- package/.server/server/plugins/engine/components/DeclarationField.d.ts +13 -11
- package/.server/server/plugins/engine/components/DeclarationField.js +31 -9
- package/.server/server/plugins/engine/components/DeclarationField.js.map +1 -1
- package/.server/server/plugins/engine/components/EastingNorthingField.d.ts +8 -5
- package/.server/server/plugins/engine/components/EastingNorthingField.js +42 -22
- package/.server/server/plugins/engine/components/EastingNorthingField.js.map +1 -1
- package/.server/server/plugins/engine/components/EmailAddressField.d.ts +11 -14
- package/.server/server/plugins/engine/components/EmailAddressField.js +2 -2
- package/.server/server/plugins/engine/components/EmailAddressField.js.map +1 -1
- package/.server/server/plugins/engine/components/FileUploadField.d.ts +14 -12
- package/.server/server/plugins/engine/components/FileUploadField.js +22 -12
- package/.server/server/plugins/engine/components/FileUploadField.js.map +1 -1
- package/.server/server/plugins/engine/components/FormComponent.d.ts +21 -12
- package/.server/server/plugins/engine/components/FormComponent.js +33 -14
- package/.server/server/plugins/engine/components/FormComponent.js.map +1 -1
- package/.server/server/plugins/engine/components/GeospatialField.d.ts +15 -12
- package/.server/server/plugins/engine/components/GeospatialField.js +21 -13
- package/.server/server/plugins/engine/components/GeospatialField.js.map +1 -1
- package/.server/server/plugins/engine/components/LatLongField.d.ts +8 -5
- package/.server/server/plugins/engine/components/LatLongField.js +32 -20
- package/.server/server/plugins/engine/components/LatLongField.js.map +1 -1
- package/.server/server/plugins/engine/components/ListFormComponent.d.ts +7 -6
- package/.server/server/plugins/engine/components/ListFormComponent.js +19 -7
- package/.server/server/plugins/engine/components/ListFormComponent.js.map +1 -1
- package/.server/server/plugins/engine/components/LocationFieldBase.d.ts +17 -16
- package/.server/server/plugins/engine/components/LocationFieldBase.js +2 -2
- package/.server/server/plugins/engine/components/LocationFieldBase.js.map +1 -1
- package/.server/server/plugins/engine/components/LocationFieldHelpers.d.ts +8 -3
- package/.server/server/plugins/engine/components/LocationFieldHelpers.js +14 -3
- package/.server/server/plugins/engine/components/LocationFieldHelpers.js.map +1 -1
- package/.server/server/plugins/engine/components/Markdown.d.ts +8 -7
- package/.server/server/plugins/engine/components/Markdown.js +5 -2
- package/.server/server/plugins/engine/components/Markdown.js.map +1 -1
- package/.server/server/plugins/engine/components/MonthYearField.d.ts +9 -7
- package/.server/server/plugins/engine/components/MonthYearField.js +26 -8
- package/.server/server/plugins/engine/components/MonthYearField.js.map +1 -1
- package/.server/server/plugins/engine/components/MultilineTextField.d.ts +10 -9
- package/.server/server/plugins/engine/components/MultilineTextField.js +2 -2
- package/.server/server/plugins/engine/components/MultilineTextField.js.map +1 -1
- package/.server/server/plugins/engine/components/NationalGridFieldNumberField.d.ts +2 -1
- package/.server/server/plugins/engine/components/NationalGridFieldNumberField.js +14 -6
- package/.server/server/plugins/engine/components/NationalGridFieldNumberField.js.map +1 -1
- package/.server/server/plugins/engine/components/NumberField.d.ts +10 -9
- package/.server/server/plugins/engine/components/NumberField.js +2 -2
- package/.server/server/plugins/engine/components/NumberField.js.map +1 -1
- package/.server/server/plugins/engine/components/OsGridRefField.d.ts +2 -1
- package/.server/server/plugins/engine/components/OsGridRefField.js +14 -6
- package/.server/server/plugins/engine/components/OsGridRefField.js.map +1 -1
- package/.server/server/plugins/engine/components/PaymentField.d.ts +12 -10
- package/.server/server/plugins/engine/components/PaymentField.js +21 -8
- package/.server/server/plugins/engine/components/PaymentField.js.map +1 -1
- package/.server/server/plugins/engine/components/SelectField.d.ts +11 -11
- package/.server/server/plugins/engine/components/SelectField.js +2 -2
- package/.server/server/plugins/engine/components/SelectField.js.map +1 -1
- package/.server/server/plugins/engine/components/SelectionControlField.d.ts +4 -4
- package/.server/server/plugins/engine/components/SelectionControlField.js +2 -2
- package/.server/server/plugins/engine/components/SelectionControlField.js.map +1 -1
- package/.server/server/plugins/engine/components/TelephoneNumberField.d.ts +10 -9
- package/.server/server/plugins/engine/components/TelephoneNumberField.js +2 -2
- package/.server/server/plugins/engine/components/TelephoneNumberField.js.map +1 -1
- package/.server/server/plugins/engine/components/UkAddressField.d.ts +12 -10
- package/.server/server/plugins/engine/components/UkAddressField.js +29 -17
- package/.server/server/plugins/engine/components/UkAddressField.js.map +1 -1
- package/.server/server/plugins/engine/components/YesNoField.d.ts +3 -0
- package/.server/server/plugins/engine/components/YesNoField.js +9 -0
- package/.server/server/plugins/engine/components/YesNoField.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/components.d.ts +3 -2
- package/.server/server/plugins/engine/components/helpers/components.js +11 -8
- package/.server/server/plugins/engine/components/helpers/components.js.map +1 -1
- package/.server/server/plugins/engine/components/types.d.ts +8 -1
- package/.server/server/plugins/engine/components/types.js.map +1 -1
- package/.server/server/plugins/engine/configureEnginePlugin.js +8 -1
- package/.server/server/plugins/engine/configureEnginePlugin.js.map +1 -1
- package/.server/server/plugins/engine/form-context.d.ts +1 -0
- package/.server/server/plugins/engine/form-context.js +4 -2
- package/.server/server/plugins/engine/form-context.js.map +1 -1
- package/.server/server/plugins/engine/helpers.d.ts +1 -1
- package/.server/server/plugins/engine/helpers.js +8 -13
- package/.server/server/plugins/engine/helpers.js.map +1 -1
- package/.server/server/plugins/engine/i18n/buildValidationMessages.d.ts +39 -0
- package/.server/server/plugins/engine/i18n/buildValidationMessages.js +50 -0
- package/.server/server/plugins/engine/i18n/buildValidationMessages.js.map +1 -0
- package/.server/server/plugins/engine/i18n/createFormTranslator.d.ts +5 -0
- package/.server/server/plugins/engine/i18n/createFormTranslator.js +18 -0
- package/.server/server/plugins/engine/i18n/createFormTranslator.js.map +1 -0
- package/.server/server/plugins/engine/i18n/createTranslator.d.ts +9 -0
- package/.server/server/plugins/engine/i18n/createTranslator.js +51 -0
- package/.server/server/plugins/engine/i18n/createTranslator.js.map +1 -0
- package/.server/server/plugins/engine/i18n/extractBaseTranslations.d.ts +5 -0
- package/.server/server/plugins/engine/i18n/extractBaseTranslations.js +57 -0
- package/.server/server/plugins/engine/i18n/extractBaseTranslations.js.map +1 -0
- package/.server/server/plugins/engine/i18n/index.d.ts +18 -0
- package/.server/server/plugins/engine/i18n/index.js +71 -0
- package/.server/server/plugins/engine/i18n/index.js.map +1 -0
- package/.server/server/plugins/engine/i18n/translations/cy.json +271 -0
- package/.server/server/plugins/engine/i18n/translations/en-GB.json +271 -0
- package/.server/server/plugins/engine/i18n/types.d.ts +41 -0
- package/.server/server/plugins/engine/i18n/types.js +2 -0
- package/.server/server/plugins/engine/i18n/types.js.map +1 -0
- package/.server/server/plugins/engine/index.js +3 -2
- package/.server/server/plugins/engine/index.js.map +1 -1
- package/.server/server/plugins/engine/models/FormModel.d.ts +9 -1
- package/.server/server/plugins/engine/models/FormModel.js +44 -18
- package/.server/server/plugins/engine/models/FormModel.js.map +1 -1
- package/.server/server/plugins/engine/models/SummaryViewModel.d.ts +5 -2
- package/.server/server/plugins/engine/models/SummaryViewModel.js +44 -18
- package/.server/server/plugins/engine/models/SummaryViewModel.js.map +1 -1
- package/.server/server/plugins/engine/options.js +2 -1
- package/.server/server/plugins/engine/options.js.map +1 -1
- package/.server/server/plugins/engine/outputFormatters/adapter/v1.js +4 -0
- package/.server/server/plugins/engine/outputFormatters/adapter/v1.js.map +1 -1
- package/.server/server/plugins/engine/outputFormatters/human/v1.js +2 -1
- package/.server/server/plugins/engine/outputFormatters/human/v1.js.map +1 -1
- package/.server/server/plugins/engine/outputFormatters/machine/v1.js +7 -6
- package/.server/server/plugins/engine/outputFormatters/machine/v1.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/FileUploadPageController.d.ts +2 -1
- package/.server/server/plugins/engine/pageControllers/FileUploadPageController.js +6 -3
- package/.server/server/plugins/engine/pageControllers/FileUploadPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/PageController.d.ts +3 -1
- package/.server/server/plugins/engine/pageControllers/PageController.js +11 -1
- package/.server/server/plugins/engine/pageControllers/PageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/QuestionPageController.d.ts +4 -2
- package/.server/server/plugins/engine/pageControllers/QuestionPageController.js +52 -21
- package/.server/server/plugins/engine/pageControllers/QuestionPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/RepeatPageController.d.ts +3 -2
- package/.server/server/plugins/engine/pageControllers/RepeatPageController.js +63 -26
- package/.server/server/plugins/engine/pageControllers/RepeatPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/StartPageController.d.ts +3 -1
- package/.server/server/plugins/engine/pageControllers/StartPageController.js +2 -2
- package/.server/server/plugins/engine/pageControllers/StartPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/StatusPageController.js +12 -2
- package/.server/server/plugins/engine/pageControllers/StatusPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/SummaryPageController.d.ts +4 -3
- package/.server/server/plugins/engine/pageControllers/SummaryPageController.js +44 -28
- package/.server/server/plugins/engine/pageControllers/SummaryPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/__stubs__/translator.d.ts +2 -0
- package/.server/server/plugins/engine/pageControllers/__stubs__/translator.js +24 -0
- package/.server/server/plugins/engine/pageControllers/__stubs__/translator.js.map +1 -0
- package/.server/server/plugins/engine/pageControllers/errors.d.ts +1 -1
- package/.server/server/plugins/engine/pageControllers/errors.js +3 -2
- package/.server/server/plugins/engine/pageControllers/errors.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/helpers/submission.d.ts +3 -2
- package/.server/server/plugins/engine/pageControllers/helpers/submission.js +4 -4
- package/.server/server/plugins/engine/pageControllers/helpers/submission.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/validationOptions.d.ts +7 -3
- package/.server/server/plugins/engine/pageControllers/validationOptions.js +34 -33
- package/.server/server/plugins/engine/pageControllers/validationOptions.js.map +1 -1
- package/.server/server/plugins/engine/plugin.js +2 -0
- package/.server/server/plugins/engine/plugin.js.map +1 -1
- package/.server/server/plugins/engine/routes/index.js +4 -1
- package/.server/server/plugins/engine/routes/index.js.map +1 -1
- package/.server/server/plugins/engine/routes/questions.js +5 -2
- package/.server/server/plugins/engine/routes/questions.js.map +1 -1
- package/.server/server/plugins/engine/types/index.d.ts +1 -0
- package/.server/server/plugins/engine/types/index.js.map +1 -1
- package/.server/server/plugins/engine/types/schema.js +1 -0
- package/.server/server/plugins/engine/types/schema.js.map +1 -1
- package/.server/server/plugins/engine/types.d.ts +12 -1
- package/.server/server/plugins/engine/types.js.map +1 -1
- package/.server/server/plugins/engine/views/components/_location-field-base.html +4 -2
- package/.server/server/plugins/engine/views/components/fileuploadfield.html +3 -3
- package/.server/server/plugins/engine/views/components/geospatialfield.html +4 -1
- package/.server/server/plugins/engine/views/components/nationalgridfieldnumberfield.html +1 -1
- package/.server/server/plugins/engine/views/components/osgridreffield.html +1 -1
- package/.server/server/plugins/engine/views/components/paymentfield.html +8 -8
- package/.server/server/plugins/engine/views/components/ukaddressfield.html +4 -4
- package/.server/server/plugins/engine/views/confirmation.html +4 -4
- package/.server/server/plugins/engine/views/exit.html +4 -4
- package/.server/server/plugins/engine/views/file-upload.html +3 -3
- package/.server/server/plugins/engine/views/index.html +3 -3
- package/.server/server/plugins/engine/views/item-delete.html +1 -1
- package/.server/server/plugins/engine/views/partials/form.html +3 -3
- package/.server/server/plugins/engine/views/partials/preview-banner.html +4 -4
- package/.server/server/plugins/engine/views/partials/warn-missing-notification-email.html +4 -5
- package/.server/server/plugins/engine/views/repeat-list-summary.html +4 -4
- package/.server/server/plugins/engine/views/summary.html +14 -7
- package/.server/server/plugins/map/routes/index.js +1 -1
- package/.server/server/plugins/map/routes/index.js.map +1 -1
- package/.server/server/plugins/map/types.d.ts +1 -25
- package/.server/server/plugins/map/types.js +1 -16
- package/.server/server/plugins/map/types.js.map +1 -1
- package/.server/server/plugins/nunjucks/enviroment.test.js +10 -0
- package/.server/server/plugins/nunjucks/enviroment.test.js.map +1 -1
- package/.server/server/plugins/nunjucks/environment.d.ts +8 -0
- package/.server/server/plugins/nunjucks/environment.js +13 -0
- package/.server/server/plugins/nunjucks/environment.js.map +1 -1
- package/.server/server/plugins/nunjucks/filters/answer.js +9 -1
- package/.server/server/plugins/nunjucks/filters/answer.js.map +1 -1
- package/.server/server/plugins/nunjucks/filters/answer.test.js +13 -2
- package/.server/server/plugins/nunjucks/filters/answer.test.js.map +1 -1
- package/.server/server/plugins/nunjucks/filters/field.d.ts +1 -1
- package/.server/server/plugins/postcode-lookup/models/index.d.ts +24 -19
- package/.server/server/plugins/postcode-lookup/models/index.js +83 -76
- package/.server/server/plugins/postcode-lookup/models/index.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/routes/index.js +7 -13
- package/.server/server/plugins/postcode-lookup/routes/index.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/types.d.ts +1 -0
- package/.server/server/plugins/postcode-lookup/types.js +1 -0
- package/.server/server/plugins/postcode-lookup/types.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/views/postcode-lookup-details.html +3 -3
- package/.server/server/types.d.ts +2 -1
- package/.server/server/types.js.map +1 -1
- package/.server/server/utils/utils.d.ts +5 -0
- package/.server/server/utils/utils.js +16 -0
- package/.server/server/utils/utils.js.map +1 -1
- package/.server/typings/hapi/index.d.js.map +1 -1
- package/package.json +5 -4
- package/src/client/javascripts/geospatial-map.js +10 -6
- package/src/client/javascripts/location-map.js +11 -0
- package/src/client/javascripts/map.js +10 -0
- package/src/client/javascripts/sssi-dataset.js +106 -0
- package/src/client/stylesheets/shared.scss +0 -2
- package/src/server/forms/register-as-a-unicorn-breeder.yaml +0 -14
- package/src/server/forms/simple-form.yaml +106 -3
- package/src/server/plugins/engine/components/AutocompleteField.ts +3 -6
- package/src/server/plugins/engine/components/CheckboxesField.ts +12 -11
- package/src/server/plugins/engine/components/ComponentCollection.ts +143 -61
- package/src/server/plugins/engine/components/DatePartsField.ts +33 -11
- package/src/server/plugins/engine/components/DeclarationField.ts +37 -14
- package/src/server/plugins/engine/components/EastingNorthingField.ts +83 -22
- package/src/server/plugins/engine/components/EmailAddressField.ts +4 -7
- package/src/server/plugins/engine/components/FileUploadField.ts +28 -22
- package/src/server/plugins/engine/components/FormComponent.ts +49 -12
- package/src/server/plugins/engine/components/GeospatialField.ts +38 -21
- package/src/server/plugins/engine/components/LatLongField.ts +52 -21
- package/src/server/plugins/engine/components/ListFormComponent.ts +26 -10
- package/src/server/plugins/engine/components/LocationFieldBase.ts +5 -8
- package/src/server/plugins/engine/components/LocationFieldHelpers.ts +24 -4
- package/src/server/plugins/engine/components/Markdown.ts +7 -3
- package/src/server/plugins/engine/components/MonthYearField.ts +32 -10
- package/src/server/plugins/engine/components/MultilineTextField.ts +5 -8
- package/src/server/plugins/engine/components/NationalGridFieldNumberField.ts +25 -11
- package/src/server/plugins/engine/components/NumberField.ts +3 -4
- package/src/server/plugins/engine/components/OsGridRefField.ts +25 -9
- package/src/server/plugins/engine/components/PaymentField.ts +22 -12
- package/src/server/plugins/engine/components/SelectField.ts +3 -6
- package/src/server/plugins/engine/components/SelectionControlField.ts +7 -8
- package/src/server/plugins/engine/components/TelephoneNumberField.ts +4 -7
- package/src/server/plugins/engine/components/UkAddressField.ts +33 -18
- package/src/server/plugins/engine/components/YesNoField.ts +10 -0
- package/src/server/plugins/engine/components/helpers/components.ts +13 -6
- package/src/server/plugins/engine/components/types.ts +9 -0
- package/src/server/plugins/engine/configureEnginePlugin.ts +12 -1
- package/src/server/plugins/engine/form-context.ts +8 -2
- package/src/server/plugins/engine/helpers.ts +10 -18
- package/src/server/plugins/engine/i18n/buildValidationMessages.ts +69 -0
- package/src/server/plugins/engine/i18n/createFormTranslator.ts +33 -0
- package/src/server/plugins/engine/i18n/createTranslator.ts +61 -0
- package/src/server/plugins/engine/i18n/extractBaseTranslations.ts +61 -0
- package/src/server/plugins/engine/i18n/index.ts +80 -0
- package/src/server/plugins/engine/i18n/translations/cy.json +271 -0
- package/src/server/plugins/engine/i18n/translations/en-GB.json +271 -0
- package/src/server/plugins/engine/i18n/types.ts +62 -0
- package/src/server/plugins/engine/index.ts +4 -2
- package/src/server/plugins/engine/models/FormModel.ts +59 -23
- package/src/server/plugins/engine/models/SummaryViewModel.ts +68 -25
- package/src/server/plugins/engine/options.js +2 -1
- package/src/server/plugins/engine/outputFormatters/adapter/v1.ts +5 -0
- package/src/server/plugins/engine/outputFormatters/human/v1.ts +2 -3
- package/src/server/plugins/engine/outputFormatters/machine/v1.ts +9 -8
- package/src/server/plugins/engine/pageControllers/FileUploadPageController.ts +7 -3
- package/src/server/plugins/engine/pageControllers/PageController.ts +12 -1
- package/src/server/plugins/engine/pageControllers/QuestionPageController.ts +53 -21
- package/src/server/plugins/engine/pageControllers/RepeatPageController.ts +66 -29
- package/src/server/plugins/engine/pageControllers/StartPageController.ts +7 -2
- package/src/server/plugins/engine/pageControllers/StatusPageController.ts +10 -2
- package/src/server/plugins/engine/pageControllers/SummaryPageController.ts +48 -22
- package/src/server/plugins/engine/pageControllers/__stubs__/translator.ts +28 -0
- package/src/server/plugins/engine/pageControllers/errors.ts +4 -2
- package/src/server/plugins/engine/pageControllers/helpers/submission.ts +11 -4
- package/src/server/plugins/engine/pageControllers/validationOptions.ts +43 -53
- package/src/server/plugins/engine/plugin.ts +2 -0
- package/src/server/plugins/engine/routes/index.ts +9 -1
- package/src/server/plugins/engine/routes/questions.ts +5 -1
- package/src/server/plugins/engine/types/index.ts +5 -0
- package/src/server/plugins/engine/types/schema.ts +1 -0
- package/src/server/plugins/engine/types.ts +10 -0
- package/src/server/plugins/engine/views/components/_location-field-base.html +4 -2
- package/src/server/plugins/engine/views/components/fileuploadfield.html +3 -3
- package/src/server/plugins/engine/views/components/geospatialfield.html +4 -1
- package/src/server/plugins/engine/views/components/nationalgridfieldnumberfield.html +1 -1
- package/src/server/plugins/engine/views/components/osgridreffield.html +1 -1
- package/src/server/plugins/engine/views/components/paymentfield.html +8 -8
- package/src/server/plugins/engine/views/components/ukaddressfield.html +4 -4
- package/src/server/plugins/engine/views/confirmation.html +4 -4
- package/src/server/plugins/engine/views/exit.html +4 -4
- package/src/server/plugins/engine/views/file-upload.html +3 -3
- package/src/server/plugins/engine/views/index.html +3 -3
- package/src/server/plugins/engine/views/item-delete.html +1 -1
- package/src/server/plugins/engine/views/partials/form.html +3 -3
- package/src/server/plugins/engine/views/partials/preview-banner.html +4 -4
- package/src/server/plugins/engine/views/partials/warn-missing-notification-email.html +4 -5
- package/src/server/plugins/engine/views/repeat-list-summary.html +4 -4
- package/src/server/plugins/engine/views/summary.html +14 -7
- package/src/server/plugins/map/routes/index.js +1 -1
- package/src/server/plugins/map/types.js +1 -16
- package/src/server/plugins/nunjucks/environment.js +14 -0
- package/src/server/plugins/nunjucks/filters/answer.js +12 -1
- package/src/server/plugins/postcode-lookup/models/index.js +144 -87
- package/src/server/plugins/postcode-lookup/routes/index.js +13 -16
- package/src/server/plugins/postcode-lookup/types.js +1 -0
- package/src/server/plugins/postcode-lookup/views/postcode-lookup-details.html +3 -3
- package/src/server/types.ts +2 -0
- package/src/server/utils/utils.js +14 -0
- package/src/typings/hapi/index.d.ts +1 -0
- package/.public/javascripts/im-search-plugin.min.js +0 -2
- package/.public/javascripts/im-search-plugin.min.js.map +0 -1
- package/.public/javascripts/vendor/preact.min.js +0 -2
- package/.public/javascripts/vendor/preact.min.js.map +0 -1
- package/.server/server/plugins/engine/components/constants.d.ts +0 -1
- package/.server/server/plugins/engine/components/constants.js +0 -2
- package/.server/server/plugins/engine/components/constants.js.map +0 -1
- package/src/server/plugins/engine/components/constants.ts +0 -1
|
@@ -5,6 +5,7 @@ import { InvalidComponentStateError } from "../pageControllers/errors.js";
|
|
|
5
5
|
import { messageTemplate } from "../pageControllers/validationOptions.js";
|
|
6
6
|
import { FileStatus, UploadStatus } from "../types.js";
|
|
7
7
|
import { render } from "../../nunjucks/index.js";
|
|
8
|
+
import { resolveLanguage } from "../../../utils/utils.js";
|
|
8
9
|
export const uploadIdSchema = joi.string().uuid().required();
|
|
9
10
|
export const fileSchema = joi.object({
|
|
10
11
|
fileId: joi.string().uuid().required(),
|
|
@@ -83,16 +84,17 @@ export class FileUploadField extends FormComponent {
|
|
|
83
84
|
getFormValue(value) {
|
|
84
85
|
return this.isValue(value) ? value : undefined;
|
|
85
86
|
}
|
|
86
|
-
getDisplayStringFromFormValue(files) {
|
|
87
|
+
getDisplayStringFromFormValue(files, translator) {
|
|
87
88
|
if (!files?.length) {
|
|
88
89
|
return '';
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
return translator.t('components.fileUploadField.filesCount', {
|
|
92
|
+
count: files.length
|
|
93
|
+
});
|
|
92
94
|
}
|
|
93
|
-
getDisplayStringFromState(state) {
|
|
95
|
+
getDisplayStringFromState(state, translator) {
|
|
94
96
|
const files = this.getFormValueFromState(state);
|
|
95
|
-
return this.getDisplayStringFromFormValue(files);
|
|
97
|
+
return this.getDisplayStringFromFormValue(files, translator);
|
|
96
98
|
}
|
|
97
99
|
getContextValueFromFormValue(files) {
|
|
98
100
|
return files?.map(({
|
|
@@ -103,16 +105,20 @@ export class FileUploadField extends FormComponent {
|
|
|
103
105
|
const files = this.getFormValueFromState(state);
|
|
104
106
|
return this.getContextValueFromFormValue(files);
|
|
105
107
|
}
|
|
106
|
-
getViewModel(
|
|
108
|
+
getViewModel(context) {
|
|
109
|
+
const {
|
|
110
|
+
errors,
|
|
111
|
+
isForceAccess = false
|
|
112
|
+
} = context;
|
|
113
|
+
const {
|
|
114
|
+
t
|
|
115
|
+
} = context.translator;
|
|
107
116
|
const {
|
|
108
117
|
options,
|
|
109
118
|
page,
|
|
110
119
|
schema
|
|
111
120
|
} = this;
|
|
112
|
-
|
|
113
|
-
// Allow preview URL direct access
|
|
114
|
-
const isForceAccess = 'force' in query;
|
|
115
|
-
const viewModel = super.getViewModel(payload, errors);
|
|
121
|
+
const viewModel = super.getViewModel(context);
|
|
116
122
|
const {
|
|
117
123
|
attributes,
|
|
118
124
|
id,
|
|
@@ -133,7 +139,7 @@ export class FileUploadField extends FormComponent {
|
|
|
133
139
|
} = form;
|
|
134
140
|
const tag = {
|
|
135
141
|
classes: 'govuk-tag--green',
|
|
136
|
-
text: '
|
|
142
|
+
text: t('components.fileUploadField.uploaded')
|
|
137
143
|
};
|
|
138
144
|
const valueHtml = render.view('components/fileuploadfield-value.html', {
|
|
139
145
|
context: {
|
|
@@ -217,6 +223,10 @@ export class FileUploadField extends FormComponent {
|
|
|
217
223
|
return FileUploadField.getAllPossibleErrors();
|
|
218
224
|
}
|
|
219
225
|
async onSubmit(request, metadata, context) {
|
|
226
|
+
const language = resolveLanguage(request);
|
|
227
|
+
const {
|
|
228
|
+
t
|
|
229
|
+
} = this.model.createTranslator(language);
|
|
220
230
|
const notificationEmail = metadata.notificationEmail;
|
|
221
231
|
if (!notificationEmail) {
|
|
222
232
|
// this should not happen because notificationEmail is checked further up
|
|
@@ -249,7 +259,7 @@ export class FileUploadField extends FormComponent {
|
|
|
249
259
|
// Failed to persist files. We can't recover from this, the only real way we can recover the submissions is
|
|
250
260
|
// by resetting the problematic components and letting the user re-try.
|
|
251
261
|
// Scenarios: file missing from S3, invalid retrieval key (timing problem), etc.
|
|
252
|
-
throw new InvalidComponentStateError(this, '
|
|
262
|
+
throw new InvalidComponentStateError(this, t('components.fileUploadField.uploadFailed'));
|
|
253
263
|
}
|
|
254
264
|
throw error;
|
|
255
265
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileUploadField.js","names":["Boom","joi","FormComponent","isUploadState","InvalidComponentStateError","messageTemplate","FileStatus","UploadStatus","render","uploadIdSchema","string","uuid","required","fileSchema","object","fileId","filename","contentLength","number","tempFileSchema","append","fileStatus","valid","complete","rejected","pending","errorMessage","optional","formFileSchema","metadataSchema","keys","retrievalKey","email","tempStatusSchema","uploadStatus","ready","metadata","form","file","array","items","single","numberOfRejectedFiles","formStatusSchema","itemSchema","uploadId","tempItemSchema","status","formItemSchema","FileUploadField","constructor","def","props","options","schema","formSchema","label","length","max","min","stateSchema","default","allow","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","getDisplayStringFromFormValue","files","unit","getDisplayStringFromState","getContextValueFromFormValue","map","getContextValueFromState","getViewModel","payload","errors","query","page","isForceAccess","viewModel","attributes","id","filtered","filter","count","rows","item","index","tag","classes","text","valueHtml","view","context","params","trim","keyHtml","path","href","getHref","push","visuallyHiddenText","key","html","actions","accept","allowsMultiple","summaryList","multiple","upload","getAllPossibleErrors","onSubmit","request","notificationEmail","Error","app","model","services","formSubmissionService","values","initiatedRetrievalKey","persistFiles","error","isBoom","output","statusCode","baseErrors","type","template","selectRequired","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/FileUploadField.ts"],"sourcesContent":["import {\n type FileUploadFieldComponent,\n type FormMetadata\n} from '@defra/forms-model'\nimport Boom from '@hapi/boom'\nimport joi, { type ArraySchema } from 'joi'\n\nimport {\n FormComponent,\n isUploadState\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { InvalidComponentStateError } from '~/src/server/plugins/engine/pageControllers/errors.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n FileStatus,\n UploadStatus,\n type ErrorMessageTemplateList,\n type FileState,\n type FileUpload,\n type FileUploadMetadata,\n type FormContext,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type SummaryList,\n type SummaryListAction,\n type SummaryListRow,\n type UploadState,\n type UploadStatusFileResponse,\n type UploadStatusResponse\n} from '~/src/server/plugins/engine/types.js'\nimport { render } from '~/src/server/plugins/nunjucks/index.js'\nimport {\n type FormQuery,\n type FormRequestPayload\n} from '~/src/server/routes/types.js'\n\nexport const uploadIdSchema = joi.string().uuid().required()\n\nexport const fileSchema = joi\n .object<FileUpload>({\n fileId: joi.string().uuid().required(),\n filename: joi.string().required(),\n contentLength: joi.number().required()\n })\n .required()\n\nexport const tempFileSchema = fileSchema.append({\n fileStatus: joi\n .string()\n .valid(FileStatus.complete, FileStatus.rejected, FileStatus.pending)\n .required(),\n errorMessage: joi.string().optional()\n})\n\nexport const formFileSchema = fileSchema.append({\n fileStatus: joi.string().valid(FileStatus.complete).required()\n})\n\nexport const metadataSchema = joi\n .object<FileUploadMetadata>()\n .keys({\n retrievalKey: joi.string().email().required()\n })\n .required()\n\nexport const tempStatusSchema = joi\n .object<UploadStatusFileResponse>({\n uploadStatus: joi\n .string()\n .valid(UploadStatus.ready, UploadStatus.pending)\n .required(),\n metadata: metadataSchema,\n form: joi\n .object()\n .required()\n .keys({\n file: joi.array().items(tempFileSchema).single().required()\n }),\n numberOfRejectedFiles: joi.number().optional()\n })\n .required()\n\nexport const formStatusSchema = joi\n .object<UploadStatusResponse>({\n uploadStatus: joi.string().valid(UploadStatus.ready).required(),\n metadata: metadataSchema,\n form: joi.object().required().keys({\n file: formFileSchema\n }),\n numberOfRejectedFiles: joi.number().required()\n })\n .required()\n\nexport const itemSchema = joi.object<FileState>({\n uploadId: uploadIdSchema\n})\n\nexport const tempItemSchema = itemSchema.append({\n status: tempStatusSchema\n})\n\nexport const formItemSchema = itemSchema.append({\n status: formStatusSchema\n})\n\nexport class FileUploadField extends FormComponent {\n declare options: FileUploadFieldComponent['options']\n declare schema: FileUploadFieldComponent['schema']\n declare formSchema: ArraySchema<FileState>\n declare stateSchema: ArraySchema<FileState>\n\n constructor(\n def: FileUploadFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, schema } = def\n\n let formSchema = joi\n .array<FileState>()\n .label(this.label)\n .single()\n .required()\n\n if (options.required === false) {\n formSchema = formSchema.optional()\n }\n\n if (typeof schema.length !== 'number') {\n if (typeof schema.max === 'number') {\n formSchema = formSchema.max(schema.max)\n }\n\n if (typeof schema.min === 'number') {\n formSchema = formSchema.min(schema.min)\n } else if (options.required !== false) {\n formSchema = formSchema.min(1)\n }\n } else {\n formSchema = formSchema.length(schema.length)\n }\n\n this.formSchema = formSchema.items(formItemSchema)\n this.stateSchema = formSchema\n .items(formItemSchema)\n .default(null)\n .allow(null)\n\n this.options = options\n this.schema = schema\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(files: FileState[] | undefined): string {\n if (!files?.length) {\n return ''\n }\n\n const unit = files.length === 1 ? 'file' : 'files'\n return `Uploaded ${files.length} ${unit}`\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const files = this.getFormValueFromState(state)\n\n return this.getDisplayStringFromFormValue(files)\n }\n\n getContextValueFromFormValue(\n files: UploadState | undefined\n ): string[] | null {\n return files?.map(({ status }) => status.form.file.fileId) ?? null\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const files = this.getFormValueFromState(state)\n return this.getContextValueFromFormValue(files)\n }\n\n getViewModel(\n payload: FormPayload,\n errors?: FormSubmissionError[],\n query: FormQuery = {}\n ) {\n const { options, page, schema } = this\n\n // Allow preview URL direct access\n const isForceAccess = 'force' in query\n\n const viewModel = super.getViewModel(payload, errors)\n const { attributes, id, value } = viewModel\n\n const files = this.getFormValue(value) ?? []\n const filtered = files.filter(\n (file) => file.status.form.file.fileStatus === FileStatus.complete\n )\n const count = filtered.length\n\n const rows: SummaryListRow[] = filtered.map((item, index) => {\n const { status } = item\n const { form } = status\n const { file } = form\n\n const tag = { classes: 'govuk-tag--green', text: 'Uploaded' }\n\n const valueHtml = render\n .view('components/fileuploadfield-value.html', {\n context: { params: { tag } }\n })\n .trim()\n\n const keyHtml = render\n .view('components/fileuploadfield-key.html', {\n context: {\n params: {\n name: file.filename,\n errorMessage: errors && file.errorMessage\n }\n }\n })\n .trim()\n\n const items: SummaryListAction[] = []\n\n // Remove summary list actions from previews\n if (!isForceAccess) {\n const path = `/${file.fileId}/confirm-delete`\n const href = page?.getHref(`${page.path}${path}`) ?? '#'\n\n items.push({\n href,\n text: 'Remove',\n classes: 'govuk-link--no-visited-state',\n attributes: { id: `${id}__${index}` },\n visuallyHiddenText: file.filename\n })\n }\n\n return {\n key: {\n html: keyHtml\n },\n value: {\n html: valueHtml\n },\n actions: {\n items\n }\n } satisfies SummaryListRow\n })\n\n // Set up the `accept` attribute\n if ('accept' in options && options.accept) {\n attributes.accept = options.accept\n }\n\n // Allow multiple file selection when schema permits more than 1 file\n const allowsMultiple = schema.max !== 1 && schema.length !== 1\n\n const summaryList: SummaryList = {\n classes: 'govuk-summary-list--long-key',\n rows\n }\n\n return {\n ...viewModel,\n\n // File input can't have a initial value\n value: '',\n\n // Override the component name we send to CDP\n name: 'file',\n\n // Enable multi-file selection in the file picker\n ...(allowsMultiple && { multiple: true }),\n\n upload: {\n count,\n summaryList\n }\n }\n }\n\n isValue(value?: FormStateValue | FormState): value is UploadState {\n return isUploadState(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return FileUploadField.getAllPossibleErrors()\n }\n\n async onSubmit(\n request: FormRequestPayload,\n metadata: FormMetadata,\n context: FormContext\n ) {\n const notificationEmail = metadata.notificationEmail\n\n if (!notificationEmail) {\n // this should not happen because notificationEmail is checked further up\n // the chain in SummaryPageController before submitForm is called.\n throw new Error('Unexpected missing notificationEmail in metadata')\n }\n\n if (!request.app.model?.services.formSubmissionService) {\n throw new Error('No form submission service available in app model')\n }\n\n const { formSubmissionService } = request.app.model.services\n const values = this.getFormValueFromState(context.state) ?? []\n\n const files = values.map((value) => ({\n fileId: value.status.form.file.fileId,\n initiatedRetrievalKey: value.status.metadata.retrievalKey\n }))\n\n if (!files.length) {\n return\n }\n\n try {\n await formSubmissionService.persistFiles(files, notificationEmail)\n } catch (error) {\n if (\n Boom.isBoom(error) &&\n (error.output.statusCode === 403 || // Forbidden - retrieval key invalid\n error.output.statusCode === 404 || // Not Found - file not found\n error.output.statusCode === 410) // Gone - file expired (took to long to submit, etc)\n ) {\n // Failed to persist files. We can't recover from this, the only real way we can recover the submissions is\n // by resetting the problematic components and letting the user re-try.\n // Scenarios: file missing from S3, invalid retrieval key (timing problem), etc.\n throw new InvalidComponentStateError(\n this,\n 'There was a problem with your uploaded files. Re-upload them before submitting the form again.'\n )\n }\n\n throw error\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: 'selectRequired', template: messageTemplate.selectRequired },\n {\n type: 'filesMimes',\n template: 'The selected file must be a {{#limit}}'\n },\n {\n type: 'filesSize',\n template: 'The selected file must be smaller than 100MB'\n },\n { type: 'filesEmpty', template: 'The selected file is empty' },\n { type: 'filesVirus', template: 'The selected file contains a virus' },\n {\n type: 'filesPartial',\n template: 'The selected file has not fully uploaded'\n },\n {\n type: 'filesError',\n template: 'The selected file could not be uploaded – try again'\n }\n ],\n advancedSettingsErrors: [\n {\n type: 'filesMin',\n template: 'You must upload {{#limit}} files or more'\n },\n {\n type: 'filesMax',\n template: 'You can only upload {{#limit}} files or less'\n },\n {\n type: 'filesExact',\n template: 'You must upload exactly {{#limit}} files'\n }\n ]\n }\n }\n}\n"],"mappings":"AAIA,OAAOA,IAAI,MAAM,YAAY;AAC7B,OAAOC,GAAG,MAA4B,KAAK;AAE3C,SACEC,aAAa,EACbC,aAAa;AAEf,SAASC,0BAA0B;AACnC,SAASC,eAAe;AACxB,SACEC,UAAU,EACVC,YAAY;AAkBd,SAASC,MAAM;AAMf,OAAO,MAAMC,cAAc,GAAGR,GAAG,CAACS,MAAM,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;AAE5D,OAAO,MAAMC,UAAU,GAAGZ,GAAG,CAC1Ba,MAAM,CAAa;EAClBC,MAAM,EAAEd,GAAG,CAACS,MAAM,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACtCI,QAAQ,EAAEf,GAAG,CAACS,MAAM,CAAC,CAAC,CAACE,QAAQ,CAAC,CAAC;EACjCK,aAAa,EAAEhB,GAAG,CAACiB,MAAM,CAAC,CAAC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ACV;QAAEC,IAAI,EAAE,gBAAgB;QAAEC,QAAQ,EAAE/H,eAAe,CAACgI;MAAe,CAAC,EACpE;QACEF,IAAI,EAAE,YAAY;QAClBC,QAAQ,EAAE;MACZ,CAAC,EACD;QACED,IAAI,EAAE,WAAW;QACjBC,QAAQ,EAAE;MACZ,CAAC,EACD;QAAED,IAAI,EAAE,YAAY;QAAEC,QAAQ,EAAE;MAA6B,CAAC,EAC9D;QAAED,IAAI,EAAE,YAAY;QAAEC,QAAQ,EAAE;MAAqC,CAAC,EACtE;QACED,IAAI,EAAE,cAAc;QACpBC,QAAQ,EAAE;MACZ,CAAC,EACD;QACED,IAAI,EAAE,YAAY;QAClBC,QAAQ,EAAE;MACZ,CAAC,CACF;MACDE,sBAAsB,EAAE,CACtB;QACEH,IAAI,EAAE,UAAU;QAChBC,QAAQ,EAAE;MACZ,CAAC,EACD;QACED,IAAI,EAAE,UAAU;QAChBC,QAAQ,EAAE;MACZ,CAAC,EACD;QACED,IAAI,EAAE,YAAY;QAClBC,QAAQ,EAAE;MACZ,CAAC;IAEL,CAAC;EACH;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"FileUploadField.js","names":["Boom","joi","FormComponent","isUploadState","InvalidComponentStateError","messageTemplate","FileStatus","UploadStatus","render","resolveLanguage","uploadIdSchema","string","uuid","required","fileSchema","object","fileId","filename","contentLength","number","tempFileSchema","append","fileStatus","valid","complete","rejected","pending","errorMessage","optional","formFileSchema","metadataSchema","keys","retrievalKey","email","tempStatusSchema","uploadStatus","ready","metadata","form","file","array","items","single","numberOfRejectedFiles","formStatusSchema","itemSchema","uploadId","tempItemSchema","status","formItemSchema","FileUploadField","constructor","def","props","options","schema","formSchema","label","length","max","min","stateSchema","default","allow","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","getDisplayStringFromFormValue","files","translator","t","count","getDisplayStringFromState","getContextValueFromFormValue","map","getContextValueFromState","getViewModel","context","errors","isForceAccess","page","viewModel","attributes","id","filtered","filter","rows","item","index","tag","classes","text","valueHtml","view","params","trim","keyHtml","path","href","getHref","push","visuallyHiddenText","key","html","actions","accept","allowsMultiple","summaryList","multiple","upload","getAllPossibleErrors","onSubmit","request","language","model","createTranslator","notificationEmail","Error","app","services","formSubmissionService","values","initiatedRetrievalKey","persistFiles","error","isBoom","output","statusCode","baseErrors","type","template","selectRequired","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/FileUploadField.ts"],"sourcesContent":["import {\n type FileUploadFieldComponent,\n type FormMetadata\n} from '@defra/forms-model'\nimport Boom from '@hapi/boom'\nimport joi, { type ArraySchema } from 'joi'\n\nimport {\n FormComponent,\n isUploadState\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { InvalidComponentStateError } from '~/src/server/plugins/engine/pageControllers/errors.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n FileStatus,\n UploadStatus,\n type ErrorMessageTemplateList,\n type FileState,\n type FileUpload,\n type FileUploadMetadata,\n type FormContext,\n type FormState,\n type FormStateValue,\n type FormSubmissionState,\n type SummaryList,\n type SummaryListAction,\n type SummaryListRow,\n type UploadState,\n type UploadStatusFileResponse,\n type UploadStatusResponse\n} from '~/src/server/plugins/engine/types.js'\nimport { render } from '~/src/server/plugins/nunjucks/index.js'\nimport { type FormRequestPayload } from '~/src/server/routes/types.js'\nimport { resolveLanguage } from '~/src/server/utils/utils.js'\n\nexport const uploadIdSchema = joi.string().uuid().required()\n\nexport const fileSchema = joi\n .object<FileUpload>({\n fileId: joi.string().uuid().required(),\n filename: joi.string().required(),\n contentLength: joi.number().required()\n })\n .required()\n\nexport const tempFileSchema = fileSchema.append({\n fileStatus: joi\n .string()\n .valid(FileStatus.complete, FileStatus.rejected, FileStatus.pending)\n .required(),\n errorMessage: joi.string().optional()\n})\n\nexport const formFileSchema = fileSchema.append({\n fileStatus: joi.string().valid(FileStatus.complete).required()\n})\n\nexport const metadataSchema = joi\n .object<FileUploadMetadata>()\n .keys({\n retrievalKey: joi.string().email().required()\n })\n .required()\n\nexport const tempStatusSchema = joi\n .object<UploadStatusFileResponse>({\n uploadStatus: joi\n .string()\n .valid(UploadStatus.ready, UploadStatus.pending)\n .required(),\n metadata: metadataSchema,\n form: joi\n .object()\n .required()\n .keys({\n file: joi.array().items(tempFileSchema).single().required()\n }),\n numberOfRejectedFiles: joi.number().optional()\n })\n .required()\n\nexport const formStatusSchema = joi\n .object<UploadStatusResponse>({\n uploadStatus: joi.string().valid(UploadStatus.ready).required(),\n metadata: metadataSchema,\n form: joi.object().required().keys({\n file: formFileSchema\n }),\n numberOfRejectedFiles: joi.number().required()\n })\n .required()\n\nexport const itemSchema = joi.object<FileState>({\n uploadId: uploadIdSchema\n})\n\nexport const tempItemSchema = itemSchema.append({\n status: tempStatusSchema\n})\n\nexport const formItemSchema = itemSchema.append({\n status: formStatusSchema\n})\n\nexport class FileUploadField extends FormComponent {\n declare options: FileUploadFieldComponent['options']\n declare schema: FileUploadFieldComponent['schema']\n declare formSchema: ArraySchema<FileState>\n declare stateSchema: ArraySchema<FileState>\n\n constructor(\n def: FileUploadFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, schema } = def\n\n let formSchema = joi\n .array<FileState>()\n .label(this.label)\n .single()\n .required()\n\n if (options.required === false) {\n formSchema = formSchema.optional()\n }\n\n if (typeof schema.length !== 'number') {\n if (typeof schema.max === 'number') {\n formSchema = formSchema.max(schema.max)\n }\n\n if (typeof schema.min === 'number') {\n formSchema = formSchema.min(schema.min)\n } else if (options.required !== false) {\n formSchema = formSchema.min(1)\n }\n } else {\n formSchema = formSchema.length(schema.length)\n }\n\n this.formSchema = formSchema.items(formItemSchema)\n this.stateSchema = formSchema\n .items(formItemSchema)\n .default(null)\n .allow(null)\n\n this.options = options\n this.schema = schema\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(\n files: FileState[] | undefined,\n translator: Translator\n ): string {\n if (!files?.length) {\n return ''\n }\n\n return translator.t('components.fileUploadField.filesCount', {\n count: files.length\n })\n }\n\n getDisplayStringFromState(\n state: FormSubmissionState,\n translator: Translator\n ) {\n const files = this.getFormValueFromState(state)\n\n return this.getDisplayStringFromFormValue(files, translator)\n }\n\n getContextValueFromFormValue(\n files: UploadState | undefined\n ): string[] | null {\n return files?.map(({ status }) => status.form.file.fileId) ?? null\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const files = this.getFormValueFromState(state)\n return this.getContextValueFromFormValue(files)\n }\n\n getViewModel(context: RenderContext) {\n const { errors, isForceAccess = false } = context\n const { t } = context.translator\n const { options, page, schema } = this\n\n const viewModel = super.getViewModel(context)\n const { attributes, id, value } = viewModel\n\n const files = this.getFormValue(value) ?? []\n const filtered = files.filter(\n (file) => file.status.form.file.fileStatus === FileStatus.complete\n )\n const count = filtered.length\n\n const rows: SummaryListRow[] = filtered.map((item, index) => {\n const { status } = item\n const { form } = status\n const { file } = form\n\n const tag = {\n classes: 'govuk-tag--green',\n text: t('components.fileUploadField.uploaded')\n }\n\n const valueHtml = render\n .view('components/fileuploadfield-value.html', {\n context: { params: { tag } }\n })\n .trim()\n\n const keyHtml = render\n .view('components/fileuploadfield-key.html', {\n context: {\n params: {\n name: file.filename,\n errorMessage: errors && file.errorMessage\n }\n }\n })\n .trim()\n\n const items: SummaryListAction[] = []\n\n // Remove summary list actions from previews\n if (!isForceAccess) {\n const path = `/${file.fileId}/confirm-delete`\n const href = page?.getHref(`${page.path}${path}`) ?? '#'\n\n items.push({\n href,\n text: 'Remove',\n classes: 'govuk-link--no-visited-state',\n attributes: { id: `${id}__${index}` },\n visuallyHiddenText: file.filename\n })\n }\n\n return {\n key: {\n html: keyHtml\n },\n value: {\n html: valueHtml\n },\n actions: {\n items\n }\n } satisfies SummaryListRow\n })\n\n // Set up the `accept` attribute\n if ('accept' in options && options.accept) {\n attributes.accept = options.accept\n }\n\n // Allow multiple file selection when schema permits more than 1 file\n const allowsMultiple = schema.max !== 1 && schema.length !== 1\n\n const summaryList: SummaryList = {\n classes: 'govuk-summary-list--long-key',\n rows\n }\n\n return {\n ...viewModel,\n\n // File input can't have a initial value\n value: '',\n\n // Override the component name we send to CDP\n name: 'file',\n\n // Enable multi-file selection in the file picker\n ...(allowsMultiple && { multiple: true }),\n\n upload: {\n count,\n summaryList\n }\n }\n }\n\n isValue(value?: FormStateValue | FormState): value is UploadState {\n return isUploadState(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return FileUploadField.getAllPossibleErrors()\n }\n\n async onSubmit(\n request: FormRequestPayload,\n metadata: FormMetadata,\n context: FormContext\n ) {\n const language = resolveLanguage(request)\n const { t } = this.model.createTranslator(language)\n\n const notificationEmail = metadata.notificationEmail\n\n if (!notificationEmail) {\n // this should not happen because notificationEmail is checked further up\n // the chain in SummaryPageController before submitForm is called.\n throw new Error('Unexpected missing notificationEmail in metadata')\n }\n\n if (!request.app.model?.services.formSubmissionService) {\n throw new Error('No form submission service available in app model')\n }\n\n const { formSubmissionService } = request.app.model.services\n const values = this.getFormValueFromState(context.state) ?? []\n\n const files = values.map((value) => ({\n fileId: value.status.form.file.fileId,\n initiatedRetrievalKey: value.status.metadata.retrievalKey\n }))\n\n if (!files.length) {\n return\n }\n\n try {\n await formSubmissionService.persistFiles(files, notificationEmail)\n } catch (error) {\n if (\n Boom.isBoom(error) &&\n (error.output.statusCode === 403 || // Forbidden - retrieval key invalid\n error.output.statusCode === 404 || // Not Found - file not found\n error.output.statusCode === 410) // Gone - file expired (took to long to submit, etc)\n ) {\n // Failed to persist files. We can't recover from this, the only real way we can recover the submissions is\n // by resetting the problematic components and letting the user re-try.\n // Scenarios: file missing from S3, invalid retrieval key (timing problem), etc.\n throw new InvalidComponentStateError(\n this,\n t('components.fileUploadField.uploadFailed')\n )\n }\n\n throw error\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: 'selectRequired', template: messageTemplate.selectRequired },\n {\n type: 'filesMimes',\n template: 'The selected file must be a {{#limit}}'\n },\n {\n type: 'filesSize',\n template: 'The selected file must be smaller than 100MB'\n },\n { type: 'filesEmpty', template: 'The selected file is empty' },\n { type: 'filesVirus', template: 'The selected file contains a virus' },\n {\n type: 'filesPartial',\n template: 'The selected file has not fully uploaded'\n },\n {\n type: 'filesError',\n template: 'The selected file could not be uploaded – try again'\n }\n ],\n advancedSettingsErrors: [\n {\n type: 'filesMin',\n template: 'You must upload {{#limit}} files or more'\n },\n {\n type: 'filesMax',\n template: 'You can only upload {{#limit}} files or less'\n },\n {\n type: 'filesExact',\n template: 'You must upload exactly {{#limit}} files'\n }\n ]\n }\n }\n}\n"],"mappings":"AAIA,OAAOA,IAAI,MAAM,YAAY;AAC7B,OAAOC,GAAG,MAA4B,KAAK;AAE3C,SACEC,aAAa,EACbC,aAAa;AAIf,SAASC,0BAA0B;AACnC,SAASC,eAAe;AACxB,SACEC,UAAU,EACVC,YAAY;AAgBd,SAASC,MAAM;AAEf,SAASC,eAAe;AAExB,OAAO,MAAMC,cAAc,GAAGT,GAAG,CAACU,MAAM,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;AAE5D,OAAO,MAAMC,UAAU,GAAGb,GAAG,CAC1Bc,MAAM,CAAa;EAClBC,MAAM,EAAEf,GAAG,CAACU,MAAM,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACtCI,QAAQ,EAAEhB,GAAG,CAACU,MAAM,CAAC,CAAC,CAACE,QAAQ,CAAC,CAAC;EACjCK,aAAa,EAA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,UAAU,KAAK,GAAG,CAAC,CAAC;MAAA,EACnC;QACA;QACA;QACA;QACA,MAAM,IAAI/H,0BAA0B,CAClC,IAAI,EACJsE,CAAC,CAAC,yCAAyC,CAC7C,CAAC;MACH;MAEA,MAAMsD,KAAK;IACb;EACF;;EAEA;AACF;AACA;EACE,OAAOd,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLkB,UAAU,EAAE,CACV;QAAEC,IAAI,EAAE,gBAAgB;QAAEC,QAAQ,EAAEjI,eAAe,CAACkI;MAAe,CAAC,EACpE;QACEF,IAAI,EAAE,YAAY;QAClBC,QAAQ,EAAE;MACZ,CAAC,EACD;QACED,IAAI,EAAE,WAAW;QACjBC,QAAQ,EAAE;MACZ,CAAC,EACD;QAAED,IAAI,EAAE,YAAY;QAAEC,QAAQ,EAAE;MAA6B,CAAC,EAC9D;QAAED,IAAI,EAAE,YAAY;QAAEC,QAAQ,EAAE;MAAqC,CAAC,EACtE;QACED,IAAI,EAAE,cAAc;QACpBC,QAAQ,EAAE;MACZ,CAAC,EACD;QACED,IAAI,EAAE,YAAY;QAClBC,QAAQ,EAAE;MACZ,CAAC,CACF;MACDE,sBAAsB,EAAE,CACtB;QACEH,IAAI,EAAE,UAAU;QAChBC,QAAQ,EAAE;MACZ,CAAC,EACD;QACED,IAAI,EAAE,UAAU;QAChBC,QAAQ,EAAE;MACZ,CAAC,EACD;QACED,IAAI,EAAE,YAAY;QAClBC,QAAQ,EAAE;MACZ,CAAC;IAEL,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type FormComponentsDef, type FormMetadata, type Item } from '@defra/forms-model';
|
|
2
|
+
import { type LanguageMessages } from 'joi';
|
|
2
3
|
import { ComponentBase } from '../../../../server/plugins/engine/components/ComponentBase.js';
|
|
4
|
+
import { type RenderContext } from '../../../../server/plugins/engine/components/types.js';
|
|
5
|
+
import { type Translator } from '../../../../server/plugins/engine/i18n/types.js';
|
|
3
6
|
import { type FormContext, type FormRequestPayload } from '../../../../server/plugins/engine/types/index.js';
|
|
4
7
|
import { type ErrorMessageTemplateList, type Feature, type FileState, type FormPayload, type FormState, type FormStateValue, type FormSubmissionError, type FormSubmissionState, type FormValue, type GeospatialState, type RepeatItemState, type RepeatListState, type UploadState } from '../../../../server/plugins/engine/types.js';
|
|
5
8
|
export declare class FormComponent extends ComponentBase {
|
|
@@ -17,10 +20,16 @@ export declare class FormComponent extends ComponentBase {
|
|
|
17
20
|
getFormValueFromState(state: FormSubmissionState): FormValue | FormPayload;
|
|
18
21
|
getFormValue(value?: FormStateValue | FormState): NonNullable<FormStateValue> | undefined;
|
|
19
22
|
getStateFromValidForm(payload: FormPayload): FormState;
|
|
20
|
-
getErrors(errors?: FormSubmissionError[]): FormSubmissionError[] | undefined;
|
|
21
|
-
getFirstError(errors?: FormSubmissionError[]): FormSubmissionError | undefined;
|
|
22
|
-
getViewErrors(errors?: FormSubmissionError[]): FormSubmissionError[] | undefined;
|
|
23
|
-
|
|
23
|
+
getErrors(_translator: Translator, errors?: FormSubmissionError[]): FormSubmissionError[] | undefined;
|
|
24
|
+
getFirstError(translator: Translator, errors?: FormSubmissionError[]): FormSubmissionError | undefined;
|
|
25
|
+
getViewErrors(translator: Translator, errors?: FormSubmissionError[]): FormSubmissionError[] | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Override in composite fields to return translated Joi message overrides for
|
|
28
|
+
* their sub-fields, applied at validation time so schema-level English messages
|
|
29
|
+
* are replaced with the correct language. Return null to skip message patching.
|
|
30
|
+
*/
|
|
31
|
+
getValidationMessagesOverride(_translator: Translator): LanguageMessages | null;
|
|
32
|
+
getViewModel({ payload, errors, translator, isForceAccess: _isForceAccess }: RenderContext): {
|
|
24
33
|
label: {
|
|
25
34
|
text: string;
|
|
26
35
|
};
|
|
@@ -32,8 +41,8 @@ export declare class FormComponent extends ComponentBase {
|
|
|
32
41
|
id?: string;
|
|
33
42
|
text: string;
|
|
34
43
|
};
|
|
35
|
-
prefix?: import("../../../../server/plugins/engine/types
|
|
36
|
-
suffix?: import("../../../../server/plugins/engine/types
|
|
44
|
+
prefix?: import("../../../../server/plugins/engine/components/types.js").ComponentText;
|
|
45
|
+
suffix?: import("../../../../server/plugins/engine/components/types.js").ComponentText;
|
|
37
46
|
classes?: string;
|
|
38
47
|
condition?: string;
|
|
39
48
|
errors?: FormSubmissionError[];
|
|
@@ -49,28 +58,28 @@ export declare class FormComponent extends ComponentBase {
|
|
|
49
58
|
accept?: string;
|
|
50
59
|
inputmode?: string;
|
|
51
60
|
};
|
|
52
|
-
content?: import("../../../../server/plugins/engine/types
|
|
61
|
+
content?: import("../../../../server/plugins/engine/components/types.js").Content | import("../../../../server/plugins/engine/components/types.js").Content[] | string;
|
|
53
62
|
maxlength?: number;
|
|
54
63
|
maxwords?: number;
|
|
55
64
|
rows?: number;
|
|
56
|
-
items?: import("../../../../server/plugins/engine/types
|
|
65
|
+
items?: import("../../../../server/plugins/engine/components/types.js").ListItem[] | import("../../../../server/plugins/engine/components/types.js").DateInputItem[];
|
|
57
66
|
fieldset?: {
|
|
58
67
|
attributes?: string | Record<string, string>;
|
|
59
|
-
legend?: import("../../../../server/plugins/engine/types
|
|
68
|
+
legend?: import("../../../../server/plugins/engine/components/types.js").Label;
|
|
60
69
|
};
|
|
61
70
|
formGroup?: {
|
|
62
71
|
classes?: string;
|
|
63
72
|
attributes?: string | Record<string, string>;
|
|
64
73
|
};
|
|
65
74
|
showFieldsetError?: boolean;
|
|
66
|
-
components?: import("../../../../server/plugins/engine/types
|
|
75
|
+
components?: import("../../../../server/plugins/engine/components/types.js").ComponentViewModel[];
|
|
67
76
|
upload?: {
|
|
68
77
|
count: number;
|
|
69
78
|
summaryList: import("../../../../server/plugins/engine/types.js").SummaryList;
|
|
70
79
|
};
|
|
71
80
|
};
|
|
72
|
-
getDisplayStringFromFormValue(value: FormValue | FormPayload): string;
|
|
73
|
-
getDisplayStringFromState(state: FormSubmissionState): string;
|
|
81
|
+
getDisplayStringFromFormValue(value: FormValue | FormPayload, _translator: Translator): string;
|
|
82
|
+
getDisplayStringFromState(state: FormSubmissionState, translator: Translator): string;
|
|
74
83
|
getContextValueFromFormValue(value: FormValue | FormPayload): Item['value'] | Item['value'][] | null;
|
|
75
84
|
getContextValueFromState(state: FormSubmissionState): Item['value'] | Item['value'][] | null;
|
|
76
85
|
isValue(value?: FormStateValue | FormState): value is NonNullable<FormStateValue>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ComponentBase } from "./ComponentBase.js";
|
|
2
|
-
import { optionalText } from "./constants.js";
|
|
3
2
|
export class FormComponent extends ComponentBase {
|
|
4
3
|
type;
|
|
5
4
|
hint;
|
|
@@ -82,7 +81,7 @@ export class FormComponent extends ComponentBase {
|
|
|
82
81
|
[name]: this.getFormValue(payload[name]) ?? null
|
|
83
82
|
};
|
|
84
83
|
}
|
|
85
|
-
getErrors(errors) {
|
|
84
|
+
getErrors(_translator, errors) {
|
|
86
85
|
const {
|
|
87
86
|
name
|
|
88
87
|
} = this;
|
|
@@ -94,14 +93,28 @@ export class FormComponent extends ComponentBase {
|
|
|
94
93
|
}
|
|
95
94
|
return list;
|
|
96
95
|
}
|
|
97
|
-
getFirstError(errors) {
|
|
98
|
-
return this.getErrors(errors)?.[0];
|
|
96
|
+
getFirstError(translator, errors) {
|
|
97
|
+
return this.getErrors(translator, errors)?.[0];
|
|
99
98
|
}
|
|
100
|
-
getViewErrors(errors) {
|
|
101
|
-
const firstError = this.getFirstError(errors);
|
|
99
|
+
getViewErrors(translator, errors) {
|
|
100
|
+
const firstError = this.getFirstError(translator, errors);
|
|
102
101
|
return firstError && [firstError];
|
|
103
102
|
}
|
|
104
|
-
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Override in composite fields to return translated Joi message overrides for
|
|
106
|
+
* their sub-fields, applied at validation time so schema-level English messages
|
|
107
|
+
* are replaced with the correct language. Return null to skip message patching.
|
|
108
|
+
*/
|
|
109
|
+
getValidationMessagesOverride(_translator) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
getViewModel({
|
|
113
|
+
payload,
|
|
114
|
+
errors,
|
|
115
|
+
translator,
|
|
116
|
+
isForceAccess: _isForceAccess = false
|
|
117
|
+
}) {
|
|
105
118
|
const {
|
|
106
119
|
hint,
|
|
107
120
|
name,
|
|
@@ -109,18 +122,24 @@ export class FormComponent extends ComponentBase {
|
|
|
109
122
|
title,
|
|
110
123
|
viewModel
|
|
111
124
|
} = this;
|
|
125
|
+
const {
|
|
126
|
+
t,
|
|
127
|
+
tComponent
|
|
128
|
+
} = translator;
|
|
112
129
|
const isRequired = !('required' in options) || options.required !== false;
|
|
113
130
|
const hideOptional = 'optionalText' in options && options.optionalText;
|
|
114
|
-
const
|
|
131
|
+
const resolvedTitle = tComponent(this, 'title') || title;
|
|
132
|
+
const optionalTag = !isRequired && !hideOptional ? ` ${t('common.optional')}` : '';
|
|
133
|
+
const label = `${resolvedTitle}${optionalTag}`;
|
|
115
134
|
if (hint) {
|
|
116
135
|
viewModel.hint = {
|
|
117
|
-
text: hint
|
|
136
|
+
text: tComponent(this, 'hint') || hint
|
|
118
137
|
};
|
|
119
138
|
}
|
|
120
139
|
|
|
121
140
|
// Filter component errors only
|
|
122
|
-
const componentErrors = this.getErrors(errors);
|
|
123
|
-
const componentError = this.getFirstError(componentErrors);
|
|
141
|
+
const componentErrors = this.getErrors(translator, errors);
|
|
142
|
+
const componentError = this.getFirstError(translator, componentErrors);
|
|
124
143
|
if (componentErrors) {
|
|
125
144
|
viewModel.errors = componentErrors;
|
|
126
145
|
}
|
|
@@ -139,14 +158,14 @@ export class FormComponent extends ComponentBase {
|
|
|
139
158
|
value: payload[name]
|
|
140
159
|
};
|
|
141
160
|
}
|
|
142
|
-
getDisplayStringFromFormValue(value) {
|
|
161
|
+
getDisplayStringFromFormValue(value, _translator) {
|
|
143
162
|
// Map selected values to text
|
|
144
163
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
145
164
|
return this.isValue(value) ? value.toString() : '';
|
|
146
165
|
}
|
|
147
|
-
getDisplayStringFromState(state) {
|
|
166
|
+
getDisplayStringFromState(state, translator) {
|
|
148
167
|
const value = this.getFormValueFromState(state);
|
|
149
|
-
return this.getDisplayStringFromFormValue(value);
|
|
168
|
+
return this.getDisplayStringFromFormValue(value, translator);
|
|
150
169
|
}
|
|
151
170
|
getContextValueFromFormValue(value) {
|
|
152
171
|
// Filter object field values
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormComponent.js","names":["ComponentBase","optionalText","FormComponent","type","hint","label","summaryLabel","isFormComponent","isAppendageStateSingleObject","constructor","def","props","getLabel","getSummaryLabel","errorDescription","shortDescription","title","keys","collection","name","fields","map","getFormDataFromState","state","getFormValue","getFormValueFromState","value","isValue","undefined","getStateFromValidForm","payload","getErrors","errors","list","filter","error","path","includes","length","getFirstError","getViewErrors","firstError","getViewModel","options","viewModel","isRequired","required","hideOptional","text","componentErrors","componentError","errorMessage","id","getDisplayStringFromFormValue","toString","getDisplayStringFromState","getContextValueFromFormValue","isState","values","Object","isFormValue","Array","isArray","getContextValueFromState","isFormState","getAllPossibleErrors","baseErrors","advancedSettingsErrors","onSubmit","_request","_metadata","_context","Promise","resolve","isRepeatState","every","isRepeatValue","itemId","isUploadState","isUploadValue","isGeospatialState","isGeospatialValue","uploadId"],"sources":["../../../../../src/server/plugins/engine/components/FormComponent.ts"],"sourcesContent":["import {\n type FormComponentsDef,\n type FormMetadata,\n type Item\n} from '@defra/forms-model'\n\nimport { ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport { optionalText } from '~/src/server/plugins/engine/components/constants.js'\nimport {\n type FormContext,\n type FormRequestPayload\n} from '~/src/server/plugins/engine/types/index.js'\nimport {\n type ErrorMessageTemplateList,\n type Feature,\n type FileState,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type FormValue,\n type GeospatialState,\n type RepeatItemState,\n type RepeatListState,\n type UploadState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class FormComponent extends ComponentBase {\n type: FormComponentsDef['type']\n hint: FormComponentsDef['hint']\n label: string\n summaryLabel: string\n\n isFormComponent = true\n isAppendageStateSingleObject = false\n\n constructor(\n def: FormComponentsDef,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { hint, type } = def\n\n this.type = type\n this.hint = hint\n\n this.label = this.getLabel(def)\n this.summaryLabel = this.getSummaryLabel(def)\n }\n\n getLabel(def: FormComponentsDef) {\n if ('errorDescription' in def && def.errorDescription) {\n return def.errorDescription\n }\n\n return this.getSummaryLabel(def)\n }\n\n getSummaryLabel(def: FormComponentsDef) {\n if ('shortDescription' in def && def.shortDescription) {\n return def.shortDescription\n }\n\n return def.title\n }\n\n get keys() {\n const { collection, name } = this\n\n if (collection) {\n const { fields } = collection\n return [name, ...fields.map(({ name }) => name)]\n }\n\n return [name]\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { collection, name } = this\n\n if (collection) {\n return collection.getFormDataFromState(state)\n }\n\n return {\n [name]: this.getFormValue(state[name])\n }\n }\n\n getFormValueFromState(state: FormSubmissionState): FormValue | FormPayload {\n const { collection, name } = this\n\n if (collection) {\n return collection.getFormValueFromState(state)\n }\n\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { collection, name } = this\n\n if (collection) {\n return collection.getStateFromValidForm(payload)\n }\n\n return {\n [name]: this.getFormValue(payload[name]) ?? null\n }\n }\n\n getErrors(errors?: FormSubmissionError[]): FormSubmissionError[] | undefined {\n const { name } = this\n\n // Filter component and child errors only\n const list = errors?.filter(\n (error) =>\n error.name === name ||\n error.path.includes(name) ||\n this.keys.includes(error.name)\n )\n\n if (!list?.length) {\n return\n }\n\n return list\n }\n\n getFirstError(\n errors?: FormSubmissionError[]\n ): FormSubmissionError | undefined {\n return this.getErrors(errors)?.[0]\n }\n\n getViewErrors(\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const firstError = this.getFirstError(errors)\n return firstError && [firstError]\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { hint, name, options = {}, title, viewModel } = this\n\n const isRequired = !('required' in options) || options.required !== false\n const hideOptional = 'optionalText' in options && options.optionalText\n const label = `${title}${!isRequired && !hideOptional ? optionalText : ''}`\n\n if (hint) {\n viewModel.hint = {\n text: hint\n }\n }\n\n // Filter component errors only\n const componentErrors = this.getErrors(errors)\n const componentError = this.getFirstError(componentErrors)\n\n if (componentErrors) {\n viewModel.errors = componentErrors\n }\n\n if (componentError) {\n viewModel.errorMessage = {\n text: componentError.text\n }\n }\n\n return {\n ...viewModel,\n label: {\n text: label\n },\n id: name,\n name,\n value: payload[name]\n }\n }\n\n getDisplayStringFromFormValue(value: FormValue | FormPayload): string {\n // Map selected values to text\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n return this.isValue(value) ? value.toString() : ''\n }\n\n getDisplayStringFromState(state: FormSubmissionState): string {\n const value = this.getFormValueFromState(state)\n return this.getDisplayStringFromFormValue(value)\n }\n\n getContextValueFromFormValue(\n value: FormValue | FormPayload\n ): Item['value'] | Item['value'][] | null {\n // Filter object field values\n if (this.isState(value)) {\n const values = Object.values(value).filter(isFormValue)\n return values.length ? values : null\n }\n\n // Filter array field values\n if (this.isValue(value) && Array.isArray(value)) {\n return value.filter(isFormValue)\n }\n\n return this.isValue(value) ? value : null\n }\n\n getContextValueFromState(\n state: FormSubmissionState\n ): Item['value'] | Item['value'][] | null {\n const value = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(value)\n }\n\n isValue(\n value?: FormStateValue | FormState\n ): value is NonNullable<FormStateValue> {\n return isFormValue(value)\n }\n\n isState(value?: FormStateValue | FormState): value is FormState {\n return isFormState(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return FormComponent.getAllPossibleErrors()\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 advancedSettingsErrors: []\n }\n }\n\n onSubmit(\n _request: FormRequestPayload,\n _metadata: FormMetadata,\n _context: FormContext\n ): Promise<void> {\n return Promise.resolve()\n }\n}\n\n/**\n * Check for form value\n */\nexport function isFormValue(\n value?: unknown\n): value is string | number | boolean {\n return (\n (typeof value === 'string' && value.length > 0) ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n )\n}\n\n/**\n * Check for form state with nested values\n */\nexport function isFormState(value?: unknown): value is FormState {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return false\n }\n\n // Skip empty objects\n return !!Object.values(value).length\n}\n\n/**\n * Check for repeat list state\n */\nexport function isRepeatState(value?: unknown): value is RepeatListState {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isRepeatValue)\n}\n\n/**\n * Check for repeat list value\n */\nexport function isRepeatValue(value?: unknown): value is RepeatItemState {\n return isFormState(value) && typeof value.itemId === 'string'\n}\n\n/**\n * Check for upload state\n */\nexport function isUploadState(value?: unknown): value is UploadState {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isUploadValue)\n}\n\n/**\n * Check for geospatial state\n */\nexport function isGeospatialState(value?: unknown): value is GeospatialState {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isGeospatialValue)\n}\n\n/**\n * Check for upload state value\n */\nexport function isUploadValue(value?: unknown): value is FileState {\n return isFormState(value) && typeof value.uploadId === 'string'\n}\n\n/**\n * Check for geospatial state value\n */\nexport function isGeospatialValue(value?: unknown): value is Feature {\n return (\n isFormState(value) &&\n typeof value.type === 'string' &&\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,CAAC;AACnC;;AAEA;AACA;AACA;AACA,OAAO,SAASA,aAAaA,CAAClD,KAAe,EAA4B;EACvE,OAAOsC,WAAW,CAACtC,KAAK,CAAC,IAAI,OAAOA,KAAK,CAACmD,MAAM,KAAK,QAAQ;AAC/D;;AAEA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACpD,KAAe,EAAwB;EACnE,IAAI,CAACmC,KAAK,CAACC,OAAO,CAACpC,KAAK,CAAC,EAAE;IACzB,OAAO,KAAK;EACd;;EAEA;EACA,IAAI,CAACA,KAAK,CAACY,MAAM,EAAE;IACjB,OAAO,IAAI;EACb;EAEA,OAAOZ,KAAK,CAACiD,KAAK,CAACI,aAAa,CAAC;AACnC;;AAEA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAACtD,KAAe,EAA4B;EAC3E,IAAI,CAACmC,KAAK,CAACC,OAAO,CAACpC,KAAK,CAAC,EAAE;IACzB,OAAO,KAAK;EACd;;EAEA;EACA,IAAI,CAACA,KAAK,CAACY,MAAM,EAAE;IACjB,OAAO,IAAI;EACb;EAEA,OAAOZ,KAAK,CAACiD,KAAK,CAACM,iBAAiB,CAAC;AACvC;;AAEA;AACA;AACA;AACA,OAAO,SAASF,aAAaA,CAACrD,KAAe,EAAsB;EACjE,OAAOsC,WAAW,CAACtC,KAAK,CAAC,IAAI,OAAOA,KAAK,CAACwD,QAAQ,KAAK,QAAQ;AACjE;;AAEA;AACA;AACA;AACA,OAAO,SAASD,iBAAiBA,CAACvD,KAAe,EAAoB;EACnE,OACEsC,WAAW,CAACtC,KAAK,CAAC,IAClB,OAAOA,KAAK,CAACvB,IAAI,KAAK,QAAQ,IAC9BuB,KAAK,CAACvB,IAAI,KAAK,SAAS;AAE5B","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"FormComponent.js","names":["ComponentBase","FormComponent","type","hint","label","summaryLabel","isFormComponent","isAppendageStateSingleObject","constructor","def","props","getLabel","getSummaryLabel","errorDescription","shortDescription","title","keys","collection","name","fields","map","getFormDataFromState","state","getFormValue","getFormValueFromState","value","isValue","undefined","getStateFromValidForm","payload","getErrors","_translator","errors","list","filter","error","path","includes","length","getFirstError","translator","getViewErrors","firstError","getValidationMessagesOverride","getViewModel","isForceAccess","_isForceAccess","options","viewModel","t","tComponent","isRequired","required","hideOptional","optionalText","resolvedTitle","optionalTag","text","componentErrors","componentError","errorMessage","id","getDisplayStringFromFormValue","toString","getDisplayStringFromState","getContextValueFromFormValue","isState","values","Object","isFormValue","Array","isArray","getContextValueFromState","isFormState","getAllPossibleErrors","baseErrors","advancedSettingsErrors","onSubmit","_request","_metadata","_context","Promise","resolve","isRepeatState","every","isRepeatValue","itemId","isUploadState","isUploadValue","isGeospatialState","isGeospatialValue","uploadId"],"sources":["../../../../../src/server/plugins/engine/components/FormComponent.ts"],"sourcesContent":["import {\n type ComponentDef,\n type FormComponentsDef,\n type FormMetadata,\n type Item\n} from '@defra/forms-model'\nimport { type LanguageMessages } from 'joi'\n\nimport { ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport {\n type FormContext,\n type FormRequestPayload\n} from '~/src/server/plugins/engine/types/index.js'\nimport {\n type ErrorMessageTemplateList,\n type Feature,\n type FileState,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type FormValue,\n type GeospatialState,\n type RepeatItemState,\n type RepeatListState,\n type UploadState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class FormComponent extends ComponentBase {\n type: FormComponentsDef['type']\n hint: FormComponentsDef['hint']\n label: string\n summaryLabel: string\n\n isFormComponent = true\n isAppendageStateSingleObject = false\n\n constructor(\n def: FormComponentsDef,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { hint, type } = def\n\n this.type = type\n this.hint = hint\n\n this.label = this.getLabel(def)\n this.summaryLabel = this.getSummaryLabel(def)\n }\n\n getLabel(def: FormComponentsDef) {\n if ('errorDescription' in def && def.errorDescription) {\n return def.errorDescription\n }\n\n return this.getSummaryLabel(def)\n }\n\n getSummaryLabel(def: FormComponentsDef) {\n if ('shortDescription' in def && def.shortDescription) {\n return def.shortDescription\n }\n\n return def.title\n }\n\n get keys() {\n const { collection, name } = this\n\n if (collection) {\n const { fields } = collection\n return [name, ...fields.map(({ name }) => name)]\n }\n\n return [name]\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { collection, name } = this\n\n if (collection) {\n return collection.getFormDataFromState(state)\n }\n\n return {\n [name]: this.getFormValue(state[name])\n }\n }\n\n getFormValueFromState(state: FormSubmissionState): FormValue | FormPayload {\n const { collection, name } = this\n\n if (collection) {\n return collection.getFormValueFromState(state)\n }\n\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { collection, name } = this\n\n if (collection) {\n return collection.getStateFromValidForm(payload)\n }\n\n return {\n [name]: this.getFormValue(payload[name]) ?? null\n }\n }\n\n getErrors(\n _translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const { name } = this\n\n // Filter component and child errors only\n const list = errors?.filter(\n (error) =>\n error.name === name ||\n error.path.includes(name) ||\n this.keys.includes(error.name)\n )\n\n if (!list?.length) {\n return\n }\n\n return list\n }\n\n getFirstError(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError | undefined {\n return this.getErrors(translator, errors)?.[0]\n }\n\n getViewErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const firstError = this.getFirstError(translator, errors)\n return firstError && [firstError]\n }\n\n /**\n * Override in composite fields to return translated Joi message overrides for\n * their sub-fields, applied at validation time so schema-level English messages\n * are replaced with the correct language. Return null to skip message patching.\n */\n getValidationMessagesOverride(\n _translator: Translator\n ): LanguageMessages | null {\n return null\n }\n\n getViewModel({\n payload,\n errors,\n translator,\n isForceAccess: _isForceAccess = false\n }: RenderContext) {\n const { hint, name, options = {}, title, viewModel } = this\n\n const { t, tComponent } = translator\n\n const isRequired = !('required' in options) || options.required !== false\n const hideOptional = 'optionalText' in options && options.optionalText\n\n const resolvedTitle =\n tComponent(this as unknown as ComponentDef, 'title') || title\n const optionalTag =\n !isRequired && !hideOptional ? ` ${t('common.optional')}` : ''\n const label = `${resolvedTitle}${optionalTag}`\n\n if (hint) {\n viewModel.hint = {\n text: tComponent(this as unknown as ComponentDef, 'hint') || hint\n }\n }\n\n // Filter component errors only\n const componentErrors = this.getErrors(translator, errors)\n const componentError = this.getFirstError(translator, componentErrors)\n\n if (componentErrors) {\n viewModel.errors = componentErrors\n }\n\n if (componentError) {\n viewModel.errorMessage = {\n text: componentError.text\n }\n }\n\n return {\n ...viewModel,\n label: {\n text: label\n },\n id: name,\n name,\n value: payload[name]\n }\n }\n\n getDisplayStringFromFormValue(\n value: FormValue | FormPayload,\n _translator: Translator\n ): string {\n // Map selected values to text\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n return this.isValue(value) ? value.toString() : ''\n }\n\n getDisplayStringFromState(\n state: FormSubmissionState,\n translator: Translator\n ): string {\n const value = this.getFormValueFromState(state)\n return this.getDisplayStringFromFormValue(value, translator)\n }\n\n getContextValueFromFormValue(\n value: FormValue | FormPayload\n ): Item['value'] | Item['value'][] | null {\n // Filter object field values\n if (this.isState(value)) {\n const values = Object.values(value).filter(isFormValue)\n return values.length ? values : null\n }\n\n // Filter array field values\n if (this.isValue(value) && Array.isArray(value)) {\n return value.filter(isFormValue)\n }\n\n return this.isValue(value) ? value : null\n }\n\n getContextValueFromState(\n state: FormSubmissionState\n ): Item['value'] | Item['value'][] | null {\n const value = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(value)\n }\n\n isValue(\n value?: FormStateValue | FormState\n ): value is NonNullable<FormStateValue> {\n return isFormValue(value)\n }\n\n isState(value?: FormStateValue | FormState): value is FormState {\n return isFormState(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return FormComponent.getAllPossibleErrors()\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 advancedSettingsErrors: []\n }\n }\n\n onSubmit(\n _request: FormRequestPayload,\n _metadata: FormMetadata,\n _context: FormContext\n ): Promise<void> {\n return Promise.resolve()\n }\n}\n\n/**\n * Check for form value\n */\nexport function isFormValue(\n value?: unknown\n): value is string | number | boolean {\n return (\n (typeof value === 'string' && value.length > 0) ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n )\n}\n\n/**\n * Check for form state with nested values\n */\nexport function isFormState(value?: unknown): value is FormState {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return false\n }\n\n // Skip empty objects\n return !!Object.values(value).length\n}\n\n/**\n * Check for repeat list state\n */\nexport function isRepeatState(value?: unknown): value is RepeatListState {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isRepeatValue)\n}\n\n/**\n * Check for repeat list value\n */\nexport function isRepeatValue(value?: unknown): value is RepeatItemState {\n return isFormState(value) && typeof value.itemId === 'string'\n}\n\n/**\n * Check for upload state\n */\nexport function isUploadState(value?: unknown): value is UploadState {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isUploadValue)\n}\n\n/**\n * Check for geospatial state\n */\nexport function isGeospatialState(value?: unknown): value is GeospatialState {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isGeospatialValue)\n}\n\n/**\n * Check for upload state value\n */\nexport function isUploadValue(value?: unknown): value is FileState {\n return isFormState(value) && typeof value.uploadId === 'string'\n}\n\n/**\n * Check for geospatial state value\n */\nexport function isGeospatialValue(value?: unknown): value is Feature {\n return (\n isFormState(value) &&\n typeof value.type === 'string' &&\n value.type === 'Feature'\n )\n}\n"],"mappings":"AAQA,SAASA,aAAa;AAuBtB,OAAO,MAAMC,aAAa,SAASD,aAAa,CAAC;EAC/CE,IAAI;EACJC,IAAI;EACJC,KAAK;EACLC,YAAY;EAEZC,eAAe,GAAG,IAAI;EACtBC,4BAA4B,GAAG,KAAK;EAEpCC,WAAWA,CACTC,GAAsB,EACtBC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEP,IAAI;MAAED;IAAK,CAAC,GAAGO,GAAG;IAE1B,IAAI,CAACP,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,IAAI,GAAGA,IAAI;IAEhB,IAAI,CAACC,KAAK,GAAG,IAAI,CAACO,QAAQ,CAACF,GAAG,CAAC;IAC/B,IAAI,CAACJ,YAAY,GAAG,IAAI,CAACO,eAAe,CAACH,GAAG,CAAC;EAC/C;EAEAE,QAAQA,CAACF,GAAsB,EAAE;IAC/B,IAAI,kBAAkB,IAAIA,GAAG,IAAIA,GAAG,CAACI,gBAAgB,EAAE;MACrD,OAAOJ,GAAG,CAACI,gBAAgB;IAC7B;IAEA,OAAO,IAAI,CAACD,eAAe,CAACH,GAAG,CAAC;EAClC;EAEAG,eAAeA,CAACH,GAAsB,EAAE;IACtC,IAAI,kBAAkB,IAAIA,GAAG,IAAIA,GAAG,CAACK,gBAAgB,EAAE;MACrD,OAAOL,GAAG,CAACK,gBAAgB;IAC7B;IAEA,OAAOL,GAAG,CAACM,KAAK;EAClB;EAEA,IAAIC,IAAIA,CAAA,EAAG;IACT,MAAM;MAAEC,UAAU;MAAEC;IAAK,CAAC,GAAG,IAAI;IAEjC,IAAID,UAAU,EAAE;MACd,MAAM;QAAEE;MAAO,CAAC,GAAGF,UAAU;MAC7B,OAAO,CAACC,IAAI,EAAE,GAAGC,MAAM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,MAAM,EAAE;IACjB,OAAO,IAAI;EACb;EAEA,OAAOb,KAAK,CAAC2D,KAAK,CAACM,iBAAiB,CAAC;AACvC;;AAEA;AACA;AACA;AACA,OAAO,SAASF,aAAaA,CAAC/D,KAAe,EAAsB;EACjE,OAAOgD,WAAW,CAAChD,KAAK,CAAC,IAAI,OAAOA,KAAK,CAACkE,QAAQ,KAAK,QAAQ;AACjE;;AAEA;AACA;AACA;AACA,OAAO,SAASD,iBAAiBA,CAACjE,KAAe,EAAoB;EACnE,OACEgD,WAAW,CAAChD,KAAK,CAAC,IAClB,OAAOA,KAAK,CAACvB,IAAI,KAAK,QAAQ,IAC9BuB,KAAK,CAACvB,IAAI,KAAK,SAAS;AAE5B","ignoreList":[]}
|
|
@@ -2,7 +2,9 @@ import { type GeospatialFieldComponent } from '@defra/forms-model';
|
|
|
2
2
|
import { type ArraySchema } from 'joi';
|
|
3
3
|
import { type ComponentBase } from '../../../../server/plugins/engine/components/ComponentBase.js';
|
|
4
4
|
import { FormComponent } from '../../../../server/plugins/engine/components/FormComponent.js';
|
|
5
|
-
import { type
|
|
5
|
+
import { type RenderContext } from '../../../../server/plugins/engine/components/types.js';
|
|
6
|
+
import { type Translator } from '../../../../server/plugins/engine/i18n/types.js';
|
|
7
|
+
import { type ErrorMessageTemplateList, type FormState, type FormStateValue, type FormSubmissionError, type FormSubmissionState, type GeospatialState } from '../../../../server/plugins/engine/types.js';
|
|
6
8
|
export declare class GeospatialField extends FormComponent {
|
|
7
9
|
options: GeospatialFieldComponent['options'];
|
|
8
10
|
formSchema: ArraySchema<GeospatialState>;
|
|
@@ -10,13 +12,14 @@ export declare class GeospatialField extends FormComponent {
|
|
|
10
12
|
constructor(def: GeospatialFieldComponent, props: ConstructorParameters<typeof ComponentBase>[1]);
|
|
11
13
|
getFormValueFromState(state: FormSubmissionState): import("../../../../server/plugins/engine/types.js").FeatureCollection | undefined;
|
|
12
14
|
getFormValue(value?: FormStateValue | FormState): import("../../../../server/plugins/engine/types.js").FeatureCollection | undefined;
|
|
13
|
-
getDisplayStringFromFormValue(features: GeospatialState | undefined): string;
|
|
14
|
-
getDisplayStringFromState(state: FormSubmissionState): string;
|
|
15
|
+
getDisplayStringFromFormValue(features: GeospatialState | undefined, translator: Translator): string;
|
|
16
|
+
getDisplayStringFromState(state: FormSubmissionState, translator: Translator): string;
|
|
15
17
|
getContextValueFromFormValue(features: GeospatialState | undefined): string[] | null;
|
|
16
18
|
getContextValueFromState(state: FormSubmissionState): string[] | null;
|
|
17
|
-
getViewModel(
|
|
19
|
+
getViewModel(context: RenderContext): {
|
|
18
20
|
country: import("@defra/forms-model").GeospatialFieldOptionsCountry | undefined;
|
|
19
21
|
geometryTypes: import("@defra/forms-model").GeospatialFieldGeometryTypesEnum[] | undefined;
|
|
22
|
+
mapLayers: string;
|
|
20
23
|
value: string;
|
|
21
24
|
label: {
|
|
22
25
|
text: string;
|
|
@@ -28,8 +31,8 @@ export declare class GeospatialField extends FormComponent {
|
|
|
28
31
|
id?: string;
|
|
29
32
|
text: string;
|
|
30
33
|
};
|
|
31
|
-
prefix?: import("
|
|
32
|
-
suffix?: import("
|
|
34
|
+
prefix?: import("../../../../server/plugins/engine/components/types.js").ComponentText;
|
|
35
|
+
suffix?: import("../../../../server/plugins/engine/components/types.js").ComponentText;
|
|
33
36
|
classes?: string;
|
|
34
37
|
condition?: string;
|
|
35
38
|
errors?: FormSubmissionError[];
|
|
@@ -45,28 +48,28 @@ export declare class GeospatialField extends FormComponent {
|
|
|
45
48
|
accept?: string;
|
|
46
49
|
inputmode?: string;
|
|
47
50
|
};
|
|
48
|
-
content?: import("
|
|
51
|
+
content?: import("../../../../server/plugins/engine/components/types.js").Content | import("../../../../server/plugins/engine/components/types.js").Content[] | string;
|
|
49
52
|
maxlength?: number;
|
|
50
53
|
maxwords?: number;
|
|
51
54
|
rows?: number;
|
|
52
|
-
items?: import("
|
|
55
|
+
items?: import("../../../../server/plugins/engine/components/types.js").ListItem[] | import("../../../../server/plugins/engine/components/types.js").DateInputItem[];
|
|
53
56
|
fieldset?: {
|
|
54
57
|
attributes?: string | Record<string, string>;
|
|
55
|
-
legend?: import("
|
|
58
|
+
legend?: import("../../../../server/plugins/engine/components/types.js").Label;
|
|
56
59
|
};
|
|
57
60
|
formGroup?: {
|
|
58
61
|
classes?: string;
|
|
59
62
|
attributes?: string | Record<string, string>;
|
|
60
63
|
};
|
|
61
64
|
showFieldsetError?: boolean;
|
|
62
|
-
components?: import("
|
|
65
|
+
components?: import("../../../../server/plugins/engine/components/types.js").ComponentViewModel[];
|
|
63
66
|
upload?: {
|
|
64
67
|
count: number;
|
|
65
68
|
summaryList: import("../../../../server/plugins/engine/types.js").SummaryList;
|
|
66
69
|
};
|
|
67
70
|
};
|
|
68
|
-
getErrors(errors?: FormSubmissionError[]): FormSubmissionError[] | undefined;
|
|
69
|
-
getViewErrors(errors?: FormSubmissionError[]): FormSubmissionError[] | undefined;
|
|
71
|
+
getErrors(translator: Translator, errors?: FormSubmissionError[]): FormSubmissionError[] | undefined;
|
|
72
|
+
getViewErrors(translator: Translator, errors?: FormSubmissionError[]): FormSubmissionError[] | undefined;
|
|
70
73
|
isValue(value?: FormStateValue | FormState): value is GeospatialState;
|
|
71
74
|
/**
|
|
72
75
|
* For error preview page that shows all possible errors on a component
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FormComponent, isGeospatialState } from "./FormComponent.js";
|
|
2
|
+
import { getMapLayers } from "./LocationFieldHelpers.js";
|
|
2
3
|
import { getGeospatialSchema } from "./helpers/geospatial.js";
|
|
3
4
|
import { messageTemplate } from "../pageControllers/validationOptions.js";
|
|
4
5
|
export class GeospatialField extends FormComponent {
|
|
@@ -28,16 +29,17 @@ export class GeospatialField extends FormComponent {
|
|
|
28
29
|
getFormValue(value) {
|
|
29
30
|
return this.isValue(value) ? value : undefined;
|
|
30
31
|
}
|
|
31
|
-
getDisplayStringFromFormValue(features) {
|
|
32
|
+
getDisplayStringFromFormValue(features, translator) {
|
|
32
33
|
if (!features?.length) {
|
|
33
34
|
return '';
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
return translator.t('components.geospatialField.added', {
|
|
37
|
+
count: features.length
|
|
38
|
+
});
|
|
37
39
|
}
|
|
38
|
-
getDisplayStringFromState(state) {
|
|
40
|
+
getDisplayStringFromState(state, translator) {
|
|
39
41
|
const features = this.getFormValueFromState(state);
|
|
40
|
-
return this.getDisplayStringFromFormValue(features);
|
|
42
|
+
return this.getDisplayStringFromFormValue(features, translator);
|
|
41
43
|
}
|
|
42
44
|
getContextValueFromFormValue(features) {
|
|
43
45
|
return features?.map(({
|
|
@@ -48,31 +50,37 @@ export class GeospatialField extends FormComponent {
|
|
|
48
50
|
const features = this.getFormValueFromState(state);
|
|
49
51
|
return this.getContextValueFromFormValue(features);
|
|
50
52
|
}
|
|
51
|
-
getViewModel(
|
|
52
|
-
const viewModel = super.getViewModel(
|
|
53
|
+
getViewModel(context) {
|
|
54
|
+
const viewModel = super.getViewModel(context);
|
|
53
55
|
const value = typeof viewModel.value === 'string' ? viewModel.value : JSON.stringify(viewModel.value, null, 2);
|
|
54
56
|
return {
|
|
55
57
|
...viewModel,
|
|
56
58
|
country: this.options.countries?.at(0),
|
|
57
59
|
geometryTypes: this.options.geometryTypes,
|
|
60
|
+
mapLayers: getMapLayers(this),
|
|
58
61
|
value
|
|
59
62
|
};
|
|
60
63
|
}
|
|
61
|
-
getErrors(errors) {
|
|
62
|
-
const fieldErrors = super.getErrors(errors);
|
|
64
|
+
getErrors(translator, errors) {
|
|
65
|
+
const fieldErrors = super.getErrors(translator, errors);
|
|
63
66
|
fieldErrors?.forEach(err => {
|
|
64
67
|
if (err.name === 'description') {
|
|
65
68
|
err.href = `#description_${err.path[1]}`;
|
|
66
|
-
err.text =
|
|
69
|
+
err.text = translator.t('components.geospatialField.validation.descriptionRequired', {
|
|
70
|
+
count: Number(err.path[1]) + 1
|
|
71
|
+
});
|
|
67
72
|
} else if (typeof err.name === 'number' && err.context?.country) {
|
|
68
73
|
err.href = `#description_${err.path[1]}`;
|
|
69
|
-
err.text =
|
|
74
|
+
err.text = translator.t('components.geospatialField.validation.wrongCountry', {
|
|
75
|
+
count: Number(err.path[1]) + 1,
|
|
76
|
+
country: err.context.country
|
|
77
|
+
});
|
|
70
78
|
}
|
|
71
79
|
});
|
|
72
80
|
return fieldErrors;
|
|
73
81
|
}
|
|
74
|
-
getViewErrors(errors) {
|
|
75
|
-
return this.getErrors(errors);
|
|
82
|
+
getViewErrors(translator, errors) {
|
|
83
|
+
return this.getErrors(translator, errors);
|
|
76
84
|
}
|
|
77
85
|
isValue(value) {
|
|
78
86
|
return isGeospatialState(value);
|