@defra/forms-model 3.0.693 → 3.0.695
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/dist/module/__stubs__/examples.js +28 -0
- package/dist/module/__stubs__/examples.js.map +1 -1
- package/dist/module/form/form-editor/translations/translations-config.js +7 -0
- package/dist/module/form/form-editor/translations/translations-config.js.map +1 -1
- package/dist/module/form/form-editor/translations/translations.js +37 -36
- package/dist/module/form/form-editor/translations/translations.js.map +1 -1
- package/dist/module/form/form-manager/errors.js +32 -0
- package/dist/module/form/form-manager/errors.js.map +1 -1
- package/dist/types/__stubs__/examples.d.ts +1 -0
- package/dist/types/__stubs__/examples.d.ts.map +1 -1
- package/dist/types/form/form-editor/translations/translations-config.d.ts +1 -0
- package/dist/types/form/form-editor/translations/translations-config.d.ts.map +1 -1
- package/dist/types/form/form-editor/translations/translations.d.ts.map +1 -1
- package/dist/types/form/form-manager/errors.d.ts +6 -0
- package/dist/types/form/form-manager/errors.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__stubs__/examples.js +35 -0
- package/src/form/form-editor/translations/translations-config.js +8 -0
- package/src/form/form-editor/translations/translations.js +90 -52
- package/src/form/form-manager/errors.ts +56 -0
|
@@ -106,6 +106,34 @@ export const formDefinitionWithLocationAndDeclaration = buildDefinition({
|
|
|
106
106
|
id: 'p2'
|
|
107
107
|
})]
|
|
108
108
|
});
|
|
109
|
+
export const formDefinitionWithFormLevelDeclaration = buildDefinition({
|
|
110
|
+
pages: [buildQuestionPage({
|
|
111
|
+
id: 'p1',
|
|
112
|
+
section: 'section',
|
|
113
|
+
components: [buildTextFieldComponent({
|
|
114
|
+
id: 'q1',
|
|
115
|
+
name: 'textField',
|
|
116
|
+
title: 'This is the first textfield question',
|
|
117
|
+
hint: 'Hint text 1',
|
|
118
|
+
shortDescription: 'Short desc 1'
|
|
119
|
+
}), buildTextFieldComponent({
|
|
120
|
+
id: 'q2',
|
|
121
|
+
name: 'textField',
|
|
122
|
+
title: 'This is the second textfield question',
|
|
123
|
+
hint: 'Hint text 2',
|
|
124
|
+
shortDescription: 'Short desc 2'
|
|
125
|
+
})],
|
|
126
|
+
next: [{
|
|
127
|
+
path: '/summary'
|
|
128
|
+
}]
|
|
129
|
+
}), buildSummaryPage({
|
|
130
|
+
id: 'p2',
|
|
131
|
+
components: [buildMarkdownComponent({
|
|
132
|
+
id: 'q10',
|
|
133
|
+
content: 'This is a final declaration for the summary page'
|
|
134
|
+
})]
|
|
135
|
+
})]
|
|
136
|
+
});
|
|
109
137
|
export const formDefinitionWithRepeater = buildDefinition({
|
|
110
138
|
pages: [buildRepeaterPage({
|
|
111
139
|
id: 'p1',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"examples.js","names":["buildDeclarationFieldComponent","buildLatLongFieldComponent","buildMarkdownComponent","buildRadiosComponent","buildTextFieldComponent","buildDefinition","buildQuestionPage","buildRepeaterPage","buildSummaryPage","formDefinitionWithSinglePage","pages","id","section","components","name","title","hint","next","path","formDefinitionWithoutSummary","formDefinitionWithTwoQuestions","formDefinitionWithTwoQuestionsAndGuidance","content","formDefinitionWithLocationAndDeclaration","options","instructionText","shortDescription","formDefinitionWithRepeater","formDefinitionWithNoQuestions","formDefinitionWithRadioQuestion","list","lists","type","items","text","value"],"sources":["../../../src/__stubs__/examples.js"],"sourcesContent":["import {\n buildDeclarationFieldComponent,\n buildLatLongFieldComponent,\n buildMarkdownComponent,\n buildRadiosComponent,\n buildTextFieldComponent\n} from '~/src/__stubs__/components.js'\nimport { buildDefinition } from '~/src/__stubs__/form-definition.js'\nimport {\n buildQuestionPage,\n buildRepeaterPage,\n buildSummaryPage\n} from '~/src/__stubs__/pages.js'\n\nexport const formDefinitionWithSinglePage = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildTextFieldComponent({\n id: 'c1',\n name: 'textField',\n title: 'This is your first field',\n hint: 'Help text'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'c2'\n })\n ]\n})\n\nexport const formDefinitionWithoutSummary = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildTextFieldComponent({\n id: 'c1',\n name: 'textField',\n title: 'This is your first field',\n hint: 'Help text'\n })\n ],\n next: [{ path: '/summary' }]\n })\n ]\n})\n\nexport const formDefinitionWithTwoQuestions = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildTextFieldComponent({\n id: 'q1',\n name: 'textField',\n title: 'This is your first question',\n hint: 'Help text'\n }),\n buildTextFieldComponent({\n id: 'q2',\n name: 'textField',\n title: 'This is your second question',\n hint: 'Help text'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ]\n})\n\nexport const formDefinitionWithTwoQuestionsAndGuidance = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildMarkdownComponent({ content: 'My markdown text' }),\n buildTextFieldComponent({\n id: 'q1',\n name: 'textField',\n title: 'This is the first textfield question',\n hint: 'Help text'\n }),\n buildTextFieldComponent({\n id: 'q2',\n name: 'textField',\n title: 'This is the second textfield question',\n hint: 'Help text'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ]\n})\n\nexport const formDefinitionWithLocationAndDeclaration = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildLatLongFieldComponent({\n id: 'q1',\n name: 'latLongField',\n title: 'This is the first lat long field question',\n hint: 'Hint text',\n options: {\n instructionText: 'Some instruction text'\n }\n }),\n buildDeclarationFieldComponent({\n id: 'q2',\n name: 'declarationField',\n title: 'This is a declaration question',\n hint: 'Declaration hint text',\n content: 'This is the declaration that needs agreeing to',\n shortDescription: 'Declaration short desc'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ]\n})\n\nexport const formDefinitionWithRepeater = buildDefinition({\n pages: [\n buildRepeaterPage({\n id: 'p1',\n section: 'section',\n components: [\n buildTextFieldComponent({\n id: 'q1',\n name: 'TextField',\n title: 'This is the first text field field question',\n hint: 'Hint text',\n shortDescription: 'Short desc'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ]\n})\n\nexport const formDefinitionWithNoQuestions = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ]\n})\n\nexport const formDefinitionWithRadioQuestion = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildRadiosComponent({\n id: 'q1',\n name: 'radioField',\n title: 'This is a radio question',\n hint: 'Help text',\n list: 'my-list-id'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ],\n lists: [\n {\n name: 'my-list',\n id: 'my-list-id',\n type: 'string',\n title: 'list for radio',\n items: [\n {\n id: 'option-1',\n text: 'Option 1',\n hint: {\n text: 'Option 1 hint'\n },\n value: 'Option1'\n },\n {\n id: 'option-2',\n text: 'Option 2',\n hint: {\n text: 'Option 2 hint'\n },\n value: 'Option2'\n },\n {\n id: 'option-3',\n text: 'Option 3',\n hint: {\n text: 'Option 3 hint'\n },\n value: 'Option3'\n }\n ]\n }\n ]\n})\n"],"mappings":"AAAA,SACEA,8BAA8B,EAC9BC,0BAA0B,EAC1BC,sBAAsB,EACtBC,oBAAoB,EACpBC,uBAAuB;AAEzB,SAASC,eAAe;AACxB,SACEC,iBAAiB,EACjBC,iBAAiB,EACjBC,gBAAgB;AAGlB,OAAO,MAAMC,4BAA4B,GAAGJ,eAAe,CAAC;EAC1DK,KAAK,EAAE,CACLJ,iBAAiB,CAAC;IAChBK,EAAE,EAAE,IAAI;IACRC,OAAO,EAAE,SAAS;IAClBC,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R,CAAC,CAAC,CACH;IACDb,IAAI,EAAE,CAAC;MAAEC,IAAI,EAAE;IAAW,CAAC;EAC7B,CAAC,CAAC,EACFV,gBAAgB,CAAC;IACfG,EAAE,EAAE;EACN,CAAC,CAAC,CACH;EACDoB,KAAK,EAAE,CACL;IACEjB,IAAI,EAAE,SAAS;IACfH,EAAE,EAAE,YAAY;IAChBqB,IAAI,EAAE,QAAQ;IACdjB,KAAK,EAAE,gBAAgB;IACvBkB,KAAK,EAAE,CACL;MACEtB,EAAE,EAAE,UAAU;MACduB,IAAI,EAAE,UAAU;MAChBlB,IAAI,EAAE;QACJkB,IAAI,EAAE;MACR,CAAC;MACDC,KAAK,EAAE;IACT,CAAC,EACD;MACExB,EAAE,EAAE,UAAU;MACduB,IAAI,EAAE,UAAU;MAChBlB,IAAI,EAAE;QACJkB,IAAI,EAAE;MACR,CAAC;MACDC,KAAK,EAAE;IACT,CAAC,EACD;MACExB,EAAE,EAAE,UAAU;MACduB,IAAI,EAAE,UAAU;MAChBlB,IAAI,EAAE;QACJkB,IAAI,EAAE;MACR,CAAC;MACDC,KAAK,EAAE;IACT,CAAC;EAEL,CAAC;AAEL,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"examples.js","names":["buildDeclarationFieldComponent","buildLatLongFieldComponent","buildMarkdownComponent","buildRadiosComponent","buildTextFieldComponent","buildDefinition","buildQuestionPage","buildRepeaterPage","buildSummaryPage","formDefinitionWithSinglePage","pages","id","section","components","name","title","hint","next","path","formDefinitionWithoutSummary","formDefinitionWithTwoQuestions","formDefinitionWithTwoQuestionsAndGuidance","content","formDefinitionWithLocationAndDeclaration","options","instructionText","shortDescription","formDefinitionWithFormLevelDeclaration","formDefinitionWithRepeater","formDefinitionWithNoQuestions","formDefinitionWithRadioQuestion","list","lists","type","items","text","value"],"sources":["../../../src/__stubs__/examples.js"],"sourcesContent":["import {\n buildDeclarationFieldComponent,\n buildLatLongFieldComponent,\n buildMarkdownComponent,\n buildRadiosComponent,\n buildTextFieldComponent\n} from '~/src/__stubs__/components.js'\nimport { buildDefinition } from '~/src/__stubs__/form-definition.js'\nimport {\n buildQuestionPage,\n buildRepeaterPage,\n buildSummaryPage\n} from '~/src/__stubs__/pages.js'\n\nexport const formDefinitionWithSinglePage = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildTextFieldComponent({\n id: 'c1',\n name: 'textField',\n title: 'This is your first field',\n hint: 'Help text'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'c2'\n })\n ]\n})\n\nexport const formDefinitionWithoutSummary = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildTextFieldComponent({\n id: 'c1',\n name: 'textField',\n title: 'This is your first field',\n hint: 'Help text'\n })\n ],\n next: [{ path: '/summary' }]\n })\n ]\n})\n\nexport const formDefinitionWithTwoQuestions = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildTextFieldComponent({\n id: 'q1',\n name: 'textField',\n title: 'This is your first question',\n hint: 'Help text'\n }),\n buildTextFieldComponent({\n id: 'q2',\n name: 'textField',\n title: 'This is your second question',\n hint: 'Help text'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ]\n})\n\nexport const formDefinitionWithTwoQuestionsAndGuidance = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildMarkdownComponent({ content: 'My markdown text' }),\n buildTextFieldComponent({\n id: 'q1',\n name: 'textField',\n title: 'This is the first textfield question',\n hint: 'Help text'\n }),\n buildTextFieldComponent({\n id: 'q2',\n name: 'textField',\n title: 'This is the second textfield question',\n hint: 'Help text'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ]\n})\n\nexport const formDefinitionWithLocationAndDeclaration = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildLatLongFieldComponent({\n id: 'q1',\n name: 'latLongField',\n title: 'This is the first lat long field question',\n hint: 'Hint text',\n options: {\n instructionText: 'Some instruction text'\n }\n }),\n buildDeclarationFieldComponent({\n id: 'q2',\n name: 'declarationField',\n title: 'This is a declaration question',\n hint: 'Declaration hint text',\n content: 'This is the declaration that needs agreeing to',\n shortDescription: 'Declaration short desc'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ]\n})\n\nexport const formDefinitionWithFormLevelDeclaration = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildTextFieldComponent({\n id: 'q1',\n name: 'textField',\n title: 'This is the first textfield question',\n hint: 'Hint text 1',\n shortDescription: 'Short desc 1'\n }),\n buildTextFieldComponent({\n id: 'q2',\n name: 'textField',\n title: 'This is the second textfield question',\n hint: 'Hint text 2',\n shortDescription: 'Short desc 2'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2',\n components: [\n buildMarkdownComponent({\n id: 'q10',\n content: 'This is a final declaration for the summary page'\n })\n ]\n })\n ]\n})\n\nexport const formDefinitionWithRepeater = buildDefinition({\n pages: [\n buildRepeaterPage({\n id: 'p1',\n section: 'section',\n components: [\n buildTextFieldComponent({\n id: 'q1',\n name: 'TextField',\n title: 'This is the first text field field question',\n hint: 'Hint text',\n shortDescription: 'Short desc'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ]\n})\n\nexport const formDefinitionWithNoQuestions = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ]\n})\n\nexport const formDefinitionWithRadioQuestion = buildDefinition({\n pages: [\n buildQuestionPage({\n id: 'p1',\n section: 'section',\n components: [\n buildRadiosComponent({\n id: 'q1',\n name: 'radioField',\n title: 'This is a radio question',\n hint: 'Help text',\n list: 'my-list-id'\n })\n ],\n next: [{ path: '/summary' }]\n }),\n buildSummaryPage({\n id: 'p2'\n })\n ],\n lists: [\n {\n name: 'my-list',\n id: 'my-list-id',\n type: 'string',\n title: 'list for radio',\n items: [\n {\n id: 'option-1',\n text: 'Option 1',\n hint: {\n text: 'Option 1 hint'\n },\n value: 'Option1'\n },\n {\n id: 'option-2',\n text: 'Option 2',\n hint: {\n text: 'Option 2 hint'\n },\n value: 'Option2'\n },\n {\n id: 'option-3',\n text: 'Option 3',\n hint: {\n text: 'Option 3 hint'\n },\n value: 'Option3'\n }\n ]\n }\n ]\n})\n"],"mappings":"AAAA,SACEA,8BAA8B,EAC9BC,0BAA0B,EAC1BC,sBAAsB,EACtBC,oBAAoB,EACpBC,uBAAuB;AAEzB,SAASC,eAAe;AACxB,SACEC,iBAAiB,EACjBC,iBAAiB,EACjBC,gBAAgB;AAGlB,OAAO,MAAMC,4BAA4B,GAAGJ,eAAe,CAAC;EAC1DK,KAAK,EAAE,CACLJ,iBAAiB,CAAC;IAChBK,EAAE,EAAE,IAAI;IACRC,OAAO,EAAE,SAAS;IAClBC,UAAU,EAAE,CACVT,uBAAuB,CAAC;MACtBO,EAAE,EAAE,IAAI;MACRG,IAAI,EAAE,WAAW;MACjBC,KAAK,EAAE,0BAA0B;MACjCC,IAAI,EAAE;IACR,CAAC,CAAC,CACH;IACDC,IAAI,EAAE,CAAC;MAAEC,IAAI,EAAE;IAAW,CAAC;EAC7B,CAAC,CAAC,EACFV,gBAAgB,CAAC;IACfG,EAAE,EAAE;EACN,CAAC,CAAC;AAEN,CAAC,CAAC;AAEF,OAAO,MAAMQ,4BAA4B,GAAGd,eAAe,CAAC;EAC1DK,KAAK,EAAE,CACLJ,iBAAiB,CAAC;IAChBK,EAAE,EAAE,IAAI;IACRC,OAAO,EAAE,SAAS;IAClBC,UAAU,EAAE,CACVT,uBAAuB,CAAC;MACtBO,EAAE,EAAE,IAAI;M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AAE,CACLJ,iBAAiB,CAAC;IAChBK,EAAE,EAAE,IAAI;IACRC,OAAO,EAAE,SAAS;IAClBC,UAAU,EAAE,CACVV,oBAAoB,CAAC;MACnBQ,EAAE,EAAE,IAAI;MACRG,IAAI,EAAE,YAAY;MAClBC,KAAK,EAAE,0BAA0B;MACjCC,IAAI,EAAE,WAAW;MACjBe,IAAI,EAAE;IACR,CAAC,CAAC,CACH;IACDd,IAAI,EAAE,CAAC;MAAEC,IAAI,EAAE;IAAW,CAAC;EAC7B,CAAC,CAAC,EACFV,gBAAgB,CAAC;IACfG,EAAE,EAAE;EACN,CAAC,CAAC,CACH;EACDqB,KAAK,EAAE,CACL;IACElB,IAAI,EAAE,SAAS;IACfH,EAAE,EAAE,YAAY;IAChBsB,IAAI,EAAE,QAAQ;IACdlB,KAAK,EAAE,gBAAgB;IACvBmB,KAAK,EAAE,CACL;MACEvB,EAAE,EAAE,UAAU;MACdwB,IAAI,EAAE,UAAU;MAChBnB,IAAI,EAAE;QACJmB,IAAI,EAAE;MACR,CAAC;MACDC,KAAK,EAAE;IACT,CAAC,EACD;MACEzB,EAAE,EAAE,UAAU;MACdwB,IAAI,EAAE,UAAU;MAChBnB,IAAI,EAAE;QACJmB,IAAI,EAAE;MACR,CAAC;MACDC,KAAK,EAAE;IACT,CAAC,EACD;MACEzB,EAAE,EAAE,UAAU;MACdwB,IAAI,EAAE,UAAU;MAChBnB,IAAI,EAAE;QACJmB,IAAI,EAAE;MACR,CAAC;MACDC,KAAK,EAAE;IACT,CAAC;EAEL,CAAC;AAEL,CAAC,CAAC","ignoreList":[]}
|
|
@@ -36,6 +36,7 @@ export const TranslationRowTypes = {
|
|
|
36
36
|
ListItemHint: 'ListItemHint',
|
|
37
37
|
InstructionText: 'InstructionText',
|
|
38
38
|
DeclarationBody: 'DeclarationBody',
|
|
39
|
+
EndOfFormDeclarationBody: 'EndOfFormDeclarationBody',
|
|
39
40
|
PaymentDescription: 'PaymentDescription'
|
|
40
41
|
};
|
|
41
42
|
export const TEXTAREA_3_ROWS = 'textarea3';
|
|
@@ -82,6 +83,12 @@ export const keyConfig = {
|
|
|
82
83
|
displayName: 'Declaration body',
|
|
83
84
|
getLabel: (pageNum, questionNum) => `Welsh declaration body - Page ${pageNum}, question ${questionNum}`
|
|
84
85
|
},
|
|
86
|
+
[TranslationRowTypes.EndOfFormDeclarationBody]: {
|
|
87
|
+
jsonPrefix: 'components',
|
|
88
|
+
jsonSuffix: 'content',
|
|
89
|
+
displayName: 'Declaration body',
|
|
90
|
+
getLabel: (pageNum, _questionNum) => `Welsh declaration body - Page ${pageNum}`
|
|
91
|
+
},
|
|
85
92
|
[TranslationRowTypes.PaymentDescription]: {
|
|
86
93
|
jsonPrefix: 'components',
|
|
87
94
|
jsonSuffix: 'paymentDescription',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translations-config.js","names":["ComponentType","TranslationRowTypes","PageHeading","PageGuidance","RepeatTitle","QuestionText","QuestionHint","ShortDescription","ErrorDescription","ListItemText","ListItemHint","InstructionText","DeclarationBody","PaymentDescription","TEXTAREA_3_ROWS","TEXTAREA_5_ROWS","TEXTAREA_12_ROWS_WITH_MARKDOWN","LIST_ITEM_HINT","LIST_ITEM_WITH_HINT_FOLLOWING","keyConfig","jsonPrefix","jsonSuffix","displayName","getLabel","pageNum","questionNum","itemNum","IGNORE_FIELDS","Details","Html","InsetText","HiddenField","lookupTranslation","key","translations","drillDown","keyType","entity","resolveData","options","instructionText","hint","text","content","description","func","entityWithDynamicProperties"],"sources":["../../../../../src/form/form-editor/translations/translations-config.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\n\n/**\n * @typedef {object} TranslationRow\n * @property {string} name - the key name\n * @property {string} [type] - type of text\n * @property {string | undefined} englishContent - English text\n * @property {string | undefined} welshContent - Welsh text\n * @property {number} [pageNum] - page number\n * @property {number} [questionNum] - question number\n * @property {number} [itemNum] - list item number\n * @property {string} [label] - label for field\n */\n\n/**\n * @typedef {{ text: string, href?: string }} ErrorDetailsItem\n * @typedef {Record<string, ErrorDetailsItem>} ErrorDetails\n */\n\n/**\n * @template {object} [Schema=object]\n * @typedef {object} ValidationFailure\n * @property {ErrorDetails} formErrors - Formatted errors for error summary\n * @property {Schema} formValues - Form POST payload from Hapi request\n */\n\nexport const TranslationRowTypes = {\n PageHeading: 'PageHeading',\n PageGuidance: 'PageGuidance',\n RepeatTitle: 'RepeatTitle',\n QuestionText: 'QuestionText',\n QuestionHint: 'QuestionHint',\n ShortDescription: 'ShortDescription',\n ErrorDescription: 'ErrorDescription',\n ListItemText: 'ListItemText',\n ListItemHint: 'ListItemHint',\n InstructionText: 'InstructionText',\n DeclarationBody: 'DeclarationBody',\n PaymentDescription: 'PaymentDescription'\n}\n\nexport const TEXTAREA_3_ROWS = 'textarea3'\nexport const TEXTAREA_5_ROWS = 'textarea5'\nexport const TEXTAREA_12_ROWS_WITH_MARKDOWN = 'textarea12markdown'\nexport const LIST_ITEM_HINT = 'listitemhint'\nexport const LIST_ITEM_WITH_HINT_FOLLOWING = 'listoptionwithhintfollowing'\n\n/** @type {Record<string, { jsonPrefix: string, jsonSuffix: string, displayName: string, getLabel: (pageNum: number, questionNum?: number, itemNum?: number) => string }>} */\nexport const keyConfig = {\n [TranslationRowTypes.QuestionText]: {\n jsonPrefix: 'components',\n jsonSuffix: 'title',\n displayName: 'Question text',\n getLabel: (pageNum, questionNum) =>\n `Welsh question text - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.QuestionHint]: {\n jsonPrefix: 'components',\n jsonSuffix: 'hint',\n displayName: 'Hint',\n getLabel: (pageNum, questionNum) =>\n `Welsh hint - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.ShortDescription]: {\n jsonPrefix: 'components',\n jsonSuffix: 'shortDescription',\n displayName: 'Short description',\n getLabel: (pageNum, questionNum) =>\n `Welsh short description - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.ErrorDescription]: {\n jsonPrefix: 'components',\n jsonSuffix: 'errorDescription',\n displayName: 'Error description',\n getLabel: (pageNum, questionNum) =>\n `Welsh error description - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.InstructionText]: {\n jsonPrefix: 'components',\n jsonSuffix: 'instructionText',\n displayName: 'Instruction text',\n getLabel: (pageNum, questionNum) =>\n `Welsh instruction text - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.DeclarationBody]: {\n jsonPrefix: 'components',\n jsonSuffix: 'content',\n displayName: 'Declaration body',\n getLabel: (pageNum, questionNum) =>\n `Welsh declaration body - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.PaymentDescription]: {\n jsonPrefix: 'components',\n jsonSuffix: 'paymentDescription',\n displayName: 'Payment description',\n getLabel: (pageNum, questionNum) =>\n `Welsh payment description - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.ListItemText]: {\n jsonPrefix: 'listItems',\n jsonSuffix: 'text',\n displayName: 'Option',\n getLabel: (pageNum, questionNum, itemNum) =>\n `Welsh option ${itemNum} - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.ListItemHint]: {\n jsonPrefix: 'listItems',\n jsonSuffix: 'hint',\n displayName: 'Option hint',\n getLabel: (pageNum, questionNum, itemNum) =>\n `Welsh hint for option ${itemNum} - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.PageGuidance]: {\n jsonPrefix: 'components',\n jsonSuffix: 'content',\n displayName: 'Guidance text',\n getLabel: (pageNum) => `Welsh guidance text (markdown) - page ${pageNum}`\n },\n [TranslationRowTypes.PageHeading]: {\n jsonPrefix: 'pages',\n jsonSuffix: 'title',\n displayName: 'Page heading',\n getLabel: (pageNum) => `Welsh page heading - page ${pageNum}`\n },\n [TranslationRowTypes.RepeatTitle]: {\n jsonPrefix: 'pages',\n jsonSuffix: 'repeatTitle',\n displayName: 'Repeat name',\n getLabel: (pageNum) => `Welsh repeat name - page ${pageNum}`\n }\n}\n\nexport const IGNORE_FIELDS = [\n ComponentType.Details,\n ComponentType.Html,\n ComponentType.InsetText,\n ComponentType.HiddenField\n]\n\n/**\n * Lookup a translation from a list of translation records.\n * @param {string} key - The translation key to look up.\n * @param {Record<string, string> | undefined} translations - The translation values to search.\n */\nexport function lookupTranslation(key, translations) {\n if (!translations) {\n return ''\n }\n return translations[key] ?? ''\n}\n\n/**\n * Resolve the underlying content for a translation row from an entity.\n * Involves using the appropriate child properties if necessary.\n * @param {string} keyType - The translation row type being resolved.\n * @param {ComponentDef | Page | Item} entity - The entity that may contain the content to translate.\n * @param {string} jsonSuffix - The property name to read from the entity.\n */\nexport function drillDown(keyType, entity, jsonSuffix) {\n /** @type {Partial<Record<string, (entity: ComponentDef | Page | Item) => string>>} */\n const resolveData = {\n [TranslationRowTypes.InstructionText]: () =>\n // @ts-expect-error - dynamic property lookup\n 'options' in entity ? entity.options?.instructionText : '',\n [TranslationRowTypes.ListItemHint]: () =>\n // @ts-expect-error - dynamic property lookup\n 'hint' in entity ? entity.hint.text : '',\n [TranslationRowTypes.DeclarationBody]: () =>\n 'content' in entity ? entity.content : '',\n [TranslationRowTypes.PaymentDescription]: () =>\n // @ts-expect-error - dynamic property lookup\n 'options' in entity ? entity.options?.description : ''\n }\n const func = resolveData[keyType]\n if (func) {\n return func(entity)\n } else {\n const entityWithDynamicProperties = /** @type {Record<string, unknown>} */ (\n /** @type {unknown} */ (entity)\n )\n if (typeof entity === 'object') {\n return jsonSuffix in entityWithDynamicProperties\n ? /** @type {string} */ (entityWithDynamicProperties[jsonSuffix])\n : ''\n }\n }\n return entity\n}\n\n/**\n * @import { ComponentDef } from '~/src/components/types.js'\n * @import { Item, Page } from '~/src/form/form-definition/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMC,mBAAmB,GAA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AC5D,CAACvC,mBAAmB,CAACS,YAAY,GAAG;IAClC;IACA,MAAM,IAAI2B,MAAM,GAAGA,MAAM,CAACI,IAAI,CAACC,IAAI,GAAG,EAAE;IAC1C,CAACzC,mBAAmB,CAACW,eAAe,GAAG,MACrC,SAAS,IAAIyB,MAAM,GAAGA,MAAM,CAACM,OAAO,GAAG,EAAE;IAC3C,CAAC1C,mBAAmB,CAACY,kBAAkB,GAAG;IACxC;IACA,SAAS,IAAIwB,MAAM,GAAGA,MAAM,CAACE,OAAO,EAAEK,WAAW,GAAG;EACxD,CAAC;EACD,MAAMC,IAAI,GAAGP,WAAW,CAACF,OAAO,CAAC;EACjC,IAAIS,IAAI,EAAE;IACR,OAAOA,IAAI,CAACR,MAAM,CAAC;EACrB,CAAC,MAAM;IACL,MAAMS,2BAA2B,GAAG;IAClC,sBAAwBT,MACzB;IACD,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;MAC9B,OAAOhB,UAAU,IAAIyB,2BAA2B,IAC5C,qBAAuBA,2BAA2B,CAACzB,UAAU,CAAC,IAC9D,EAAE;IACR;EACF;EACA,OAAOgB,MAAM;AACf;;AAEA;AACA;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"translations-config.js","names":["ComponentType","TranslationRowTypes","PageHeading","PageGuidance","RepeatTitle","QuestionText","QuestionHint","ShortDescription","ErrorDescription","ListItemText","ListItemHint","InstructionText","DeclarationBody","EndOfFormDeclarationBody","PaymentDescription","TEXTAREA_3_ROWS","TEXTAREA_5_ROWS","TEXTAREA_12_ROWS_WITH_MARKDOWN","LIST_ITEM_HINT","LIST_ITEM_WITH_HINT_FOLLOWING","keyConfig","jsonPrefix","jsonSuffix","displayName","getLabel","pageNum","questionNum","_questionNum","itemNum","IGNORE_FIELDS","Details","Html","InsetText","HiddenField","lookupTranslation","key","translations","drillDown","keyType","entity","resolveData","options","instructionText","hint","text","content","description","func","entityWithDynamicProperties"],"sources":["../../../../../src/form/form-editor/translations/translations-config.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\n\n/**\n * @typedef {object} TranslationRow\n * @property {string} name - the key name\n * @property {string} [type] - type of text\n * @property {string | undefined} englishContent - English text\n * @property {string | undefined} welshContent - Welsh text\n * @property {number} [pageNum] - page number\n * @property {number} [questionNum] - question number\n * @property {number} [itemNum] - list item number\n * @property {string} [label] - label for field\n */\n\n/**\n * @typedef {{ text: string, href?: string }} ErrorDetailsItem\n * @typedef {Record<string, ErrorDetailsItem>} ErrorDetails\n */\n\n/**\n * @template {object} [Schema=object]\n * @typedef {object} ValidationFailure\n * @property {ErrorDetails} formErrors - Formatted errors for error summary\n * @property {Schema} formValues - Form POST payload from Hapi request\n */\n\nexport const TranslationRowTypes = {\n PageHeading: 'PageHeading',\n PageGuidance: 'PageGuidance',\n RepeatTitle: 'RepeatTitle',\n QuestionText: 'QuestionText',\n QuestionHint: 'QuestionHint',\n ShortDescription: 'ShortDescription',\n ErrorDescription: 'ErrorDescription',\n ListItemText: 'ListItemText',\n ListItemHint: 'ListItemHint',\n InstructionText: 'InstructionText',\n DeclarationBody: 'DeclarationBody',\n EndOfFormDeclarationBody: 'EndOfFormDeclarationBody',\n PaymentDescription: 'PaymentDescription'\n}\n\nexport const TEXTAREA_3_ROWS = 'textarea3'\nexport const TEXTAREA_5_ROWS = 'textarea5'\nexport const TEXTAREA_12_ROWS_WITH_MARKDOWN = 'textarea12markdown'\nexport const LIST_ITEM_HINT = 'listitemhint'\nexport const LIST_ITEM_WITH_HINT_FOLLOWING = 'listoptionwithhintfollowing'\n\n/** @type {Record<string, { jsonPrefix: string, jsonSuffix: string, displayName: string, getLabel: (pageNum: number, questionNum?: number, itemNum?: number) => string }>} */\nexport const keyConfig = {\n [TranslationRowTypes.QuestionText]: {\n jsonPrefix: 'components',\n jsonSuffix: 'title',\n displayName: 'Question text',\n getLabel: (pageNum, questionNum) =>\n `Welsh question text - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.QuestionHint]: {\n jsonPrefix: 'components',\n jsonSuffix: 'hint',\n displayName: 'Hint',\n getLabel: (pageNum, questionNum) =>\n `Welsh hint - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.ShortDescription]: {\n jsonPrefix: 'components',\n jsonSuffix: 'shortDescription',\n displayName: 'Short description',\n getLabel: (pageNum, questionNum) =>\n `Welsh short description - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.ErrorDescription]: {\n jsonPrefix: 'components',\n jsonSuffix: 'errorDescription',\n displayName: 'Error description',\n getLabel: (pageNum, questionNum) =>\n `Welsh error description - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.InstructionText]: {\n jsonPrefix: 'components',\n jsonSuffix: 'instructionText',\n displayName: 'Instruction text',\n getLabel: (pageNum, questionNum) =>\n `Welsh instruction text - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.DeclarationBody]: {\n jsonPrefix: 'components',\n jsonSuffix: 'content',\n displayName: 'Declaration body',\n getLabel: (pageNum, questionNum) =>\n `Welsh declaration body - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.EndOfFormDeclarationBody]: {\n jsonPrefix: 'components',\n jsonSuffix: 'content',\n displayName: 'Declaration body',\n getLabel: (pageNum, _questionNum) =>\n `Welsh declaration body - Page ${pageNum}`\n },\n [TranslationRowTypes.PaymentDescription]: {\n jsonPrefix: 'components',\n jsonSuffix: 'paymentDescription',\n displayName: 'Payment description',\n getLabel: (pageNum, questionNum) =>\n `Welsh payment description - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.ListItemText]: {\n jsonPrefix: 'listItems',\n jsonSuffix: 'text',\n displayName: 'Option',\n getLabel: (pageNum, questionNum, itemNum) =>\n `Welsh option ${itemNum} - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.ListItemHint]: {\n jsonPrefix: 'listItems',\n jsonSuffix: 'hint',\n displayName: 'Option hint',\n getLabel: (pageNum, questionNum, itemNum) =>\n `Welsh hint for option ${itemNum} - Page ${pageNum}, question ${questionNum}`\n },\n [TranslationRowTypes.PageGuidance]: {\n jsonPrefix: 'components',\n jsonSuffix: 'content',\n displayName: 'Guidance text',\n getLabel: (pageNum) => `Welsh guidance text (markdown) - page ${pageNum}`\n },\n [TranslationRowTypes.PageHeading]: {\n jsonPrefix: 'pages',\n jsonSuffix: 'title',\n displayName: 'Page heading',\n getLabel: (pageNum) => `Welsh page heading - page ${pageNum}`\n },\n [TranslationRowTypes.RepeatTitle]: {\n jsonPrefix: 'pages',\n jsonSuffix: 'repeatTitle',\n displayName: 'Repeat name',\n getLabel: (pageNum) => `Welsh repeat name - page ${pageNum}`\n }\n}\n\nexport const IGNORE_FIELDS = [\n ComponentType.Details,\n ComponentType.Html,\n ComponentType.InsetText,\n ComponentType.HiddenField\n]\n\n/**\n * Lookup a translation from a list of translation records.\n * @param {string} key - The translation key to look up.\n * @param {Record<string, string> | undefined} translations - The translation values to search.\n */\nexport function lookupTranslation(key, translations) {\n if (!translations) {\n return ''\n }\n return translations[key] ?? ''\n}\n\n/**\n * Resolve the underlying content for a translation row from an entity.\n * Involves using the appropriate child properties if necessary.\n * @param {string} keyType - The translation row type being resolved.\n * @param {ComponentDef | Page | Item} entity - The entity that may contain the content to translate.\n * @param {string} jsonSuffix - The property name to read from the entity.\n */\nexport function drillDown(keyType, entity, jsonSuffix) {\n /** @type {Partial<Record<string, (entity: ComponentDef | Page | Item) => string>>} */\n const resolveData = {\n [TranslationRowTypes.InstructionText]: () =>\n // @ts-expect-error - dynamic property lookup\n 'options' in entity ? entity.options?.instructionText : '',\n [TranslationRowTypes.ListItemHint]: () =>\n // @ts-expect-error - dynamic property lookup\n 'hint' in entity ? entity.hint.text : '',\n [TranslationRowTypes.DeclarationBody]: () =>\n 'content' in entity ? entity.content : '',\n [TranslationRowTypes.PaymentDescription]: () =>\n // @ts-expect-error - dynamic property lookup\n 'options' in entity ? entity.options?.description : ''\n }\n const func = resolveData[keyType]\n if (func) {\n return func(entity)\n } else {\n const entityWithDynamicProperties = /** @type {Record<string, unknown>} */ (\n /** @type {unknown} */ (entity)\n )\n if (typeof entity === 'object') {\n return jsonSuffix in entityWithDynamicProperties\n ? /** @type {string} */ (entityWithDynamicProperties[jsonSuffix])\n : ''\n }\n }\n return entity\n}\n\n/**\n * @import { ComponentDef } from '~/src/components/types.js'\n * @import { Item, Page } from '~/src/form/form-definition/types.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMC,mBAAmB,GAAG;EACjCC,WAAW,EAAE,aAAa;EAC1BC,YAAY,EAAE,cAAc;EAC5BC,WAAW,EAAE,aAAa;EAC1BC,YAAY,EAAE,cAAc;EAC5BC,YAAY,EAAE,cAAc;EAC5BC,gBAAgB,EAAE,kBAAkB;EACpCC,gBAAgB,EAAE,kBAAkB;EACpCC,YAAY,EAAE,cAAc;EAC5BC,YAAY,EAAE,cAAc;EAC5BC,eAAe,EAAE,iBAAiB;EAClCC,eAAe,EAAE,iBAAiB;EAClCC,wBAAwB,EAAE,0BAA0B;EACpDC,kBAAkB,EAAE;AACtB,CAAC;AAED,OAAO,MAAMC,eAAe,GAAG,WAAW;AAC1C,OAAO,MAAMC,eAAe,GAAG,WAAW;AAC1C,OAAO,MAAMC,8BAA8B,GAAG,oBAAoB;AAClE,OAAO,MAAMC,cAAc,GAAG,cAAc;AAC5C,OAAO,MAAMC,6BAA6B,GAAG,6BAA6B;;AAE1E;AACA,OAAO,MAAMC,SAAS,GAAG;EACvB,CAACnB,mBAAmB,CAACI,YAAY,GAAG;IAClCgB,UAAU,EAAE,YAAY;IACxBC,UAAU,EAAE,OAAO;IACnBC,WAAW,EAAE,eAAe;IAC5BC,QAAQ,EAAEA,CAACC,OAAO,EAAEC,WAAW,KAC7B,8BAA8BD,OAAO,cAAcC,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QAAQ,EAAE;MAC9B,OAAOjB,UAAU,IAAI0B,2BAA2B,IAC5C,qBAAuBA,2BAA2B,CAAC1B,UAAU,CAAC,IAC9D,EAAE;IACR;EACF;EACA,OAAOiB,MAAM;AACf;;AAEA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ import { buildOverviewSection } from "./translations-overview.js";
|
|
|
5
5
|
import { getListFromComponent } from "../../utils/list.js";
|
|
6
6
|
import { getPageNum, getQuestionNum } from "../../utils/numbering.js";
|
|
7
7
|
import { ControllerType } from "../../../pages/enums.js";
|
|
8
|
-
import { hasComponents } from "../../../pages/helpers.js";
|
|
8
|
+
import { hasComponents, hasComponentsEvenIfNoNext, isSummaryPage } from "../../../pages/helpers.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Create a translation row for a single entity field.
|
|
@@ -35,7 +35,28 @@ function createRow(entity, keyType, {
|
|
|
35
35
|
label: keyProperties.getLabel(pageNum, questionNum, itemNum)
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Constructs a page row
|
|
41
|
+
* @param {string} rowType
|
|
42
|
+
* @param { string | undefined } id
|
|
43
|
+
* @param {number} pageNum
|
|
44
|
+
* @param {string} englishContent
|
|
45
|
+
* @param {Record<string, string>} translations - Existing Welsh translations keyed by translation name.
|
|
46
|
+
* @param {ValidationFailure<any>} [validation] - Optional validation context for posted form values.
|
|
47
|
+
*/
|
|
48
|
+
function buildPageRow(rowType, id, pageNum, englishContent, translations, validation) {
|
|
49
|
+
const keyProperties = keyConfig[rowType];
|
|
50
|
+
const keyName = `${keyProperties.jsonPrefix}.${id}.${keyProperties.jsonSuffix}`;
|
|
51
|
+
return {
|
|
52
|
+
name: keyName,
|
|
53
|
+
type: rowType,
|
|
54
|
+
pageNum,
|
|
55
|
+
englishContent,
|
|
56
|
+
welshContent: validation?.formValues[keyName] ?? lookupTranslation(keyName, translations),
|
|
57
|
+
label: keyProperties.getLabel(pageNum)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
39
60
|
|
|
40
61
|
/**
|
|
41
62
|
* Build the translation rows for a single page.
|
|
@@ -46,46 +67,26 @@ const allowedControllerTypesSet = new Set([ControllerType.Page, ControllerType.R
|
|
|
46
67
|
* @returns {TranslationRow[]} The translation rows generated for the page.
|
|
47
68
|
*/
|
|
48
69
|
function buildPage(page, pageNum, translations, validation) {
|
|
49
|
-
if (page.controller && !allowedControllerTypesSet.has(page.controller)) {
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
70
|
const translationRows = [];
|
|
71
|
+
|
|
72
|
+
// The only possible element for translation on a summary page is the end-of-form declaration,
|
|
73
|
+
// so we don't proceed further in this case
|
|
74
|
+
if (isSummaryPage(page)) {
|
|
75
|
+
const endOfFormDeclaration = hasComponentsEvenIfNoNext(page) && page.components[0].type === ComponentType.Markdown ? page.components[0] : undefined;
|
|
76
|
+
if (endOfFormDeclaration) {
|
|
77
|
+
translationRows.push(buildPageRow(TranslationRowTypes.EndOfFormDeclarationBody, endOfFormDeclaration.id, pageNum, endOfFormDeclaration.content, translations, validation));
|
|
78
|
+
}
|
|
79
|
+
return translationRows;
|
|
80
|
+
}
|
|
53
81
|
if (page.title) {
|
|
54
|
-
|
|
55
|
-
const keyName = `${keyProperties.jsonPrefix}.${page.id}.${keyProperties.jsonSuffix}`;
|
|
56
|
-
translationRows.push({
|
|
57
|
-
name: keyName,
|
|
58
|
-
type: TranslationRowTypes.PageHeading,
|
|
59
|
-
pageNum,
|
|
60
|
-
englishContent: page.title,
|
|
61
|
-
welshContent: validation?.formValues[keyName] ?? lookupTranslation(keyName, translations),
|
|
62
|
-
label: keyProperties.getLabel(pageNum)
|
|
63
|
-
});
|
|
82
|
+
translationRows.push(buildPageRow(TranslationRowTypes.PageHeading, page.id, pageNum, page.title, translations, validation));
|
|
64
83
|
}
|
|
65
84
|
const guidance = hasComponents(page) && page.components[0].type === ComponentType.Markdown ? page.components[0] : undefined;
|
|
66
85
|
if (guidance) {
|
|
67
|
-
|
|
68
|
-
const keyName = `${keyProperties.jsonPrefix}.${guidance.id}.${keyProperties.jsonSuffix}`;
|
|
69
|
-
translationRows.push({
|
|
70
|
-
name: keyName,
|
|
71
|
-
type: TranslationRowTypes.PageGuidance,
|
|
72
|
-
pageNum,
|
|
73
|
-
englishContent: guidance.content,
|
|
74
|
-
welshContent: validation?.formValues[keyName] ?? lookupTranslation(keyName, translations),
|
|
75
|
-
label: keyProperties.getLabel(pageNum)
|
|
76
|
-
});
|
|
86
|
+
translationRows.push(buildPageRow(TranslationRowTypes.PageGuidance, guidance.id, pageNum, guidance.content, translations, validation));
|
|
77
87
|
}
|
|
78
88
|
if (page.controller === ControllerType.Repeat) {
|
|
79
|
-
|
|
80
|
-
const keyName = `${keyProperties.jsonPrefix}.${page.id}.${keyProperties.jsonSuffix}`;
|
|
81
|
-
translationRows.push({
|
|
82
|
-
name: keyName,
|
|
83
|
-
type: TranslationRowTypes.RepeatTitle,
|
|
84
|
-
pageNum,
|
|
85
|
-
englishContent: page.repeat.options.title,
|
|
86
|
-
welshContent: validation?.formValues[keyName] ?? lookupTranslation(keyName, translations),
|
|
87
|
-
label: keyProperties.getLabel(pageNum)
|
|
88
|
-
});
|
|
89
|
+
translationRows.push(buildPageRow(TranslationRowTypes.RepeatTitle, page.id, pageNum, page.repeat.options.title, translations, validation));
|
|
89
90
|
}
|
|
90
91
|
return translationRows;
|
|
91
92
|
}
|
|
@@ -185,7 +186,7 @@ export function buildTranslationDataRows(metadata, definition, validation) {
|
|
|
185
186
|
for (const page of definition.pages) {
|
|
186
187
|
const pageId = /** @type {string} */page.id;
|
|
187
188
|
const pageNum = getPageNum(definition, pageId);
|
|
188
|
-
const components =
|
|
189
|
+
const components = hasComponentsEvenIfNoNext(page) ? page.components : [];
|
|
189
190
|
if (components.length === 0) {
|
|
190
191
|
continue;
|
|
191
192
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translations.js","names":["ComponentType","isListType","isTypeWithInstructions","IGNORE_FIELDS","TranslationRowTypes","drillDown","keyConfig","lookupTranslation","buildOverviewSection","getListFromComponent","getPageNum","getQuestionNum","ControllerType","hasComponents","createRow","entity","keyType","pageNum","questionNum","itemNum","translations","validation","keyProperties","innerEnglishContent","jsonSuffix","keyName","jsonPrefix","id","name","type","englishContent","welshContent","formValues","label","getLabel","allowedControllerTypesSet","Set","Page","Repeat","Start","FileUpload","Terminal","buildPage","page","controller","has","translationRows","title","PageHeading","push","guidance","components","Markdown","undefined","PageGuidance","content","RepeatTitle","repeat","options","buildComponent","definition","component","includes","rows","typed","PaymentField","QuestionText","hint","QuestionHint","ShortDescription","errorDescription","ErrorDescription","PaymentDescription","DeclarationField","DeclarationBody","instructionText","InstructionText","addSelectionOptions","YesNoField","list","items","length","item","listOptions","ListItemText","ListItemHint","buildTranslationDataRows","metadata","translationsJSON","cy","overviewRows","formRows","pages","pageId","questionId"],"sources":["../../../../../src/form/form-editor/translations/translations.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { isListType, isTypeWithInstructions } from '~/src/components/helpers.js'\nimport {\n IGNORE_FIELDS,\n TranslationRowTypes,\n drillDown,\n keyConfig,\n lookupTranslation\n} from '~/src/form/form-editor/translations/translations-config.js'\nimport { buildOverviewSection } from '~/src/form/form-editor/translations/translations-overview.js'\nimport { getListFromComponent } from '~/src/form/utils/list.js'\nimport { getPageNum, getQuestionNum } from '~/src/form/utils/numbering.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport { hasComponents } from '~/src/pages/helpers.js'\n\n/**\n * Create a translation row for a single entity field.\n * @param {ComponentDef | Page | Item} entity - The source entity that contains the English content.\n * @param {string} keyType - The translation row type to build.\n * @param {{ pageNum: number, questionNum?: number, itemNum?: number, translations: Record<string, string>, validation?: ValidationFailure<any> }} options - The row context including numbering and translation values.\n * @returns {TranslationRow} The populated translation row for the entity field.\n */\nfunction createRow(\n entity,\n keyType,\n { pageNum, questionNum, itemNum, translations, validation }\n) {\n const keyProperties = keyConfig[keyType]\n\n const innerEnglishContent = drillDown(\n keyType,\n entity,\n keyProperties.jsonSuffix\n )\n\n const keyName = `${keyProperties.jsonPrefix}.${entity.id}.${keyProperties.jsonSuffix}`\n\n return {\n name: keyName,\n type: keyType,\n pageNum,\n questionNum,\n itemNum,\n englishContent: innerEnglishContent,\n welshContent:\n validation?.formValues[keyName] ??\n lookupTranslation(keyName, translations),\n label: keyProperties.getLabel(pageNum, questionNum, itemNum)\n }\n}\n\nconst allowedControllerTypesSet = new Set([\n ControllerType.Page,\n ControllerType.Repeat,\n ControllerType.Start,\n ControllerType.FileUpload,\n ControllerType.Terminal\n])\n\n/**\n * Build the translation rows for a single page.\n * @param {Page} page - The page definition to inspect for translatable content.\n * @param {number} pageNum - The page number used in the generated labels.\n * @param {Record<string, string>} translations - Existing Welsh translations keyed by translation name.\n * @param {ValidationFailure<any>} [validation] - Optional validation context for posted form values.\n * @returns {TranslationRow[]} The translation rows generated for the page.\n */\nfunction buildPage(page, pageNum, translations, validation) {\n if (page.controller && !allowedControllerTypesSet.has(page.controller)) {\n return []\n }\n\n const translationRows = []\n if (page.title) {\n const keyProperties = keyConfig[TranslationRowTypes.PageHeading]\n\n const keyName = `${keyProperties.jsonPrefix}.${page.id}.${keyProperties.jsonSuffix}`\n\n translationRows.push({\n name: keyName,\n type: TranslationRowTypes.PageHeading,\n pageNum,\n englishContent: page.title,\n welshContent:\n validation?.formValues[keyName] ??\n lookupTranslation(keyName, translations),\n label: keyProperties.getLabel(pageNum)\n })\n }\n\n const guidance =\n hasComponents(page) && page.components[0].type === ComponentType.Markdown\n ? page.components[0]\n : undefined\n if (guidance) {\n const keyProperties = keyConfig[TranslationRowTypes.PageGuidance]\n const keyName = `${keyProperties.jsonPrefix}.${guidance.id}.${keyProperties.jsonSuffix}`\n\n translationRows.push({\n name: keyName,\n type: TranslationRowTypes.PageGuidance,\n pageNum,\n englishContent: guidance.content,\n welshContent:\n validation?.formValues[keyName] ??\n lookupTranslation(keyName, translations),\n label: keyProperties.getLabel(pageNum)\n })\n }\n\n if (page.controller === ControllerType.Repeat) {\n const keyProperties = keyConfig[TranslationRowTypes.RepeatTitle]\n const keyName = `${keyProperties.jsonPrefix}.${page.id}.${keyProperties.jsonSuffix}`\n\n translationRows.push({\n name: keyName,\n type: TranslationRowTypes.RepeatTitle,\n pageNum,\n englishContent: page.repeat.options.title,\n welshContent:\n validation?.formValues[keyName] ??\n lookupTranslation(keyName, translations),\n label: keyProperties.getLabel(pageNum)\n })\n }\n\n return translationRows\n}\n\n/**\n * Build the translation rows for a single component.\n * @param {FormDefinition} definition - The overall form definition used to resolve list-based content.\n * @param {ComponentDef} component - The component to inspect for translatable fields.\n * @param {number} pageNum - The page number used in the generated labels.\n * @param {number} questionNum - The question number used in the generated labels.\n * @param {Record<string, string>} translations - Existing Welsh translations keyed by translation name.\n * @param {ValidationFailure<any>} [validation] - Optional validation context for posted form values.\n * @returns {TranslationRow[]} The translation rows generated for the component.\n */\nexport function buildComponent(\n definition,\n component,\n pageNum,\n questionNum,\n translations,\n validation\n) {\n if (IGNORE_FIELDS.includes(component.type)) {\n return []\n }\n\n const rows = []\n\n const options = { pageNum, questionNum, translations, validation }\n\n const typed = /** @type {InputFieldsComponentsDef} */ (component)\n if (typed.title && component.type !== ComponentType.PaymentField) {\n rows.push(createRow(component, TranslationRowTypes.QuestionText, options))\n }\n if (typed.hint) {\n rows.push(createRow(component, TranslationRowTypes.QuestionHint, options))\n }\n\n if (component.type !== ComponentType.PaymentField) {\n rows.push(\n createRow(component, TranslationRowTypes.ShortDescription, options)\n )\n if (typed.errorDescription) {\n rows.push(\n createRow(component, TranslationRowTypes.ErrorDescription, options)\n )\n }\n } else {\n rows.push(\n createRow(component, TranslationRowTypes.PaymentDescription, options)\n )\n }\n\n if (component.type === ComponentType.DeclarationField) {\n rows.push(\n createRow(component, TranslationRowTypes.DeclarationBody, options)\n )\n }\n\n if (typed.options.instructionText && isTypeWithInstructions(component.type)) {\n rows.push(\n createRow(component, TranslationRowTypes.InstructionText, options)\n )\n }\n\n if (isListType(component.type)) {\n addSelectionOptions(rows, component, definition, options)\n }\n return rows\n}\n\n/**\n * Add translation rows for the select item options of a list-based component.\n * @param {any[]} rows - The accumulator for translation rows.\n * @param {ComponentDef} component - The list-based component to inspect.\n * @param {FormDefinition} definition - The form definition that contains the option list data.\n * @param {{ pageNum: number, questionNum?: number, translations: Record<string, string>, validation?: ValidationFailure<any> }} options - The row context including numbering and translation values.\n */\nfunction addSelectionOptions(rows, component, definition, options) {\n // Temporary workaround - ignore for Yes/No and use defaults in the plugin,\n // until we create a solution that allows users to override the Yes/No options\n if (component.type === ComponentType.YesNoField) {\n return\n }\n\n const list = getListFromComponent(component, definition)\n if (list?.items.length) {\n let itemNum = 0\n for (const item of list.items) {\n itemNum++\n const listOptions = {\n ...options,\n itemNum\n }\n if (item.hint) {\n rows.push(\n createRow(item, TranslationRowTypes.ListItemText, listOptions),\n createRow(item, TranslationRowTypes.ListItemHint, listOptions)\n )\n } else {\n rows.push(\n createRow(item, TranslationRowTypes.ListItemText, listOptions)\n )\n }\n }\n }\n}\n\n/**\n * Build the overview and form translation rows for a form definition.\n * @param {FormMetadata} metadata - The form metadata used to build the overview section.\n * @param {FormDefinition} definition - The form definition containing pages and components.\n * @param {ValidationFailure<any>} [validation] - Optional validation context for posted form values.\n * @returns {{ overviewRows: TranslationRow[], formRows: TranslationRow[] }} The generated overview and form translation rows.\n */\nexport function buildTranslationDataRows(metadata, definition, validation) {\n const translationsJSON = /** @type {Record<string, string>} */ (\n // @ts-expect-error - dynamic language definition\n definition.metadata?.translations?.cy\n )\n\n const overviewRows = buildOverviewSection(\n metadata,\n definition,\n translationsJSON,\n validation\n )\n\n const formRows = []\n for (const page of definition.pages) {\n const pageId = /** @type {string} */ (page.id)\n const pageNum = getPageNum(definition, pageId)\n const components = hasComponents(page) ? page.components : []\n if (components.length === 0) {\n continue\n }\n\n formRows.push(...buildPage(page, pageNum, translationsJSON, validation))\n\n for (const component of components) {\n if (component.type === ComponentType.Markdown) {\n continue\n }\n const questionId = /** @type {string} */ (component.id)\n const questionNum = getQuestionNum(definition, pageId, questionId)\n\n formRows.push(\n ...buildComponent(\n definition,\n component,\n pageNum,\n questionNum,\n translationsJSON,\n validation\n )\n )\n }\n }\n\n return {\n overviewRows,\n formRows\n }\n}\n\n/**\n * @import { ComponentDef, InputFieldsComponentsDef } from '~/src/components/types.js'\n * @import { FormMetadata } from '~/src/form/form-metadata/types.js'\n * @import { FormDefinition, Item, Page } from '~/src/form/form-definition/types.js'\n * @import { TranslationRow, ValidationFailure } from '~/src/form/form-editor/translations/translations-config.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,UAAU,EAAEC,sBAAsB;AAC3C,SACEC,aAAa,EACbC,mBAAmB,EACnBC,SAAS,EACTC,SAAS,EACTC,iBAAiB;AAEnB,SAASC,oBAAoB;AAC7B,SAASC,oBAAoB;AAC7B,SAASC,UAAU,EAAEC,cAAc;AACnC,SAASC,cAAc;AACvB,SAASC,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAChBC,MAAM,EACNC,OAAO,EACP;EAAEC,OAAO;EAAEC,WAAW;EAAEC,OAAO;EAAEC,YAAY;EAAEC;AAAW,CAAC,EAC3D;EACA,MAAMC,aAAa,GAAGhB,SAAS,CAACU,OAAO,CAAC;EAExC,MAAMO,mBAAmB,GAAGlB,SAAS,CACnCW,OAAO,EACPD,MAAM,EACNO,aAAa,CAACE,UAChB,CAAC;EAED,MAAMC,OAAO,GAAG,GAAGH,aAAa,CAACI,UAAU,IAAIX,MAAM,CAACY,EAAE,IAAIL,aAAa,CAACE,UAAU,EAAE;EAEtF,OAAO;IACLI,IAAI,EAAEH,OAAO;IACbI,IAAI,EAAEb,OAAO;IACbC,OAAO;IACPC,WAAW;IACXC,OAAO;IACPW,cAAc,EAAEP,mBAAmB;IACnCQ,YAA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K7B,aAAa,CAACoD,QAAQ,EAAE;QAC7C;MACF;MACA,MAAM0C,UAAU,GAAG,qBAAuBjC,SAAS,CAAClC,EAAG;MACvD,MAAMT,WAAW,GAAGP,cAAc,CAACiD,UAAU,EAAEiC,MAAM,EAAEC,UAAU,CAAC;MAElEH,QAAQ,CAAC1C,IAAI,CACX,GAAGU,cAAc,CACfC,UAAU,EACVC,SAAS,EACT5C,OAAO,EACPC,WAAW,EACXsE,gBAAgB,EAChBnE,UACF,CACF,CAAC;IACH;EACF;EAEA,OAAO;IACLqE,YAAY;IACZC;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"translations.js","names":["ComponentType","isListType","isTypeWithInstructions","IGNORE_FIELDS","TranslationRowTypes","drillDown","keyConfig","lookupTranslation","buildOverviewSection","getListFromComponent","getPageNum","getQuestionNum","ControllerType","hasComponents","hasComponentsEvenIfNoNext","isSummaryPage","createRow","entity","keyType","pageNum","questionNum","itemNum","translations","validation","keyProperties","innerEnglishContent","jsonSuffix","keyName","jsonPrefix","id","name","type","englishContent","welshContent","formValues","label","getLabel","buildPageRow","rowType","buildPage","page","translationRows","endOfFormDeclaration","components","Markdown","undefined","push","EndOfFormDeclarationBody","content","title","PageHeading","guidance","PageGuidance","controller","Repeat","RepeatTitle","repeat","options","buildComponent","definition","component","includes","rows","typed","PaymentField","QuestionText","hint","QuestionHint","ShortDescription","errorDescription","ErrorDescription","PaymentDescription","DeclarationField","DeclarationBody","instructionText","InstructionText","addSelectionOptions","YesNoField","list","items","length","item","listOptions","ListItemText","ListItemHint","buildTranslationDataRows","metadata","translationsJSON","cy","overviewRows","formRows","pages","pageId","questionId"],"sources":["../../../../../src/form/form-editor/translations/translations.js"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { isListType, isTypeWithInstructions } from '~/src/components/helpers.js'\nimport {\n IGNORE_FIELDS,\n TranslationRowTypes,\n drillDown,\n keyConfig,\n lookupTranslation\n} from '~/src/form/form-editor/translations/translations-config.js'\nimport { buildOverviewSection } from '~/src/form/form-editor/translations/translations-overview.js'\nimport { getListFromComponent } from '~/src/form/utils/list.js'\nimport { getPageNum, getQuestionNum } from '~/src/form/utils/numbering.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport {\n hasComponents,\n hasComponentsEvenIfNoNext,\n isSummaryPage\n} from '~/src/pages/helpers.js'\n\n/**\n * Create a translation row for a single entity field.\n * @param {ComponentDef | Page | Item} entity - The source entity that contains the English content.\n * @param {string} keyType - The translation row type to build.\n * @param {{ pageNum: number, questionNum?: number, itemNum?: number, translations: Record<string, string>, validation?: ValidationFailure<any> }} options - The row context including numbering and translation values.\n * @returns {TranslationRow} The populated translation row for the entity field.\n */\nfunction createRow(\n entity,\n keyType,\n { pageNum, questionNum, itemNum, translations, validation }\n) {\n const keyProperties = keyConfig[keyType]\n\n const innerEnglishContent = drillDown(\n keyType,\n entity,\n keyProperties.jsonSuffix\n )\n\n const keyName = `${keyProperties.jsonPrefix}.${entity.id}.${keyProperties.jsonSuffix}`\n\n return {\n name: keyName,\n type: keyType,\n pageNum,\n questionNum,\n itemNum,\n englishContent: innerEnglishContent,\n welshContent:\n validation?.formValues[keyName] ??\n lookupTranslation(keyName, translations),\n label: keyProperties.getLabel(pageNum, questionNum, itemNum)\n }\n}\n\n/**\n * Constructs a page row\n * @param {string} rowType\n * @param { string | undefined } id\n * @param {number} pageNum\n * @param {string} englishContent\n * @param {Record<string, string>} translations - Existing Welsh translations keyed by translation name.\n * @param {ValidationFailure<any>} [validation] - Optional validation context for posted form values.\n */\nfunction buildPageRow(\n rowType,\n id,\n pageNum,\n englishContent,\n translations,\n validation\n) {\n const keyProperties = keyConfig[rowType]\n const keyName = `${keyProperties.jsonPrefix}.${id}.${keyProperties.jsonSuffix}`\n\n return {\n name: keyName,\n type: rowType,\n pageNum,\n englishContent,\n welshContent:\n validation?.formValues[keyName] ??\n lookupTranslation(keyName, translations),\n label: keyProperties.getLabel(pageNum)\n }\n}\n\n/**\n * Build the translation rows for a single page.\n * @param {Page} page - The page definition to inspect for translatable content.\n * @param {number} pageNum - The page number used in the generated labels.\n * @param {Record<string, string>} translations - Existing Welsh translations keyed by translation name.\n * @param {ValidationFailure<any>} [validation] - Optional validation context for posted form values.\n * @returns {TranslationRow[]} The translation rows generated for the page.\n */\nfunction buildPage(page, pageNum, translations, validation) {\n const translationRows = []\n\n // The only possible element for translation on a summary page is the end-of-form declaration,\n // so we don't proceed further in this case\n if (isSummaryPage(page)) {\n const endOfFormDeclaration =\n hasComponentsEvenIfNoNext(page) &&\n page.components[0].type === ComponentType.Markdown\n ? page.components[0]\n : undefined\n if (endOfFormDeclaration) {\n translationRows.push(\n buildPageRow(\n TranslationRowTypes.EndOfFormDeclarationBody,\n endOfFormDeclaration.id,\n pageNum,\n endOfFormDeclaration.content,\n translations,\n validation\n )\n )\n }\n return translationRows\n }\n\n if (page.title) {\n translationRows.push(\n buildPageRow(\n TranslationRowTypes.PageHeading,\n page.id,\n pageNum,\n page.title,\n translations,\n validation\n )\n )\n }\n\n const guidance =\n hasComponents(page) && page.components[0].type === ComponentType.Markdown\n ? page.components[0]\n : undefined\n if (guidance) {\n translationRows.push(\n buildPageRow(\n TranslationRowTypes.PageGuidance,\n guidance.id,\n pageNum,\n guidance.content,\n translations,\n validation\n )\n )\n }\n\n if (page.controller === ControllerType.Repeat) {\n translationRows.push(\n buildPageRow(\n TranslationRowTypes.RepeatTitle,\n page.id,\n pageNum,\n page.repeat.options.title,\n translations,\n validation\n )\n )\n }\n\n return translationRows\n}\n\n/**\n * Build the translation rows for a single component.\n * @param {FormDefinition} definition - The overall form definition used to resolve list-based content.\n * @param {ComponentDef} component - The component to inspect for translatable fields.\n * @param {number} pageNum - The page number used in the generated labels.\n * @param {number} questionNum - The question number used in the generated labels.\n * @param {Record<string, string>} translations - Existing Welsh translations keyed by translation name.\n * @param {ValidationFailure<any>} [validation] - Optional validation context for posted form values.\n * @returns {TranslationRow[]} The translation rows generated for the component.\n */\nexport function buildComponent(\n definition,\n component,\n pageNum,\n questionNum,\n translations,\n validation\n) {\n if (IGNORE_FIELDS.includes(component.type)) {\n return []\n }\n\n const rows = []\n\n const options = { pageNum, questionNum, translations, validation }\n\n const typed = /** @type {InputFieldsComponentsDef} */ (component)\n if (typed.title && component.type !== ComponentType.PaymentField) {\n rows.push(createRow(component, TranslationRowTypes.QuestionText, options))\n }\n if (typed.hint) {\n rows.push(createRow(component, TranslationRowTypes.QuestionHint, options))\n }\n\n if (component.type !== ComponentType.PaymentField) {\n rows.push(\n createRow(component, TranslationRowTypes.ShortDescription, options)\n )\n if (typed.errorDescription) {\n rows.push(\n createRow(component, TranslationRowTypes.ErrorDescription, options)\n )\n }\n } else {\n rows.push(\n createRow(component, TranslationRowTypes.PaymentDescription, options)\n )\n }\n\n if (component.type === ComponentType.DeclarationField) {\n rows.push(\n createRow(component, TranslationRowTypes.DeclarationBody, options)\n )\n }\n\n if (typed.options.instructionText && isTypeWithInstructions(component.type)) {\n rows.push(\n createRow(component, TranslationRowTypes.InstructionText, options)\n )\n }\n\n if (isListType(component.type)) {\n addSelectionOptions(rows, component, definition, options)\n }\n return rows\n}\n\n/**\n * Add translation rows for the select item options of a list-based component.\n * @param {any[]} rows - The accumulator for translation rows.\n * @param {ComponentDef} component - The list-based component to inspect.\n * @param {FormDefinition} definition - The form definition that contains the option list data.\n * @param {{ pageNum: number, questionNum?: number, translations: Record<string, string>, validation?: ValidationFailure<any> }} options - The row context including numbering and translation values.\n */\nfunction addSelectionOptions(rows, component, definition, options) {\n // Temporary workaround - ignore for Yes/No and use defaults in the plugin,\n // until we create a solution that allows users to override the Yes/No options\n if (component.type === ComponentType.YesNoField) {\n return\n }\n\n const list = getListFromComponent(component, definition)\n if (list?.items.length) {\n let itemNum = 0\n for (const item of list.items) {\n itemNum++\n const listOptions = {\n ...options,\n itemNum\n }\n if (item.hint) {\n rows.push(\n createRow(item, TranslationRowTypes.ListItemText, listOptions),\n createRow(item, TranslationRowTypes.ListItemHint, listOptions)\n )\n } else {\n rows.push(\n createRow(item, TranslationRowTypes.ListItemText, listOptions)\n )\n }\n }\n }\n}\n\n/**\n * Build the overview and form translation rows for a form definition.\n * @param {FormMetadata} metadata - The form metadata used to build the overview section.\n * @param {FormDefinition} definition - The form definition containing pages and components.\n * @param {ValidationFailure<any>} [validation] - Optional validation context for posted form values.\n * @returns {{ overviewRows: TranslationRow[], formRows: TranslationRow[] }} The generated overview and form translation rows.\n */\nexport function buildTranslationDataRows(metadata, definition, validation) {\n const translationsJSON = /** @type {Record<string, string>} */ (\n // @ts-expect-error - dynamic language definition\n definition.metadata?.translations?.cy\n )\n\n const overviewRows = buildOverviewSection(\n metadata,\n definition,\n translationsJSON,\n validation\n )\n\n const formRows = []\n for (const page of definition.pages) {\n const pageId = /** @type {string} */ (page.id)\n const pageNum = getPageNum(definition, pageId)\n const components = hasComponentsEvenIfNoNext(page) ? page.components : []\n if (components.length === 0) {\n continue\n }\n\n formRows.push(...buildPage(page, pageNum, translationsJSON, validation))\n\n for (const component of components) {\n if (component.type === ComponentType.Markdown) {\n continue\n }\n const questionId = /** @type {string} */ (component.id)\n const questionNum = getQuestionNum(definition, pageId, questionId)\n\n formRows.push(\n ...buildComponent(\n definition,\n component,\n pageNum,\n questionNum,\n translationsJSON,\n validation\n )\n )\n }\n }\n\n return {\n overviewRows,\n formRows\n }\n}\n\n/**\n * @import { ComponentDef, InputFieldsComponentsDef } from '~/src/components/types.js'\n * @import { FormMetadata } from '~/src/form/form-metadata/types.js'\n * @import { FormDefinition, Item, Page } from '~/src/form/form-definition/types.js'\n * @import { TranslationRow, ValidationFailure } from '~/src/form/form-editor/translations/translations-config.js'\n */\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,UAAU,EAAEC,sBAAsB;AAC3C,SACEC,aAAa,EACbC,mBAAmB,EACnBC,SAAS,EACTC,SAAS,EACTC,iBAAiB;AAEnB,SAASC,oBAAoB;AAC7B,SAASC,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UAAU,GAAG7B,yBAAyB,CAAC0B,IAAI,CAAC,GAAGA,IAAI,CAACG,UAAU,GAAG,EAAE;IACzE,IAAIA,UAAU,CAACqC,MAAM,KAAK,CAAC,EAAE;MAC3B;IACF;IAEAU,QAAQ,CAAC5C,IAAI,CAAC,GAAGP,SAAS,CAACC,IAAI,EAAErB,OAAO,EAAEoE,gBAAgB,EAAEhE,UAAU,CAAC,CAAC;IAExE,KAAK,MAAMqC,SAAS,IAAIjB,UAAU,EAAE;MAClC,IAAIiB,SAAS,CAAC7B,IAAI,KAAK/B,aAAa,CAAC4C,QAAQ,EAAE;QAC7C;MACF;MACA,MAAMiD,UAAU,GAAG,qBAAuBjC,SAAS,CAAC/B,EAAG;MACvD,MAAMT,WAAW,GAAGT,cAAc,CAACgD,UAAU,EAAEiC,MAAM,EAAEC,UAAU,CAAC;MAElEH,QAAQ,CAAC5C,IAAI,CACX,GAAGY,cAAc,CACfC,UAAU,EACVC,SAAS,EACTzC,OAAO,EACPC,WAAW,EACXmE,gBAAgB,EAChBhE,UACF,CACF,CAAC;IACH;EACF;EAEA,OAAO;IACLkE,YAAY;IACZC;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -93,4 +93,36 @@ export function getErrors(validationError) {
|
|
|
93
93
|
};
|
|
94
94
|
}) ?? [];
|
|
95
95
|
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Human-readable messages for each {@link FormDefinitionError} code, shared
|
|
99
|
+
* by services that surface definition-validation failures (designer editor
|
|
100
|
+
* flows, runner preview error pages).
|
|
101
|
+
*/
|
|
102
|
+
export const formErrorsToMessages = {
|
|
103
|
+
[FormDefinitionError.UniquePageId]: 'Each page must have a unique ID. Change the page ID to one that is not already used.',
|
|
104
|
+
[FormDefinitionError.UniquePagePath]: 'Each page must have a unique path. Change the page path to one that is not already used.',
|
|
105
|
+
[FormDefinitionError.UniquePageComponentId]: 'Each question on a page must have a unique ID. Change the question ID to one that is not already used.',
|
|
106
|
+
[FormDefinitionError.UniquePageComponentName]: 'Each question on a page must have a unique name. Change the question name to one that is not already used.',
|
|
107
|
+
[FormDefinitionError.UniqueSectionId]: 'Each section must have a unique ID. Change the section ID to one that is not already used.',
|
|
108
|
+
[FormDefinitionError.UniqueSectionName]: 'Each section must have a unique name. Change the section name to one that is not already used.',
|
|
109
|
+
[FormDefinitionError.UniqueSectionTitle]: 'Each section must have a unique title. Change the section title to one that is not already used.',
|
|
110
|
+
[FormDefinitionError.UniqueListId]: 'Each list must have a unique ID. Change the list ID to one that is not already used.',
|
|
111
|
+
[FormDefinitionError.UniqueListTitle]: 'Each list must have a unique title. Change the list title to one that is not already used.',
|
|
112
|
+
[FormDefinitionError.UniqueListName]: 'Each list must have a unique name. Change the list name to one that is not already used.',
|
|
113
|
+
[FormDefinitionError.UniqueConditionId]: 'Each condition must have a unique ID. Change the condition ID to one that is not already used.',
|
|
114
|
+
[FormDefinitionError.UniqueConditionDisplayName]: 'Each condition must have a unique display name. Change the display name to one that is not already used.',
|
|
115
|
+
[FormDefinitionError.UniqueListItemId]: 'Each item in a list must have a unique ID. Change the item ID to one that is not already used.',
|
|
116
|
+
[FormDefinitionError.UniqueListItemText]: 'Each item in a list must have unique text. Change the item text to one that is not already used.',
|
|
117
|
+
[FormDefinitionError.UniqueListItemValue]: 'Each item in a list must have a unique value. Change the item value to one that is not already used.',
|
|
118
|
+
[FormDefinitionError.RefPageCondition]: 'This page is referenced by a condition. Remove the condition before making changes to this page.',
|
|
119
|
+
[FormDefinitionError.RefConditionComponentId]: 'Remove the condition before deleting this page',
|
|
120
|
+
[FormDefinitionError.RefConditionListId]: 'A condition is using a list in this form. Remove the condition before making changes to the list.',
|
|
121
|
+
[FormDefinitionError.RefConditionItemId]: 'A condition is using an item in this list. Remove the condition before making changes to the item.',
|
|
122
|
+
[FormDefinitionError.RefConditionConditionId]: 'A condition is using another condition. Remove the reference before making changes.',
|
|
123
|
+
[FormDefinitionError.RefPageComponentList]: 'A question on this page is using a list. Remove the reference before making changes to the list.',
|
|
124
|
+
[FormDefinitionError.IncompatibleConditionComponentType]: 'You cannot change to this question type because this question is used in a condition. Remove the condition or select a different question type.',
|
|
125
|
+
[FormDefinitionError.IncompatibleQuestionRegex]: 'The regex expression is invalid',
|
|
126
|
+
[FormDefinitionError.Other]: 'There is a problem with the form definition. Check your changes and try again.'
|
|
127
|
+
};
|
|
96
128
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["FormDefinitionError","FormDefinitionErrorType","formDefinitionErrors","checkErrors","formErrors","possibleErrors","Array","isArray","errors","forEach","err","local","errorType","formError","errorDetails","keyMatch","key","path","type","Unique","code","errorCode","Ref","Incompatible","Type","getErrors","validationError","details","map","detail","context","id","message","pos","dupePos","valueKey","value","label","incompatibleObject","reason","Other"],"sources":["../../../../src/form/form-manager/errors.ts"],"sourcesContent":["import type Joi from 'joi'\nimport { type ValidationError } from 'joi'\n\nimport {\n FormDefinitionError,\n FormDefinitionErrorType,\n formDefinitionErrors,\n type FormDefinitionErrorCause\n} from '~/src/form/form-manager/types.js'\n\n/**\n * Checks and applies an `errorType` and also an `errorCode` for known errors\n */\nexport const checkErrors = (\n formErrors: FormDefinitionError | FormDefinitionError[]\n) => {\n const possibleErrors = Array.isArray(formErrors) ? formErrors : [formErrors]\n\n return function (errors: Joi.ErrorReport[]) {\n errors.forEach((err) => {\n if (err.local.errorType) {\n return\n }\n\n for (const formError of possibleErrors) {\n const errorDetails = formDefinitionErrors[formError]\n\n // Joi's `context.key` will be the index for arrays\n // in which case use the path, otherwise use the key\n const keyMatch =\n typeof err.local.key === 'number' ? err.local.path : err.local.key\n\n if (\n errorDetails.type === FormDefinitionErrorType.Unique &&\n err.code === 'array.unique' &&\n keyMatch === errorDetails.key\n ) {\n err.local.errorCode = formError\n err.local.errorType = FormDefinitionErrorType.Unique\n return\n }\n\n if (\n errorDetails.type === FormDefinitionErrorType.Ref &&\n err.code === 'any.only' &&\n keyMatch === errorDetails.key\n ) {\n err.local.errorCode = formError\n err.local.errorType = FormDefinitionErrorType.Ref\n return\n }\n\n if (\n errorDetails.type === FormDefinitionErrorType.Incompatible &&\n err.code === 'custom.incompatible'\n // Match any key\n ) {\n err.local.errorCode = formError\n err.local.errorType = FormDefinitionErrorType.Incompatible\n return\n }\n\n err.local.errorType = FormDefinitionErrorType.Type\n }\n })\n return errors\n }\n}\n\n/**\n * Get the custom errors from a form definition joi validation error\n */\nexport function getErrors(\n validationError: ValidationError | undefined\n): FormDefinitionErrorCause[] {\n return (\n validationError?.details.map((detail) => {\n if (\n detail.context?.errorType === FormDefinitionErrorType.Unique &&\n detail.context.errorCode\n ) {\n return {\n id: /** @type {FormDefinitionError} */ detail.context.errorCode,\n type: FormDefinitionErrorType.Unique,\n message: detail.message,\n detail: {\n path: detail.path,\n pos: detail.context.pos,\n dupePos: detail.context.dupePos\n }\n }\n }\n\n if (\n detail.context?.errorType === FormDefinitionErrorType.Ref &&\n detail.context.errorCode\n ) {\n return {\n id: /** @type {FormDefinitionError} */ detail.context.errorCode,\n type: FormDefinitionErrorType.Ref,\n message: detail.message,\n detail: {\n path: detail.path\n }\n }\n }\n\n if (\n detail.context?.errorType === FormDefinitionErrorType.Incompatible &&\n detail.context.errorCode\n ) {\n return {\n id: /** @type {FormDefinitionError} */ detail.context.errorCode,\n type: FormDefinitionErrorType.Incompatible,\n message: detail.message,\n detail: {\n path: detail.path,\n key: detail.context.key,\n valueKey: detail.context.valueKey,\n value: detail.context.value,\n label: detail.context.label,\n incompatibleObject: detail.context.incompatibleObject,\n reason: detail.context.reason\n }\n }\n }\n\n // Catch all others\n return {\n id: FormDefinitionError.Other,\n type: FormDefinitionErrorType.Type,\n message: detail.message,\n detail: detail.context\n }\n }) ?? []\n )\n}\n"],"mappings":"AAGA,SACEA,mBAAmB,EACnBC,uBAAuB,EACvBC,oBAAoB;;AAItB;AACA;AACA;AACA,OAAO,MAAMC,W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;MACA,OAAO;QACLU,EAAE,EAAE,kCAAmCF,MAAM,CAACC,OAAO,CAACT,SAAS;QAC/DH,IAAI,EAAEjB,uBAAuB,CAACsB,YAAY;QAC1CS,OAAO,EAAEH,MAAM,CAACG,OAAO;QACvBH,MAAM,EAAE;UACNZ,IAAI,EAAEY,MAAM,CAACZ,IAAI;UACjBD,GAAG,EAAEa,MAAM,CAACC,OAAO,CAACd,GAAG;UACvBmB,QAAQ,EAAEN,MAAM,CAACC,OAAO,CAACK,QAAQ;UACjCC,KAAK,EAAEP,MAAM,CAACC,OAAO,CAACM,KAAK;UAC3BC,KAAK,EAAER,MAAM,CAACC,OAAO,CAACO,KAAK;UAC3BC,kBAAkB,EAAET,MAAM,CAACC,OAAO,CAACQ,kBAAkB;UACrDC,MAAM,EAAEV,MAAM,CAACC,OAAO,CAACS;QACzB;MACF,CAAC;IACH;;IAEA;IACA,OAAO;MACLR,EAAE,EAAE/B,mBAAmB,CAACwC,KAAK;MAC7BtB,IAAI,EAAEjB,uBAAuB,CAACuB,IAAI;MAClCQ,OAAO,EAAEH,MAAM,CAACG,OAAO;MACvBH,MAAM,EAAEA,MAAM,CAACC;IACjB,CAAC;EACH,CAAC,CAAC,IAAI,EAAE;AAEZ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"errors.js","names":["FormDefinitionError","FormDefinitionErrorType","formDefinitionErrors","checkErrors","formErrors","possibleErrors","Array","isArray","errors","forEach","err","local","errorType","formError","errorDetails","keyMatch","key","path","type","Unique","code","errorCode","Ref","Incompatible","Type","getErrors","validationError","details","map","detail","context","id","message","pos","dupePos","valueKey","value","label","incompatibleObject","reason","Other","formErrorsToMessages","UniquePageId","UniquePagePath","UniquePageComponentId","UniquePageComponentName","UniqueSectionId","UniqueSectionName","UniqueSectionTitle","UniqueListId","UniqueListTitle","UniqueListName","UniqueConditionId","UniqueConditionDisplayName","UniqueListItemId","UniqueListItemText","UniqueListItemValue","RefPageCondition","RefConditionComponentId","RefConditionListId","RefConditionItemId","RefConditionConditionId","RefPageComponentList","IncompatibleConditionComponentType","IncompatibleQuestionRegex"],"sources":["../../../../src/form/form-manager/errors.ts"],"sourcesContent":["import type Joi from 'joi'\nimport { type ValidationError } from 'joi'\n\nimport {\n FormDefinitionError,\n FormDefinitionErrorType,\n formDefinitionErrors,\n type FormDefinitionErrorCause\n} from '~/src/form/form-manager/types.js'\n\n/**\n * Checks and applies an `errorType` and also an `errorCode` for known errors\n */\nexport const checkErrors = (\n formErrors: FormDefinitionError | FormDefinitionError[]\n) => {\n const possibleErrors = Array.isArray(formErrors) ? formErrors : [formErrors]\n\n return function (errors: Joi.ErrorReport[]) {\n errors.forEach((err) => {\n if (err.local.errorType) {\n return\n }\n\n for (const formError of possibleErrors) {\n const errorDetails = formDefinitionErrors[formError]\n\n // Joi's `context.key` will be the index for arrays\n // in which case use the path, otherwise use the key\n const keyMatch =\n typeof err.local.key === 'number' ? err.local.path : err.local.key\n\n if (\n errorDetails.type === FormDefinitionErrorType.Unique &&\n err.code === 'array.unique' &&\n keyMatch === errorDetails.key\n ) {\n err.local.errorCode = formError\n err.local.errorType = FormDefinitionErrorType.Unique\n return\n }\n\n if (\n errorDetails.type === FormDefinitionErrorType.Ref &&\n err.code === 'any.only' &&\n keyMatch === errorDetails.key\n ) {\n err.local.errorCode = formError\n err.local.errorType = FormDefinitionErrorType.Ref\n return\n }\n\n if (\n errorDetails.type === FormDefinitionErrorType.Incompatible &&\n err.code === 'custom.incompatible'\n // Match any key\n ) {\n err.local.errorCode = formError\n err.local.errorType = FormDefinitionErrorType.Incompatible\n return\n }\n\n err.local.errorType = FormDefinitionErrorType.Type\n }\n })\n return errors\n }\n}\n\n/**\n * Get the custom errors from a form definition joi validation error\n */\nexport function getErrors(\n validationError: ValidationError | undefined\n): FormDefinitionErrorCause[] {\n return (\n validationError?.details.map((detail) => {\n if (\n detail.context?.errorType === FormDefinitionErrorType.Unique &&\n detail.context.errorCode\n ) {\n return {\n id: /** @type {FormDefinitionError} */ detail.context.errorCode,\n type: FormDefinitionErrorType.Unique,\n message: detail.message,\n detail: {\n path: detail.path,\n pos: detail.context.pos,\n dupePos: detail.context.dupePos\n }\n }\n }\n\n if (\n detail.context?.errorType === FormDefinitionErrorType.Ref &&\n detail.context.errorCode\n ) {\n return {\n id: /** @type {FormDefinitionError} */ detail.context.errorCode,\n type: FormDefinitionErrorType.Ref,\n message: detail.message,\n detail: {\n path: detail.path\n }\n }\n }\n\n if (\n detail.context?.errorType === FormDefinitionErrorType.Incompatible &&\n detail.context.errorCode\n ) {\n return {\n id: /** @type {FormDefinitionError} */ detail.context.errorCode,\n type: FormDefinitionErrorType.Incompatible,\n message: detail.message,\n detail: {\n path: detail.path,\n key: detail.context.key,\n valueKey: detail.context.valueKey,\n value: detail.context.value,\n label: detail.context.label,\n incompatibleObject: detail.context.incompatibleObject,\n reason: detail.context.reason\n }\n }\n }\n\n // Catch all others\n return {\n id: FormDefinitionError.Other,\n type: FormDefinitionErrorType.Type,\n message: detail.message,\n detail: detail.context\n }\n }) ?? []\n )\n}\n\n/**\n * Human-readable messages for each {@link FormDefinitionError} code, shared\n * by services that surface definition-validation failures (designer editor\n * flows, runner preview error pages).\n */\nexport const formErrorsToMessages: Record<FormDefinitionError, string> = {\n [FormDefinitionError.UniquePageId]:\n 'Each page must have a unique ID. Change the page ID to one that is not already used.',\n [FormDefinitionError.UniquePagePath]:\n 'Each page must have a unique path. Change the page path to one that is not already used.',\n [FormDefinitionError.UniquePageComponentId]:\n 'Each question on a page must have a unique ID. Change the question ID to one that is not already used.',\n [FormDefinitionError.UniquePageComponentName]:\n 'Each question on a page must have a unique name. Change the question name to one that is not already used.',\n [FormDefinitionError.UniqueSectionId]:\n 'Each section must have a unique ID. Change the section ID to one that is not already used.',\n [FormDefinitionError.UniqueSectionName]:\n 'Each section must have a unique name. Change the section name to one that is not already used.',\n [FormDefinitionError.UniqueSectionTitle]:\n 'Each section must have a unique title. Change the section title to one that is not already used.',\n [FormDefinitionError.UniqueListId]:\n 'Each list must have a unique ID. Change the list ID to one that is not already used.',\n [FormDefinitionError.UniqueListTitle]:\n 'Each list must have a unique title. Change the list title to one that is not already used.',\n [FormDefinitionError.UniqueListName]:\n 'Each list must have a unique name. Change the list name to one that is not already used.',\n [FormDefinitionError.UniqueConditionId]:\n 'Each condition must have a unique ID. Change the condition ID to one that is not already used.',\n [FormDefinitionError.UniqueConditionDisplayName]:\n 'Each condition must have a unique display name. Change the display name to one that is not already used.',\n [FormDefinitionError.UniqueListItemId]:\n 'Each item in a list must have a unique ID. Change the item ID to one that is not already used.',\n [FormDefinitionError.UniqueListItemText]:\n 'Each item in a list must have unique text. Change the item text to one that is not already used.',\n [FormDefinitionError.UniqueListItemValue]:\n 'Each item in a list must have a unique value. Change the item value to one that is not already used.',\n [FormDefinitionError.RefPageCondition]:\n 'This page is referenced by a condition. Remove the condition before making changes to this page.',\n [FormDefinitionError.RefConditionComponentId]:\n 'Remove the condition before deleting this page',\n [FormDefinitionError.RefConditionListId]:\n 'A condition is using a list in this form. Remove the condition before making changes to the list.',\n [FormDefinitionError.RefConditionItemId]:\n 'A condition is using an item in this list. Remove the condition before making changes to the item.',\n [FormDefinitionError.RefConditionConditionId]:\n 'A condition is using another condition. Remove the reference before making changes.',\n [FormDefinitionError.RefPageComponentList]:\n 'A question on this page is using a list. Remove the reference before making changes to the list.',\n [FormDefinitionError.IncompatibleConditionComponentType]:\n 'You cannot change to this question type because this question is used in a condition. Remove the condition or select a different question type.',\n [FormDefinitionError.IncompatibleQuestionRegex]:\n 'The regex expression is invalid',\n [FormDefinitionError.Other]:\n 'There is a problem with the form definition. Check your changes and try again.'\n}\n"],"mappings":"AAGA,SACEA,mBAAmB,EACnBC,uBAAuB,EACvBC,oBAAoB;;AAItB;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GACtBC,UAAuD,IACpD;EACH,MAAMC,cAAc,GAAGC,KAAK,CAACC,OAAO,CAACH,UAAU,CAAC,GAAGA,UAAU,GAAG,CAACA,UAAU,CAAC;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C5F,CAACnD,mBAAmB,CAACoD,iBAAiB,GACpC,gGAAgG;EAClG,CAACpD,mBAAmB,CAACqD,0BAA0B,GAC7C,0GAA0G;EAC5G,CAACrD,mBAAmB,CAACsD,gBAAgB,GACnC,gGAAgG;EAClG,CAACtD,mBAAmB,CAACuD,kBAAkB,GACrC,kGAAkG;EACpG,CAACvD,mBAAmB,CAACwD,mBAAmB,GACtC,sGAAsG;EACxG,CAACxD,mBAAmB,CAACyD,gBAAgB,GACnC,kGAAkG;EACpG,CAACzD,mBAAmB,CAAC0D,uBAAuB,GAC1C,gDAAgD;EAClD,CAAC1D,mBAAmB,CAAC2D,kBAAkB,GACrC,mGAAmG;EACrG,CAAC3D,mBAAmB,CAAC4D,kBAAkB,GACrC,oGAAoG;EACtG,CAAC5D,mBAAmB,CAAC6D,uBAAuB,GAC1C,qFAAqF;EACvF,CAAC7D,mBAAmB,CAAC8D,oBAAoB,GACvC,kGAAkG;EACpG,CAAC9D,mBAAmB,CAAC+D,kCAAkC,GACrD,iJAAiJ;EACnJ,CAAC/D,mBAAmB,CAACgE,yBAAyB,GAC5C,iCAAiC;EACnC,CAAChE,mBAAmB,CAACwC,KAAK,GACxB;AACJ,CAAC","ignoreList":[]}
|
|
@@ -3,6 +3,7 @@ export const formDefinitionWithoutSummary: import("../index.js").FormDefinition;
|
|
|
3
3
|
export const formDefinitionWithTwoQuestions: import("../index.js").FormDefinition;
|
|
4
4
|
export const formDefinitionWithTwoQuestionsAndGuidance: import("../index.js").FormDefinition;
|
|
5
5
|
export const formDefinitionWithLocationAndDeclaration: import("../index.js").FormDefinition;
|
|
6
|
+
export const formDefinitionWithFormLevelDeclaration: import("../index.js").FormDefinition;
|
|
6
7
|
export const formDefinitionWithRepeater: import("../index.js").FormDefinition;
|
|
7
8
|
export const formDefinitionWithNoQuestions: import("../index.js").FormDefinition;
|
|
8
9
|
export const formDefinitionWithRadioQuestion: import("../index.js").FormDefinition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"examples.d.ts","sourceRoot":"","sources":["../../../src/__stubs__/examples.js"],"names":[],"mappings":"AAcA,gFAmBE;AAEF,gFAgBE;AAEF,kFAyBE;AAEF,6FA0BE;AAEF,4FA8BE;AAEF,8EAoBE;AAEF,iFAYE;AAEF,mFAsDE"}
|
|
1
|
+
{"version":3,"file":"examples.d.ts","sourceRoot":"","sources":["../../../src/__stubs__/examples.js"],"names":[],"mappings":"AAcA,gFAmBE;AAEF,gFAgBE;AAEF,kFAyBE;AAEF,6FA0BE;AAEF,4FA8BE;AAEF,0FAiCE;AAEF,8EAoBE;AAEF,iFAYE;AAEF,mFAsDE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translations-config.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/translations/translations-config.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"translations-config.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/translations/translations-config.js"],"names":[],"mappings":"AAmJA;;;;GAIG;AACH,uCAHW,MAAM,gBACN,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,UAO5C;AAED;;;;;;GAMG;AACH,mCAJW,MAAM,UACN,YAAY,GAAG,IAAI,GAAG,IAAI,cAC1B,MAAM,UA+BhB;;;;;;;;;;;;;;;;AAzJD,8BAA+B,WAAW,CAAA;AAC1C,8BAA+B,WAAW,CAAA;AAC1C,6CAA8C,oBAAoB,CAAA;AAClE,6BAA8B,cAAc,CAAA;AAC5C,4CAA6C,6BAA6B,CAAA;AAE1E,6KAA6K;AAC7K,wBADW,MAAM,CAAC,MAAM,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;CAAE,CAAC,CA0FxK;AAED,4CAKC;;;;;UA7Ia,MAAM;;;;;;;;oBAEN,MAAM,GAAG,SAAS;;;;kBAClB,MAAM,GAAG,SAAS;;;;;;;;;;;;;;;;;;+BAQnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE;2BAC/B,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC;8BAItB,MAAM;;;;gBAEf,YAAY;;;;gBACZ,MAAM;;kCA+Ka,2BAA2B;0BAC7B,qCAAqC;0BAArC,qCAAqC;8BAvMtC,2BAA2B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translations.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/translations/translations.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"translations.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/translations/translations.js"],"names":[],"mappings":"AAuKA;;;;;;;;;GASG;AACH,2CARW,cAAc,aACd,YAAY,WACZ,MAAM,eACN,MAAM,gBACN,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,eACtB,kBAAkB,GAAG,CAAC,GACpB,cAAc,EAAE,CAyD5B;AAuCD;;;;;;GAMG;AACH,mDALW,YAAY,cACZ,cAAc,eACd,kBAAkB,GAAG,CAAC,GACpB;IAAE,YAAY,EAAE,cAAc,EAAE,CAAC;IAAC,QAAQ,EAAE,cAAc,EAAE,CAAA;CAAE,CAkD1E;oCAK8C,qCAAqC;kCAFzB,2BAA2B;uCAGhC,4DAA4D;oCAA5D,4DAA4D;kCAFjF,mCAAmC"}
|
|
@@ -9,4 +9,10 @@ export declare const checkErrors: (formErrors: FormDefinitionError | FormDefinit
|
|
|
9
9
|
* Get the custom errors from a form definition joi validation error
|
|
10
10
|
*/
|
|
11
11
|
export declare function getErrors(validationError: ValidationError | undefined): FormDefinitionErrorCause[];
|
|
12
|
+
/**
|
|
13
|
+
* Human-readable messages for each {@link FormDefinitionError} code, shared
|
|
14
|
+
* by services that surface definition-validation failures (designer editor
|
|
15
|
+
* flows, runner preview error pages).
|
|
16
|
+
*/
|
|
17
|
+
export declare const formErrorsToMessages: Record<FormDefinitionError, string>;
|
|
12
18
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/form/form-manager/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,KAAK,CAAA;AAE1C,OAAO,EACL,mBAAmB,EAGnB,KAAK,wBAAwB,EAC9B,MAAM,kCAAkC,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,YAAY,mBAAmB,GAAG,mBAAmB,EAAE,MAItC,QAAQ,GAAG,CAAC,WAAW,EAAE,sBAiD3C,CAAA;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,eAAe,EAAE,eAAe,GAAG,SAAS,GAC3C,wBAAwB,EAAE,CA8D5B"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/form/form-manager/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,KAAK,CAAA;AAE1C,OAAO,EACL,mBAAmB,EAGnB,KAAK,wBAAwB,EAC9B,MAAM,kCAAkC,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,YAAY,mBAAmB,GAAG,mBAAmB,EAAE,MAItC,QAAQ,GAAG,CAAC,WAAW,EAAE,sBAiD3C,CAAA;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,eAAe,EAAE,eAAe,GAAG,SAAS,GAC3C,wBAAwB,EAAE,CA8D5B;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAiDpE,CAAA"}
|
package/package.json
CHANGED
|
@@ -138,6 +138,41 @@ export const formDefinitionWithLocationAndDeclaration = buildDefinition({
|
|
|
138
138
|
]
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
+
export const formDefinitionWithFormLevelDeclaration = buildDefinition({
|
|
142
|
+
pages: [
|
|
143
|
+
buildQuestionPage({
|
|
144
|
+
id: 'p1',
|
|
145
|
+
section: 'section',
|
|
146
|
+
components: [
|
|
147
|
+
buildTextFieldComponent({
|
|
148
|
+
id: 'q1',
|
|
149
|
+
name: 'textField',
|
|
150
|
+
title: 'This is the first textfield question',
|
|
151
|
+
hint: 'Hint text 1',
|
|
152
|
+
shortDescription: 'Short desc 1'
|
|
153
|
+
}),
|
|
154
|
+
buildTextFieldComponent({
|
|
155
|
+
id: 'q2',
|
|
156
|
+
name: 'textField',
|
|
157
|
+
title: 'This is the second textfield question',
|
|
158
|
+
hint: 'Hint text 2',
|
|
159
|
+
shortDescription: 'Short desc 2'
|
|
160
|
+
})
|
|
161
|
+
],
|
|
162
|
+
next: [{ path: '/summary' }]
|
|
163
|
+
}),
|
|
164
|
+
buildSummaryPage({
|
|
165
|
+
id: 'p2',
|
|
166
|
+
components: [
|
|
167
|
+
buildMarkdownComponent({
|
|
168
|
+
id: 'q10',
|
|
169
|
+
content: 'This is a final declaration for the summary page'
|
|
170
|
+
})
|
|
171
|
+
]
|
|
172
|
+
})
|
|
173
|
+
]
|
|
174
|
+
})
|
|
175
|
+
|
|
141
176
|
export const formDefinitionWithRepeater = buildDefinition({
|
|
142
177
|
pages: [
|
|
143
178
|
buildRepeaterPage({
|
|
@@ -36,6 +36,7 @@ export const TranslationRowTypes = {
|
|
|
36
36
|
ListItemHint: 'ListItemHint',
|
|
37
37
|
InstructionText: 'InstructionText',
|
|
38
38
|
DeclarationBody: 'DeclarationBody',
|
|
39
|
+
EndOfFormDeclarationBody: 'EndOfFormDeclarationBody',
|
|
39
40
|
PaymentDescription: 'PaymentDescription'
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -89,6 +90,13 @@ export const keyConfig = {
|
|
|
89
90
|
getLabel: (pageNum, questionNum) =>
|
|
90
91
|
`Welsh declaration body - Page ${pageNum}, question ${questionNum}`
|
|
91
92
|
},
|
|
93
|
+
[TranslationRowTypes.EndOfFormDeclarationBody]: {
|
|
94
|
+
jsonPrefix: 'components',
|
|
95
|
+
jsonSuffix: 'content',
|
|
96
|
+
displayName: 'Declaration body',
|
|
97
|
+
getLabel: (pageNum, _questionNum) =>
|
|
98
|
+
`Welsh declaration body - Page ${pageNum}`
|
|
99
|
+
},
|
|
92
100
|
[TranslationRowTypes.PaymentDescription]: {
|
|
93
101
|
jsonPrefix: 'components',
|
|
94
102
|
jsonSuffix: 'paymentDescription',
|
|
@@ -11,7 +11,11 @@ import { buildOverviewSection } from '~/src/form/form-editor/translations/transl
|
|
|
11
11
|
import { getListFromComponent } from '~/src/form/utils/list.js'
|
|
12
12
|
import { getPageNum, getQuestionNum } from '~/src/form/utils/numbering.js'
|
|
13
13
|
import { ControllerType } from '~/src/pages/enums.js'
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
hasComponents,
|
|
16
|
+
hasComponentsEvenIfNoNext,
|
|
17
|
+
isSummaryPage
|
|
18
|
+
} from '~/src/pages/helpers.js'
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
21
|
* Create a translation row for a single entity field.
|
|
@@ -49,13 +53,37 @@ function createRow(
|
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Constructs a page row
|
|
58
|
+
* @param {string} rowType
|
|
59
|
+
* @param { string | undefined } id
|
|
60
|
+
* @param {number} pageNum
|
|
61
|
+
* @param {string} englishContent
|
|
62
|
+
* @param {Record<string, string>} translations - Existing Welsh translations keyed by translation name.
|
|
63
|
+
* @param {ValidationFailure<any>} [validation] - Optional validation context for posted form values.
|
|
64
|
+
*/
|
|
65
|
+
function buildPageRow(
|
|
66
|
+
rowType,
|
|
67
|
+
id,
|
|
68
|
+
pageNum,
|
|
69
|
+
englishContent,
|
|
70
|
+
translations,
|
|
71
|
+
validation
|
|
72
|
+
) {
|
|
73
|
+
const keyProperties = keyConfig[rowType]
|
|
74
|
+
const keyName = `${keyProperties.jsonPrefix}.${id}.${keyProperties.jsonSuffix}`
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
name: keyName,
|
|
78
|
+
type: rowType,
|
|
79
|
+
pageNum,
|
|
80
|
+
englishContent,
|
|
81
|
+
welshContent:
|
|
82
|
+
validation?.formValues[keyName] ??
|
|
83
|
+
lookupTranslation(keyName, translations),
|
|
84
|
+
label: keyProperties.getLabel(pageNum)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
59
87
|
|
|
60
88
|
/**
|
|
61
89
|
* Build the translation rows for a single page.
|
|
@@ -66,26 +94,42 @@ const allowedControllerTypesSet = new Set([
|
|
|
66
94
|
* @returns {TranslationRow[]} The translation rows generated for the page.
|
|
67
95
|
*/
|
|
68
96
|
function buildPage(page, pageNum, translations, validation) {
|
|
69
|
-
if (page.controller && !allowedControllerTypesSet.has(page.controller)) {
|
|
70
|
-
return []
|
|
71
|
-
}
|
|
72
|
-
|
|
73
97
|
const translationRows = []
|
|
74
|
-
if (page.title) {
|
|
75
|
-
const keyProperties = keyConfig[TranslationRowTypes.PageHeading]
|
|
76
98
|
|
|
77
|
-
|
|
99
|
+
// The only possible element for translation on a summary page is the end-of-form declaration,
|
|
100
|
+
// so we don't proceed further in this case
|
|
101
|
+
if (isSummaryPage(page)) {
|
|
102
|
+
const endOfFormDeclaration =
|
|
103
|
+
hasComponentsEvenIfNoNext(page) &&
|
|
104
|
+
page.components[0].type === ComponentType.Markdown
|
|
105
|
+
? page.components[0]
|
|
106
|
+
: undefined
|
|
107
|
+
if (endOfFormDeclaration) {
|
|
108
|
+
translationRows.push(
|
|
109
|
+
buildPageRow(
|
|
110
|
+
TranslationRowTypes.EndOfFormDeclarationBody,
|
|
111
|
+
endOfFormDeclaration.id,
|
|
112
|
+
pageNum,
|
|
113
|
+
endOfFormDeclaration.content,
|
|
114
|
+
translations,
|
|
115
|
+
validation
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
return translationRows
|
|
120
|
+
}
|
|
78
121
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
122
|
+
if (page.title) {
|
|
123
|
+
translationRows.push(
|
|
124
|
+
buildPageRow(
|
|
125
|
+
TranslationRowTypes.PageHeading,
|
|
126
|
+
page.id,
|
|
127
|
+
pageNum,
|
|
128
|
+
page.title,
|
|
129
|
+
translations,
|
|
130
|
+
validation
|
|
131
|
+
)
|
|
132
|
+
)
|
|
89
133
|
}
|
|
90
134
|
|
|
91
135
|
const guidance =
|
|
@@ -93,35 +137,29 @@ function buildPage(page, pageNum, translations, validation) {
|
|
|
93
137
|
? page.components[0]
|
|
94
138
|
: undefined
|
|
95
139
|
if (guidance) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
lookupTranslation(keyName, translations),
|
|
107
|
-
label: keyProperties.getLabel(pageNum)
|
|
108
|
-
})
|
|
140
|
+
translationRows.push(
|
|
141
|
+
buildPageRow(
|
|
142
|
+
TranslationRowTypes.PageGuidance,
|
|
143
|
+
guidance.id,
|
|
144
|
+
pageNum,
|
|
145
|
+
guidance.content,
|
|
146
|
+
translations,
|
|
147
|
+
validation
|
|
148
|
+
)
|
|
149
|
+
)
|
|
109
150
|
}
|
|
110
151
|
|
|
111
152
|
if (page.controller === ControllerType.Repeat) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
lookupTranslation(keyName, translations),
|
|
123
|
-
label: keyProperties.getLabel(pageNum)
|
|
124
|
-
})
|
|
153
|
+
translationRows.push(
|
|
154
|
+
buildPageRow(
|
|
155
|
+
TranslationRowTypes.RepeatTitle,
|
|
156
|
+
page.id,
|
|
157
|
+
pageNum,
|
|
158
|
+
page.repeat.options.title,
|
|
159
|
+
translations,
|
|
160
|
+
validation
|
|
161
|
+
)
|
|
162
|
+
)
|
|
125
163
|
}
|
|
126
164
|
|
|
127
165
|
return translationRows
|
|
@@ -255,7 +293,7 @@ export function buildTranslationDataRows(metadata, definition, validation) {
|
|
|
255
293
|
for (const page of definition.pages) {
|
|
256
294
|
const pageId = /** @type {string} */ (page.id)
|
|
257
295
|
const pageNum = getPageNum(definition, pageId)
|
|
258
|
-
const components =
|
|
296
|
+
const components = hasComponentsEvenIfNoNext(page) ? page.components : []
|
|
259
297
|
if (components.length === 0) {
|
|
260
298
|
continue
|
|
261
299
|
}
|
|
@@ -135,3 +135,59 @@ export function getErrors(
|
|
|
135
135
|
}) ?? []
|
|
136
136
|
)
|
|
137
137
|
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Human-readable messages for each {@link FormDefinitionError} code, shared
|
|
141
|
+
* by services that surface definition-validation failures (designer editor
|
|
142
|
+
* flows, runner preview error pages).
|
|
143
|
+
*/
|
|
144
|
+
export const formErrorsToMessages: Record<FormDefinitionError, string> = {
|
|
145
|
+
[FormDefinitionError.UniquePageId]:
|
|
146
|
+
'Each page must have a unique ID. Change the page ID to one that is not already used.',
|
|
147
|
+
[FormDefinitionError.UniquePagePath]:
|
|
148
|
+
'Each page must have a unique path. Change the page path to one that is not already used.',
|
|
149
|
+
[FormDefinitionError.UniquePageComponentId]:
|
|
150
|
+
'Each question on a page must have a unique ID. Change the question ID to one that is not already used.',
|
|
151
|
+
[FormDefinitionError.UniquePageComponentName]:
|
|
152
|
+
'Each question on a page must have a unique name. Change the question name to one that is not already used.',
|
|
153
|
+
[FormDefinitionError.UniqueSectionId]:
|
|
154
|
+
'Each section must have a unique ID. Change the section ID to one that is not already used.',
|
|
155
|
+
[FormDefinitionError.UniqueSectionName]:
|
|
156
|
+
'Each section must have a unique name. Change the section name to one that is not already used.',
|
|
157
|
+
[FormDefinitionError.UniqueSectionTitle]:
|
|
158
|
+
'Each section must have a unique title. Change the section title to one that is not already used.',
|
|
159
|
+
[FormDefinitionError.UniqueListId]:
|
|
160
|
+
'Each list must have a unique ID. Change the list ID to one that is not already used.',
|
|
161
|
+
[FormDefinitionError.UniqueListTitle]:
|
|
162
|
+
'Each list must have a unique title. Change the list title to one that is not already used.',
|
|
163
|
+
[FormDefinitionError.UniqueListName]:
|
|
164
|
+
'Each list must have a unique name. Change the list name to one that is not already used.',
|
|
165
|
+
[FormDefinitionError.UniqueConditionId]:
|
|
166
|
+
'Each condition must have a unique ID. Change the condition ID to one that is not already used.',
|
|
167
|
+
[FormDefinitionError.UniqueConditionDisplayName]:
|
|
168
|
+
'Each condition must have a unique display name. Change the display name to one that is not already used.',
|
|
169
|
+
[FormDefinitionError.UniqueListItemId]:
|
|
170
|
+
'Each item in a list must have a unique ID. Change the item ID to one that is not already used.',
|
|
171
|
+
[FormDefinitionError.UniqueListItemText]:
|
|
172
|
+
'Each item in a list must have unique text. Change the item text to one that is not already used.',
|
|
173
|
+
[FormDefinitionError.UniqueListItemValue]:
|
|
174
|
+
'Each item in a list must have a unique value. Change the item value to one that is not already used.',
|
|
175
|
+
[FormDefinitionError.RefPageCondition]:
|
|
176
|
+
'This page is referenced by a condition. Remove the condition before making changes to this page.',
|
|
177
|
+
[FormDefinitionError.RefConditionComponentId]:
|
|
178
|
+
'Remove the condition before deleting this page',
|
|
179
|
+
[FormDefinitionError.RefConditionListId]:
|
|
180
|
+
'A condition is using a list in this form. Remove the condition before making changes to the list.',
|
|
181
|
+
[FormDefinitionError.RefConditionItemId]:
|
|
182
|
+
'A condition is using an item in this list. Remove the condition before making changes to the item.',
|
|
183
|
+
[FormDefinitionError.RefConditionConditionId]:
|
|
184
|
+
'A condition is using another condition. Remove the reference before making changes.',
|
|
185
|
+
[FormDefinitionError.RefPageComponentList]:
|
|
186
|
+
'A question on this page is using a list. Remove the reference before making changes to the list.',
|
|
187
|
+
[FormDefinitionError.IncompatibleConditionComponentType]:
|
|
188
|
+
'You cannot change to this question type because this question is used in a condition. Remove the condition or select a different question type.',
|
|
189
|
+
[FormDefinitionError.IncompatibleQuestionRegex]:
|
|
190
|
+
'The regex expression is invalid',
|
|
191
|
+
[FormDefinitionError.Other]:
|
|
192
|
+
'There is a problem with the form definition. Check your changes and try again.'
|
|
193
|
+
}
|