@defra/forms-model 3.0.462 → 3.0.464
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__/components.js +168 -0
- package/dist/module/__stubs__/components.js.map +1 -0
- package/dist/module/__stubs__/form-definition.js +58 -0
- package/dist/module/__stubs__/form-definition.js.map +1 -0
- package/dist/module/__stubs__/pages.js +107 -0
- package/dist/module/__stubs__/pages.js.map +1 -0
- package/dist/module/conditions/condition-abstract.js +3 -0
- package/dist/module/conditions/condition-abstract.js.map +1 -1
- package/dist/module/conditions/condition-group.js +3 -0
- package/dist/module/conditions/condition-group.js.map +1 -1
- package/dist/module/conditions/condition-model.js +4 -1
- package/dist/module/conditions/condition-model.js.map +1 -1
- package/dist/module/conditions/helpers.js +3 -0
- package/dist/module/conditions/helpers.js.map +1 -1
- package/dist/module/conditions/index.js +1 -1
- package/dist/module/conditions/index.js.map +1 -1
- package/dist/module/conditions/migration.js +13 -7
- package/dist/module/conditions/migration.js.map +1 -1
- package/dist/module/stubs.js +13 -0
- package/dist/module/stubs.js.map +1 -0
- package/dist/types/__stubs__/components.d.ts +43 -0
- package/dist/types/__stubs__/components.d.ts.map +1 -0
- package/dist/types/__stubs__/form-definition.d.ts +15 -0
- package/dist/types/__stubs__/form-definition.d.ts.map +1 -0
- package/dist/types/__stubs__/pages.d.ts +25 -0
- package/dist/types/__stubs__/pages.d.ts.map +1 -0
- package/dist/types/conditions/condition-abstract.d.ts +1 -0
- package/dist/types/conditions/condition-abstract.d.ts.map +1 -1
- package/dist/types/conditions/condition-group.d.ts +1 -0
- package/dist/types/conditions/condition-group.d.ts.map +1 -1
- package/dist/types/conditions/condition-model.d.ts +1 -0
- package/dist/types/conditions/condition-model.d.ts.map +1 -1
- package/dist/types/conditions/helpers.d.ts +9 -5
- package/dist/types/conditions/helpers.d.ts.map +1 -1
- package/dist/types/conditions/index.d.ts +1 -1
- package/dist/types/conditions/index.d.ts.map +1 -1
- package/dist/types/conditions/migration.d.ts +3 -0
- package/dist/types/conditions/migration.d.ts.map +1 -1
- package/dist/types/stubs.d.ts +13 -0
- package/dist/types/stubs.d.ts.map +1 -0
- package/package.json +15 -3
- package/src/__stubs__/components.ts +209 -0
- package/src/__stubs__/form-definition.ts +64 -0
- package/src/__stubs__/pages.ts +118 -0
- package/src/conditions/condition-abstract.ts +6 -0
- package/src/conditions/condition-group.ts +4 -0
- package/src/conditions/condition-model.ts +7 -0
- package/src/conditions/helpers.ts +12 -9
- package/src/conditions/index.ts +6 -1
- package/src/conditions/migration.ts +20 -7
- package/src/stubs.ts +12 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
import { type FormDefinition } from '~/src/form/form-definition/types.js'
|
2
|
+
import { type FormMetadata } from '~/src/form/form-metadata/types.js'
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Builder to create a Form Definition
|
6
|
+
* @param {Partial<FormDefinition>} definitionPartial
|
7
|
+
* @returns {FormDefinition}
|
8
|
+
*/
|
9
|
+
export function buildDefinition(
|
10
|
+
definitionPartial: Partial<FormDefinition> = {}
|
11
|
+
): FormDefinition {
|
12
|
+
const formDefinition: FormDefinition = {
|
13
|
+
name: 'Test form',
|
14
|
+
pages: [],
|
15
|
+
conditions: [],
|
16
|
+
sections: [],
|
17
|
+
lists: []
|
18
|
+
}
|
19
|
+
return {
|
20
|
+
...formDefinition,
|
21
|
+
...definitionPartial
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
/**
|
26
|
+
*
|
27
|
+
* @param {Partial<FormMetadata>} partialMetaData
|
28
|
+
* @returns {FormMetadata}
|
29
|
+
*/
|
30
|
+
export function buildMetaData(
|
31
|
+
partialMetaData: Partial<FormMetadata> = {}
|
32
|
+
): FormMetadata {
|
33
|
+
return {
|
34
|
+
id: '681b184463c68bf6b99e2c62',
|
35
|
+
slug: 'chemistry',
|
36
|
+
title: 'Chemistry',
|
37
|
+
organisation: 'Defra',
|
38
|
+
teamName: 'Forms Team',
|
39
|
+
teamEmail: 'name@example.gov.uk',
|
40
|
+
draft: {
|
41
|
+
createdAt: new Date('2025-05-07T08:22:28.035Z'),
|
42
|
+
createdBy: {
|
43
|
+
id: '84305e4e-1f52-43d0-a123-9c873b0abb35',
|
44
|
+
displayName: 'Internal User'
|
45
|
+
},
|
46
|
+
updatedAt: new Date('2025-05-20T13:00:54.794Z'),
|
47
|
+
updatedBy: {
|
48
|
+
id: '84305e4e-1f52-43d0-a123-9c873b0abb35',
|
49
|
+
displayName: 'Internal User'
|
50
|
+
}
|
51
|
+
},
|
52
|
+
createdBy: {
|
53
|
+
id: '84305e4e-1f52-43d0-a123-9c873b0abb35',
|
54
|
+
displayName: 'Internal User'
|
55
|
+
},
|
56
|
+
createdAt: new Date('2025-05-07T08:22:28.035Z'),
|
57
|
+
updatedBy: {
|
58
|
+
id: '84305e4e-1f52-43d0-a123-9c873b0abb35',
|
59
|
+
displayName: 'Internal User'
|
60
|
+
},
|
61
|
+
updatedAt: new Date('2025-05-20T13:00:54.794Z'),
|
62
|
+
...partialMetaData
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,118 @@
|
|
1
|
+
import { buildFileUploadComponent } from '~/src/__stubs__/components.js'
|
2
|
+
import { ComponentType } from '~/src/components/enums.js'
|
3
|
+
import {
|
4
|
+
type PageFileUpload,
|
5
|
+
type PageQuestion,
|
6
|
+
type PageRepeat,
|
7
|
+
type PageSummary
|
8
|
+
} from '~/src/form/form-definition/types.js'
|
9
|
+
import { ControllerPath, ControllerType } from '~/src/pages/enums.js'
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Stub builder for a question page
|
13
|
+
* @param {Partial<PageQuestion>} [partialPage]
|
14
|
+
* @returns {PageQuestion}
|
15
|
+
*/
|
16
|
+
export function buildQuestionPage(
|
17
|
+
partialPage: Partial<PageQuestion>
|
18
|
+
): PageQuestion {
|
19
|
+
return {
|
20
|
+
id: 'ffefd409-f3f4-49fe-882e-6e89f44631b1',
|
21
|
+
title: 'Page One',
|
22
|
+
path: '/page-one',
|
23
|
+
next: [],
|
24
|
+
components: [],
|
25
|
+
...partialPage
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Stub builder for a Summary page
|
31
|
+
* @param {Partial<PageSummary>} [partialSummaryPage]
|
32
|
+
*/
|
33
|
+
export function buildSummaryPage(
|
34
|
+
partialSummaryPage: Partial<PageSummary> = {}
|
35
|
+
): PageSummary {
|
36
|
+
const pageSummary: PageSummary = {
|
37
|
+
id: '449a45f6-4541-4a46-91bd-8b8931b07b50',
|
38
|
+
title: 'Summary page',
|
39
|
+
path: ControllerPath.Summary,
|
40
|
+
controller: ControllerType.Summary
|
41
|
+
}
|
42
|
+
return { ...pageSummary, ...partialSummaryPage }
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
*
|
47
|
+
* @param {Partial<PageFileUpload>} partialFileUploadPage
|
48
|
+
* @returns {PageFileUpload}
|
49
|
+
*/
|
50
|
+
export function buildFileUploadPage(
|
51
|
+
partialFileUploadPage: Partial<PageFileUpload> = {}
|
52
|
+
): PageFileUpload {
|
53
|
+
const fileUploadPage: PageFileUpload = {
|
54
|
+
id: '85e5c8da-88f5-4009-a821-7d7de1364318',
|
55
|
+
title: '',
|
56
|
+
path: '/supporting-evidence',
|
57
|
+
components: [
|
58
|
+
buildFileUploadComponent({
|
59
|
+
type: ComponentType.FileUploadField,
|
60
|
+
title: 'Supporting Evidence',
|
61
|
+
name: 'yBpZQO',
|
62
|
+
shortDescription: 'Supporting evidence',
|
63
|
+
hint: '',
|
64
|
+
options: {
|
65
|
+
required: true,
|
66
|
+
accept:
|
67
|
+
'application/pdf,application/msword,image/jpeg,application/vnd.ms-excel,text/csv'
|
68
|
+
},
|
69
|
+
id: '4189b8a1-1a04-4f74-a7a0-dd23012a0ee0'
|
70
|
+
})
|
71
|
+
],
|
72
|
+
controller: ControllerType.FileUpload,
|
73
|
+
next: []
|
74
|
+
}
|
75
|
+
|
76
|
+
return {
|
77
|
+
...fileUploadPage,
|
78
|
+
...partialFileUploadPage
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
*
|
84
|
+
* @param {Partial<PageRepeat>} partialRepeaterPage
|
85
|
+
* @returns {PageRepeat}
|
86
|
+
*/
|
87
|
+
export function buildRepeaterPage(
|
88
|
+
partialRepeaterPage: Partial<PageRepeat> = {}
|
89
|
+
): PageRepeat {
|
90
|
+
const repeaterPage: PageRepeat = {
|
91
|
+
title: 'Repeater Page',
|
92
|
+
path: '/repeater-page',
|
93
|
+
components: [
|
94
|
+
{
|
95
|
+
type: ComponentType.TextField,
|
96
|
+
title: 'Simple text field',
|
97
|
+
name: 'IHAIzC',
|
98
|
+
shortDescription: 'Your simple text field',
|
99
|
+
hint: '',
|
100
|
+
options: {},
|
101
|
+
schema: {},
|
102
|
+
id: 'ee83413e-31b6-4158-98e0-4611479582ce'
|
103
|
+
}
|
104
|
+
],
|
105
|
+
next: [],
|
106
|
+
id: '32888028-61db-40fc-b255-80bc67829d31',
|
107
|
+
controller: ControllerType.Repeat,
|
108
|
+
repeat: {
|
109
|
+
options: { name: 'fawfed', title: 'Simple question responses' },
|
110
|
+
schema: { min: 1, max: 3 }
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
return {
|
115
|
+
...repeaterPage,
|
116
|
+
...partialRepeaterPage
|
117
|
+
}
|
118
|
+
}
|
@@ -15,6 +15,12 @@ export class ConditionAbstract {
|
|
15
15
|
return this.coordinator ? `${this.coordinator} ` : ''
|
16
16
|
}
|
17
17
|
|
18
|
+
coordinatorHtml(): string {
|
19
|
+
return this.coordinator
|
20
|
+
? `<span class="govuk-!-font-weight-bold">${this.coordinator.toUpperCase()}</span> `
|
21
|
+
: ''
|
22
|
+
}
|
23
|
+
|
18
24
|
getCoordinator(): Coordinator | undefined {
|
19
25
|
return this.coordinator
|
20
26
|
}
|
@@ -20,6 +20,10 @@ export class ConditionGroup {
|
|
20
20
|
return this.conditions[0].coordinatorString()
|
21
21
|
}
|
22
22
|
|
23
|
+
coordinatorHtml(): string {
|
24
|
+
return this.conditions[0].coordinatorHtml()
|
25
|
+
}
|
26
|
+
|
23
27
|
conditionString(): string {
|
24
28
|
const copy = [...this.conditions]
|
25
29
|
copy.splice(0, 1)
|
@@ -7,6 +7,7 @@ import {
|
|
7
7
|
hasConditionGroup,
|
8
8
|
hasConditionName,
|
9
9
|
toExpression,
|
10
|
+
toPresentationHtml,
|
10
11
|
toPresentationString
|
11
12
|
} from '~/src/conditions/helpers.js'
|
12
13
|
import {
|
@@ -166,6 +167,12 @@ export class ConditionsModel {
|
|
166
167
|
.join(' ')
|
167
168
|
}
|
168
169
|
|
170
|
+
toPresentationHtml() {
|
171
|
+
return this.#groupedConditions
|
172
|
+
.map((condition) => toPresentationHtml(condition))
|
173
|
+
.join(' ')
|
174
|
+
}
|
175
|
+
|
169
176
|
toExpression() {
|
170
177
|
return this.#groupedConditions
|
171
178
|
.map((condition) => toExpression(condition))
|
@@ -8,32 +8,35 @@ import {
|
|
8
8
|
} from '~/src/conditions/types.js'
|
9
9
|
import { type ConditionWrapper } from '~/src/form/form-definition/types.js'
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
type ConditionType = Condition | ConditionRef | ConditionGroup
|
12
|
+
type ConditionDataType = ConditionGroupData | ConditionData | ConditionRefData
|
13
|
+
|
14
|
+
export function toPresentationString(condition: ConditionType) {
|
14
15
|
return `${condition.coordinatorString()}${condition.conditionString()}`
|
15
16
|
}
|
16
17
|
|
17
|
-
export function
|
18
|
-
condition
|
19
|
-
|
18
|
+
export function toPresentationHtml(condition: ConditionType) {
|
19
|
+
return `${condition.coordinatorHtml()}${condition.conditionString()}`
|
20
|
+
}
|
21
|
+
|
22
|
+
export function toExpression(condition: ConditionType) {
|
20
23
|
return `${condition.coordinatorString()}${condition.conditionExpression()}`
|
21
24
|
}
|
22
25
|
|
23
26
|
export const hasConditionField = (
|
24
|
-
condition?:
|
27
|
+
condition?: ConditionDataType
|
25
28
|
): condition is ConditionData => {
|
26
29
|
return !!condition && 'field' in condition
|
27
30
|
}
|
28
31
|
|
29
32
|
export const hasConditionGroup = (
|
30
|
-
condition?:
|
33
|
+
condition?: ConditionDataType
|
31
34
|
): condition is ConditionGroupData => {
|
32
35
|
return !!condition && 'conditions' in condition
|
33
36
|
}
|
34
37
|
|
35
38
|
export const hasConditionName = (
|
36
|
-
condition?:
|
39
|
+
condition?: ConditionDataType
|
37
40
|
): condition is ConditionRefData => {
|
38
41
|
return !!condition && 'conditionName' in condition
|
39
42
|
}
|
package/src/conditions/index.ts
CHANGED
@@ -27,7 +27,12 @@ export {
|
|
27
27
|
toPresentationString
|
28
28
|
} from '~/src/conditions/helpers.js'
|
29
29
|
|
30
|
-
export {
|
30
|
+
export {
|
31
|
+
convertConditionWrapperFromV2,
|
32
|
+
isConditionWrapper,
|
33
|
+
isConditionWrapperV2,
|
34
|
+
type RuntimeFormModel
|
35
|
+
} from '~/src/conditions/migration.js'
|
31
36
|
|
32
37
|
export {
|
33
38
|
ConditionType,
|
@@ -72,7 +72,7 @@ function createConditionValueDataFromStringValueDataV2(
|
|
72
72
|
return {
|
73
73
|
type: ConditionType.Value,
|
74
74
|
value: value.value,
|
75
|
-
display:
|
75
|
+
display: value.value
|
76
76
|
}
|
77
77
|
}
|
78
78
|
|
@@ -119,19 +119,31 @@ function convertConditionRefDataFromV2(
|
|
119
119
|
condition: ConditionRefDataV2,
|
120
120
|
coordinator: Coordinator | undefined
|
121
121
|
): ConditionRefData {
|
122
|
-
const
|
122
|
+
const refCondition = model.getConditionById(condition.conditionId)
|
123
123
|
|
124
|
-
if (!
|
124
|
+
if (!refCondition) {
|
125
125
|
throw Error('Component not found')
|
126
126
|
}
|
127
127
|
|
128
128
|
return {
|
129
|
-
conditionName:
|
130
|
-
conditionDisplayName:
|
129
|
+
conditionName: refCondition.name,
|
130
|
+
conditionDisplayName: refCondition.displayName,
|
131
131
|
coordinator
|
132
132
|
}
|
133
133
|
}
|
134
134
|
|
135
|
+
export function isConditionWrapperV2(
|
136
|
+
wrapper: ConditionWrapper | ConditionWrapperV2
|
137
|
+
): wrapper is ConditionWrapperV2 {
|
138
|
+
return Array.isArray((wrapper as ConditionWrapperV2).conditions)
|
139
|
+
}
|
140
|
+
|
141
|
+
export function isConditionWrapper(
|
142
|
+
wrapper: ConditionWrapper | ConditionWrapperV2
|
143
|
+
): wrapper is ConditionWrapper {
|
144
|
+
return !isConditionWrapperV2(wrapper)
|
145
|
+
}
|
146
|
+
|
135
147
|
export function convertConditionWrapperFromV2(
|
136
148
|
conditionWrapper: ConditionWrapperV2,
|
137
149
|
model: RuntimeFormModel
|
@@ -149,7 +161,7 @@ export function convertConditionWrapperFromV2(
|
|
149
161
|
displayName: conditionWrapper.displayName,
|
150
162
|
value: {
|
151
163
|
name: conditionWrapper.name,
|
152
|
-
conditions: conditionWrapper.conditions.map((condition) => {
|
164
|
+
conditions: conditionWrapper.conditions.map((condition, index) => {
|
153
165
|
let newCondition: ConditionData | ConditionRefData
|
154
166
|
|
155
167
|
if (isConditionDataV2(condition)) {
|
@@ -158,7 +170,7 @@ export function convertConditionWrapperFromV2(
|
|
158
170
|
newCondition = convertConditionRefDataFromV2(
|
159
171
|
model,
|
160
172
|
condition,
|
161
|
-
coordinator
|
173
|
+
index > 0 ? coordinator : undefined
|
162
174
|
)
|
163
175
|
}
|
164
176
|
|
@@ -173,4 +185,5 @@ export function convertConditionWrapperFromV2(
|
|
173
185
|
export interface RuntimeFormModel {
|
174
186
|
getListById: (listId: string) => List | undefined
|
175
187
|
getComponentById: (componentId: string) => ComponentDef | undefined
|
188
|
+
getConditionById: (conditionId: string) => ConditionWrapperV2 | undefined
|
176
189
|
}
|
package/src/stubs.ts
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
export * from '~/src/__stubs__/form-definition.js'
|
2
|
+
export { buildList } from '~/src/__stubs__/components.js'
|
3
|
+
export { buildListItem } from '~/src/__stubs__/components.js'
|
4
|
+
export { buildCheckboxComponent } from '~/src/__stubs__/components.js'
|
5
|
+
export { buildRadioComponent } from '~/src/__stubs__/components.js'
|
6
|
+
export { buildAutoCompleteComponent } from '~/src/__stubs__/components.js'
|
7
|
+
export { buildFileUploadComponent } from '~/src/__stubs__/components.js'
|
8
|
+
export { buildTextFieldComponent } from '~/src/__stubs__/components.js'
|
9
|
+
export { buildRepeaterPage } from '~/src/__stubs__/pages.js'
|
10
|
+
export { buildFileUploadPage } from '~/src/__stubs__/pages.js'
|
11
|
+
export { buildSummaryPage } from '~/src/__stubs__/pages.js'
|
12
|
+
export { buildQuestionPage } from '~/src/__stubs__/pages.js'
|