Skip to content

Commit

Permalink
Revert "Merge pull request #187 from ukhsa-collaboration/feat/conditi…
Browse files Browse the repository at this point in the history
…onally-revealed-components"

This reverts commit 63d30e2, reversing
changes made to d7488cc.
  • Loading branch information
kathryn-dale committed Jun 25, 2024
1 parent 7af2cde commit 86f182e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 265 deletions.
8 changes: 0 additions & 8 deletions runner/src/client/sass/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,3 @@
// .govuk-phase-banner__content__tag {
// text-transform: capitalize;
// }

.govuk-radios__conditional--hidden {
display: none;
}

.govuk-checkboxes__conditional--hidden {
display: none;
}
42 changes: 7 additions & 35 deletions runner/src/server/forms/ReportAnOutbreak.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": [],
Expand Down
104 changes: 5 additions & 99 deletions runner/src/server/plugins/engine/components/SelectionControlField.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -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;
}
}
3 changes: 0 additions & 3 deletions runner/src/server/plugins/engine/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
117 changes: 0 additions & 117 deletions runner/src/server/test-forms/conditionally-revealed-components.json

This file was deleted.

6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16141,7 +16141,7 @@ __metadata:
optional: true
bin:
nunjucks-precompile: bin/precompile
checksum: 8b902a9deb9ff0f5c9ebbd2c7f96dfe5800bf42bdfc91d8f829fc0440ec1f87901593e20479f5ba1bddcc9f2472b16a5e932be5863dcdec0899a27c01a03df32
checksum: 9d0125acf917166675af2d9b5d525b6d3edaba68ec6f8c92edee8ad05140cfa8aef12feb46f4c3da52ed2836cadfb9d26fbf1fa9d9be6bef4660d03ce1e89dbe
languageName: node
linkType: hard

Expand Down

0 comments on commit 86f182e

Please sign in to comment.