From 86f182eef901a6b8b9a9e6fc1471a00a54a1300e Mon Sep 17 00:00:00 2001 From: Kathryn Dale Date: Tue, 25 Jun 2024 09:09:42 +0100 Subject: [PATCH] Revert "Merge pull request #187 from ukhsa-collaboration/feat/conditionally-revealed-components" This reverts commit 63d30e24db83d7c71927f8e7a99bb65bb1078849, reversing changes made to d7488cc956c6be63cb47fb7ec2631c242541b0f7. --- runner/src/client/sass/application.scss | 8 -- runner/src/server/forms/ReportAnOutbreak.json | 42 ++----- .../components/SelectionControlField.ts | 104 +--------------- .../server/plugins/engine/components/types.ts | 3 - .../conditionally-revealed-components.json | 117 ------------------ yarn.lock | 6 +- 6 files changed, 15 insertions(+), 265 deletions(-) delete mode 100644 runner/src/server/test-forms/conditionally-revealed-components.json diff --git a/runner/src/client/sass/application.scss b/runner/src/client/sass/application.scss index 9aa16ee7c1..d141ea8620 100644 --- a/runner/src/client/sass/application.scss +++ b/runner/src/client/sass/application.scss @@ -80,11 +80,3 @@ // .govuk-phase-banner__content__tag { // text-transform: capitalize; // } - -.govuk-radios__conditional--hidden { - display: none; -} - -.govuk-checkboxes__conditional--hidden { - display: none; -} diff --git a/runner/src/server/forms/ReportAnOutbreak.json b/runner/src/server/forms/ReportAnOutbreak.json index 64d677a9a5..eb736e3cfa 100644 --- a/runner/src/server/forms/ReportAnOutbreak.json +++ b/runner/src/server/forms/ReportAnOutbreak.json @@ -44,23 +44,14 @@ "hint": "Please provide the postcode of the specific setting affected (i.e. not the overarching management company if applicable). If there is no one specific setting affected e.g. Domiciliary or Home Care, then please provide the postcode of the care provider company" }, { - "name": "S0Q2a", - "type": "RadiosField", - "title": "Is your setting CQC registered?", - "list": "YesNoDk", - "nameHasError": false, - "schema": {}, + "name": "S0Q2", "options": { - "conditionallyRevealedComponents": { - "yes": { - "type": "TextField", - "name": "SOQ2", - "title": "Please enter your CQC Location ID", - "options": {}, - "schema": {} - } - } - } + "required": false + }, + "type": "TextField", + "title": "Please enter your CQC Location ID", + "nameHasError": false, + "schema": {} }, { "name": "VMOkqi", @@ -2179,25 +2170,6 @@ "value": "5 or more" } ] - }, - { - "title": "s0q2 - cqc registered", - "name": "YesNoDk", - "type": "string", - "items": [ - { - "text": "Yes", - "value": "yes" - }, - { - "text": "No", - "value": "no" - }, - { - "text": "Don't know", - "value": "Don't know" - } - ] } ], "sections": [], diff --git a/runner/src/server/plugins/engine/components/SelectionControlField.ts b/runner/src/server/plugins/engine/components/SelectionControlField.ts index dcd931afa5..1b0346e1f6 100644 --- a/runner/src/server/plugins/engine/components/SelectionControlField.ts +++ b/runner/src/server/plugins/engine/components/SelectionControlField.ts @@ -1,43 +1,11 @@ -import joi from "joi"; -import nunjucks from "nunjucks"; import { ListFormComponent } from "server/plugins/engine/components/ListFormComponent"; import { FormData, FormSubmissionErrors } from "server/plugins/engine/types"; -import { ListItem, ViewModel } from "server/plugins/engine/components/types"; -import { ComponentCollection } from "./ComponentCollection"; +import { ListItem } from "server/plugins/engine/components/types"; /** * "Selection controls" are checkboxes and radios (and switches), as per Material UI nomenclature. */ - -const getSchemaKeys = Symbol("getSchemaKeys"); export class SelectionControlField extends ListFormComponent { - conditionallyRevealedComponents?: any; - hasConditionallyRevealedComponents: boolean = false; - - constructor(def, model) { - super(def, model); - const { options } = def; - - const { items } = this; - - if (options.conditionallyRevealedComponents) { - this.conditionallyRevealedComponents = - options.conditionallyRevealedComponents; - - items.map((item: any) => { - const conditionallyRevealedComponent = this - .conditionallyRevealedComponents![item.value]; - if (conditionallyRevealedComponent) { - item.hasConditionallyRevealedComponents = true; - item.conditionallyRevealedComponents = new ComponentCollection( - [conditionallyRevealedComponent], - item.model - ); - } - }); - } - } - getViewModel(formData: FormData, errors: FormSubmissionErrors) { const { name, items } = this; const options: any = this.options; @@ -48,7 +16,7 @@ export class SelectionControlField extends ListFormComponent { legend: viewModel.label, }; - viewModel.items = items.map((item: any) => { + viewModel.items = items.map((item) => { const itemModel: ListItem = { text: item.text, value: item.value, @@ -67,73 +35,11 @@ export class SelectionControlField extends ListFormComponent { }; } - if (options.conditionallyRevealedComponents) { - if (options.conditionallyRevealedComponents[item.value]) { - // The gov.uk design system Nunjucks examples for conditional reveal reference variables from macros. There does not appear to - // to be a way to do this in JavaScript. As such, render the conditional components with Nunjucks before the main view is rendered. - // The conditional html tag used by the gov.uk design system macro will reference HTML rarther than one or more additional - // gov.uk design system macros. - - itemModel.conditional = { - html: nunjucks.render( - "../views/partials/conditional-components.html", - { - components: item.conditionallyRevealedComponents.getViewModel( - formData, - errors - ), - } - ), - }; - } - } - return itemModel; - }); - return viewModel; - } - - getStateSchemaKeys() { - return this[getSchemaKeys]("state"); - } - - getFormSchemaKeys() { - return this[getSchemaKeys]("form"); - } - - [getSchemaKeys](schemaType) { - const schemaName = `${schemaType}Schema`; - const schemaKeysFunctionName = `get${schemaType - .substring(0, 1) - .toUpperCase()}${schemaType.substring(1)}SchemaKeys`; - const filteredItems = this.items.filter( - (item: any) => item.hasConditionallyRevealedComponents - ); - const conditionalName = this.name; - const schemaKeys = { [conditionalName]: this[schemaName] }; - // const schema = this[schemaName]; - // All conditional component values are submitted regardless of their visibilty. - // As such create Joi validation rules such that: - // a) When a conditional component is visible it is required. - // b) When a conditional component is not visible it is optional. - filteredItems?.forEach((item: any) => { - const conditionalSchemaKeys = item.conditionallyRevealedComponents[ - schemaKeysFunctionName - ](); - // Iterate through the set of components handled by conditional reveal adding Joi validation rules - // based on whether or not the component controlling the conditional reveal is selected. - Object.keys(conditionalSchemaKeys).forEach((key) => { - Object.assign(schemaKeys, { - [key]: joi.alternatives().conditional(joi.ref(conditionalName), { - is: key, - then: conditionalSchemaKeys[key].optional(), - otherwise: joi.optional(), - //TODO: Checkbox joi validation - }), - }); - }); + // FIXME:- add this back when GDS fix accessibility issues involving conditional reveal fields + //return super.addConditionalComponents(item, itemModel, formData, errors); }); - return schemaKeys; + return viewModel; } } diff --git a/runner/src/server/plugins/engine/components/types.ts b/runner/src/server/plugins/engine/components/types.ts index 504d691b0b..5597910355 100644 --- a/runner/src/server/plugins/engine/components/types.ts +++ b/runner/src/server/plugins/engine/components/types.ts @@ -23,9 +23,6 @@ export type ListItem = { selected?: boolean; label?: ListItemLabel; condition?: string; - conditional?: { - html: string; - }; }; // TODO: Break this down for each component (Same as model/Component). diff --git a/runner/src/server/test-forms/conditionally-revealed-components.json b/runner/src/server/test-forms/conditionally-revealed-components.json deleted file mode 100644 index daf5413b1c..0000000000 --- a/runner/src/server/test-forms/conditionally-revealed-components.json +++ /dev/null @@ -1,117 +0,0 @@ -{ - "startPage": "/start", - "pages": [ - { - "path": "/start", - "title": "Start", - "components": [ - { - "type": "RadiosField", - "name": "radiosField", - "title": "How would you prefer to be contacted?", - "list": "contactTypes", - "options": { - "conditionallyRevealedComponents": { - "email": { - "type": "EmailAddressField", - "name": "email", - "title": "Your email address", - "options": {}, - "schema": {} - }, - "phoneNumber": { - "type": "TelephoneNumberField", - "name": "phoneNumber", - "title": "Your phone number", - "options": {}, - "schema": {} - }, - "text": { - "type": "TextField", - "name": "text", - "title": "Some text", - "options": {}, - "schema": {} - }, - "number": { - "type": "NumberField", - "name": "number", - "title": "A number", - "options": {}, - "schema": {} - }, - "date": { - "type": "DateField", - "name": "date", - "title": "Date of birth", - "options": {}, - "schema": {} - } - } - } - } - ], - "next": [ - { - "path": "/page-two" - } - ] - }, - { - "path": "/page-two", - "title": "Data submitted", - "components": [ - { - "name": "koE_ae", - "options": { - "required": false - }, - "type": "Para", - "title": "Submitted data", - "schema": {} - } - ] - } - ], - "lists": [ - { - "name": "contactTypes", - "title": "Contact Types", - "type": "string", - "items": [ - { - "text": "Email", - "value": "email" - }, - { - "text": "Phone", - "value": "phoneNumber" - }, - { - "text": "Text", - "value": "text" - }, - { - "text": "Number", - "value": "number" - }, - { - "text": "Date", - "value": "date" - }, - { - "text": "Don't contact me", - "value": "doNotContact" - } - ] - } - ], - "sections": [], - "phaseBanner": {}, - "fees": [], - "payApiKey": "", - "outputs": [], - "declaration": "", - "version": 2, - "conditions": [] -} diff --git a/yarn.lock b/yarn.lock index 5ac4ebdae7..865e052a91 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16128,8 +16128,8 @@ __metadata: linkType: hard "nunjucks@npm:^3.2.3": - version: 3.2.4 - resolution: "nunjucks@npm:3.2.4" + version: 3.2.3 + resolution: "nunjucks@npm:3.2.3" dependencies: a-sync-waterfall: ^1.0.0 asap: ^2.0.3 @@ -16141,7 +16141,7 @@ __metadata: optional: true bin: nunjucks-precompile: bin/precompile - checksum: 8b902a9deb9ff0f5c9ebbd2c7f96dfe5800bf42bdfc91d8f829fc0440ec1f87901593e20479f5ba1bddcc9f2472b16a5e932be5863dcdec0899a27c01a03df32 + checksum: 9d0125acf917166675af2d9b5d525b6d3edaba68ec6f8c92edee8ad05140cfa8aef12feb46f4c3da52ed2836cadfb9d26fbf1fa9d9be6bef4660d03ce1e89dbe languageName: node linkType: hard