Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike/repeat sections #1263

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions model/src/data-model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface Section {
name: string;
title: string;
hideTitle: boolean;
repeating: boolean;
}

export interface Item {
Expand Down
1 change: 1 addition & 0 deletions model/src/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const sectionsSchema = joi.object().keys({
name: joi.string().required(),
title: joi.string().required(),
hideTitle: joi.boolean().default(false),
repeating: joi.boolean().default(false).optional(),
});

const conditionFieldSchema = joi.object().keys({
Expand Down
255 changes: 255 additions & 0 deletions runner/src/server/forms/repeat-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
{
"startPage": "/start",
"pages": [
{
"title": "Start",
"path": "/start",
"components": [],
"next": [
{
"path": "/uk-passport"
}
],
"controller": "./pages/start.js"
},
{
"path": "/uk-passport",
"components": [
{
"type": "YesNoField",
"name": "ukPassport",
"title": "Do you have a UK passport?",
"options": {
"required": true
},
"schema": {}
}
],
"section": "checkBeforeYouStart",
"next": [
{
"path": "/passport"
},
{
"path": "/no-uk-passport",
"condition": "doesntHaveUKPassport"
}
],
"title": "Do you have a UK passport?"
},
{
"path": "/no-uk-passport",
"title": "You're not eligible for this service",
"components": [
{
"type": "Para",
"content": "If you still think you're eligible please contact the Foreign and Commonwealth Office.",
"options": {
"required": true
},
"schema": {}
}
],
"next": []
},
{
"path": "/passport",
"title": "Applicant",
"section": "applicantDetails",
"components": [
{
"type": "Para",
"content": "Provide the details as they appear on your passport.",
"options": {
"required": true
},
"schema": {}
},
{
"type": "TextField",
"name": "firstName",
"title": "First name",
"options": {
"required": true
},
"schema": {}
},
{
"options": {
"required": false,
"optionalText": false
},
"type": "TextField",
"name": "middleName",
"title": "Middle name",
"hint": "If you have a middle name on your passport you must include it here",
"schema": {}
},
{
"type": "TextField",
"name": "lastName",
"title": "Surname",
"options": {
"required": true
},
"schema": {}
},
{
"type": "RadiosField",
"name": "country",
"title": "Country",
"options": {
"required": true
},
"list": "countries",
"schema": {}
}
],
"next": [
{
"path": "/address"
}
]
},
{
"path": "/address",
"section": "applicantDetails",
"components": [
{
"type": "UkAddressField",
"name": "address",
"title": "Address",
"options": {
"required": true
},
"schema": {}
}
],
"next": [
{
"path": "/contact-details"
}
],
"title": "Address"
},
{
"path": "/contact-details",
"section": "applicantDetails",
"components": [
{
"type": "TelephoneNumberField",
"name": "phoneNumber",
"title": "Phone number",
"hint": "If you haven't got a UK phone number, include country code",
"options": {
"required": true
},
"schema": {}
},
{
"type": "EmailAddressField",
"name": "emailAddress",
"title": "Your email address",
"options": {
"required": true
},
"schema": {}
}
],
"next": [
{
"path": "/summary"
}
],
"title": "Applicant contact details"
},
{
"path": "/summary",
"controller": "./pages/summary.js",
"title": "Summary",
"components": [],
"next": []
}
],
"lists": [
{
"name": "countries",
"title": "countries",
"type": "string",
"items": [
{
"text": "United Kingdom",
"value": "United Kingdom"
},
{
"text": "France",
"value": "France"
}
]
},
{
"name": "numberOfApplicants",
"title": "Number of people",
"type": "number",
"items": [
{
"text": "1",
"value": 1,
"description": "",
"condition": ""
},
{
"text": "2",
"value": 2,
"description": "",
"condition": ""
},
{
"text": "3",
"value": 3,
"description": "",
"condition": ""
},
{
"text": "4",
"value": 4,
"description": "",
"condition": ""
}
]
}
],
"sections": [
{
"name": "checkBeforeYouStart",
"title": "Check before you start"
},
{
"name": "applicantDetails",
"title": "Applicant details",
"repeating": true
}
],
"phaseBanner": {},
"fees": [],
"payApiKey": "",
"outputs": [
{
"name": "LwQeVI",
"title": "Test webhook",
"type": "webhook",
"outputConfiguration": {
"url": "https://61bca17e-fe74-40e0-9c15-a901ad120eca.mock.pstmn.io"
}
}
],
"declaration": "<p class=\"govuk-body\">All the answers you have provided are true to the best of your knowledge.</p>",
"version": 2,
"conditions": [
{
"name": "hasUKPassport",
"displayName": "hasUKPassport",
"value": "checkBeforeYouStart.ukPassport==true"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export class SelectionControlField extends ListFormComponent {
getViewModel(formData: FormData, errors: FormSubmissionErrors) {
const { name, items } = this;
const options: any = this.options;
const viewModel = super.getViewModel(formData, errors);
const viewModel: ViewModel = super.getViewModel(formData, errors);

viewModel.fieldset = {
legend: viewModel.label,
};

viewModel.items = items.map((item) => {
viewModel.items = items.map((item: any) => {
const itemModel: ListItem = {
text: item.text,
value: item.value,
Expand All @@ -35,9 +35,6 @@ export class SelectionControlField extends ListFormComponent {
}

return itemModel;

// FIXME:- add this back when GDS fix accessibility issues involving conditional reveal fields
//return super.addConditionalComponents(item, itemModel, formData, errors);
});
return viewModel;
}
Expand Down
56 changes: 28 additions & 28 deletions runner/src/server/plugins/engine/models/FormModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { PageController } from "../pageControllers/PageController";
import { ExecutableCondition } from "server/plugins/engine/models/types";
import { DEFAULT_FEE_OPTIONS } from "server/plugins/engine/models/FormModel.feeOptions";
import { ComponentCollection } from "server/plugins/engine/components";
import { Sections, SuperGraph } from "./Section";

class EvaluationContext {
constructor(conditions, value) {
Expand Down Expand Up @@ -56,7 +57,8 @@ export class FormModel {

feeOptions: FormDefinition["feeOptions"];
specialPages: FormDefinition["specialPages"];

_PAGES: Map<string, PageControllerBase> = new Map();
_SECTIONS: Sections;
constructor(def, options) {
const result = Schema.validate(def, { abortEarly: false });

Expand Down Expand Up @@ -115,9 +117,13 @@ export class FormModel {
this.fieldsForPrePopulation = {};

// @ts-ignore

this.pages = def.pages.map((pageDef) => this.makePage(pageDef));
this.startPage = this.pages.find((page) => page.path === def.startPage);
this._SECTIONS = new Sections(this);
// this._SECTIONS.sections.forEach((section) => section.graph.logGraph());
this.specialPages = def.specialPages;

this.feeOptions = { ...DEFAULT_FEE_OPTIONS, ...def.feeOptions };
}

Expand All @@ -142,33 +148,27 @@ export class FormModel {
(page) => page.section === section
);

if (sectionPages.length > 0) {
if (section) {
const isRepeatable = sectionPages.find(
(page) => page.pageDef.repeatField
);

let sectionSchema:
| joi.ObjectSchema<any>
| joi.ArraySchema = joi.object().required();

sectionPages.forEach((sectionPage) => {
sectionSchema = sectionSchema.concat(sectionPage.stateSchema);
});

if (isRepeatable) {
sectionSchema = joi.array().items(sectionSchema);
}

schema = schema.append({
// @ts-ignore
[section.name]: sectionSchema,
});
} else {
sectionPages.forEach((sectionPage) => {
schema = schema.concat(sectionPage.stateSchema);
});
}
if (!sectionPages.length) {
return schema;
}

if (!section) {
sectionPages.forEach((sectionPage) => {
schema = schema.concat(sectionPage.stateSchema);
});
return schema;
}

if (section.repeating) {
const sectionSchema = joi.array().items(joi.object().required());
sectionPages.forEach((sectionPage) => {
sectionSchema.items(sectionPage.stateSchema);
});

schema = schema.append({
// @ts-ignore
[section.name]: sectionSchema,
});
}
});

Expand Down
Loading
Loading