@ukhomeoffice/cop-react-form-renderer 2.6.1 → 2.7.1

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.
Files changed (30) hide show
  1. package/dist/components/CheckYourAnswers/Answer.js +3 -1
  2. package/dist/components/CheckYourAnswers/Answer.test.js +3 -2
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +45 -5
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.scss +10 -0
  5. package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +331 -269
  6. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +74 -12
  7. package/dist/components/FormComponent/Container.test.js +89 -10
  8. package/dist/components/FormComponent/FormComponent.js +63 -14
  9. package/dist/components/FormRenderer/FormRenderer.test.js +1 -1
  10. package/dist/components/FormRenderer/helpers/canActionProceed.js +1 -1
  11. package/dist/components/FormRenderer/helpers/canCYASubmit.js +1 -1
  12. package/dist/components/SummaryList/GroupAction.js +68 -0
  13. package/dist/components/SummaryList/GroupAction.test.js +94 -0
  14. package/dist/components/SummaryList/SummaryList.js +15 -4
  15. package/dist/components/SummaryList/SummaryList.scss +29 -5
  16. package/dist/components/SummaryList/SummaryList.test.js +47 -4
  17. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +27 -0
  18. package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +77 -0
  19. package/dist/json/groupOfRow.json +158 -0
  20. package/dist/json/groupOfRowData.json +15 -0
  21. package/dist/models/ComponentTypes.js +2 -0
  22. package/dist/utils/Component/getComponent.js +13 -5
  23. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +81 -0
  24. package/dist/utils/Component/isEditable.js +1 -1
  25. package/dist/utils/Data/index.js +3 -0
  26. package/dist/utils/Data/setDataItem.js +29 -0
  27. package/dist/utils/Data/setDataItem.test.js +112 -0
  28. package/dist/utils/Validate/validatePage.js +7 -6
  29. package/dist/utils/Validate/validatePage.test.js +60 -12
  30. package/package.json +2 -2
@@ -1,269 +1,331 @@
1
- <!-- Global imports -->
2
-
3
- import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
4
- import {
5
- Details,
6
- Heading,
7
- Link,
8
- Tag,
9
- } from '@ukhomeoffice/cop-react-components';
10
- import withMock from 'storybook-addon-mock';
11
-
12
- <!-- Local imports -->
13
-
14
- import Utils from '../../utils';
15
- import CheckYourAnswers from './CheckYourAnswers';
16
-
17
- <!-- JSON documents -->
18
-
19
- import CIVIL_SERVANT from '../../json/areYouACivilServant.json';
20
- import GRADE from '../../json/grade.json';
21
- import TEAMS from '../../json/team.json';
22
- import USER_PROFILE_DATA from '../../json/userProfile.data.json';
23
- import USER_PROFILE from '../../json/userProfile.json';
24
- import FIRST_FORM from '../../json/firstForm.json';
25
-
26
- <Meta
27
- title='Components/Check your answers'
28
- id='D-CheckYourAnswers'
29
- component={CheckYourAnswers}
30
- decorators={[withMock]}
31
- />
32
-
33
- <Heading size='xl' caption='Components'>
34
- Check your answers
35
- </Heading>
36
-
37
- Renders the **Check your answers** screen for a form.
38
-
39
- <Canvas withToolbar>
40
- <Story
41
- name='Default'
42
- parameters={{
43
- mockData: [
44
- {
45
- url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
46
- method: 'GET',
47
- status: 200,
48
- response: CIVIL_SERVANT,
49
- },
50
- {
51
- url: `${USER_PROFILE_DATA.urls.refData}/grade`,
52
- method: 'GET',
53
- status: 200,
54
- response: GRADE,
55
- },
56
- {
57
- url: `${USER_PROFILE_DATA.urls.refData}/team`,
58
- method: 'GET',
59
- status: 200,
60
- response: TEAMS,
61
- },
62
- ],
63
- }}
64
- >
65
- {() => {
66
- const DATA = Utils.Data.setupForm(
67
- USER_PROFILE.pages,
68
- USER_PROFILE.components,
69
- USER_PROFILE_DATA
70
- );
71
- const PAGES = Utils.FormPage.getAll(
72
- USER_PROFILE.pages,
73
- USER_PROFILE.components,
74
- { ...DATA }
75
- );
76
- const ON_ACTION = (action, patch, onError) => {
77
- console.log('action invoked', action, patch);
78
- };
79
- const ON_ROW_ACTION = (page) => {
80
- console.log('row action invoked', page);
81
- };
82
- return (
83
- <CheckYourAnswers
84
- pages={PAGES}
85
- onAction={ON_ACTION}
86
- onRowAction={ON_ROW_ACTION}
87
- />
88
- );
89
- }}
90
- </Story>
91
- </Canvas>
92
-
93
- <Details summary='Properties' className='no-indent'>
94
- <ArgsTable of={CheckYourAnswers} />
95
- </Details>
96
-
97
- ## Variant
98
-
99
- ### Without page titles
100
-
101
- <Canvas>
102
- <Story
103
- name='No page titles'
104
- parameters={{
105
- mockData: [
106
- {
107
- url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
108
- method: 'GET',
109
- status: 200,
110
- response: CIVIL_SERVANT,
111
- },
112
- {
113
- url: `${USER_PROFILE_DATA.urls.refData}/grade`,
114
- method: 'GET',
115
- status: 200,
116
- response: GRADE,
117
- },
118
- {
119
- url: `${USER_PROFILE_DATA.urls.refData}/team`,
120
- method: 'GET',
121
- status: 200,
122
- response: TEAMS,
123
- },
124
- ],
125
- }}
126
- >
127
- {() => {
128
- const DATA = Utils.Data.setupForm(
129
- USER_PROFILE.pages,
130
- USER_PROFILE.components,
131
- USER_PROFILE_DATA
132
- );
133
- const PAGES = Utils.FormPage.getAll(
134
- USER_PROFILE.pages,
135
- USER_PROFILE.components,
136
- { ...DATA }
137
- );
138
- const ON_ACTION = (action, patch, onError) => {
139
- console.log('action invoked', action, patch);
140
- };
141
- const ON_ROW_ACTION = (page) => {
142
- console.log('row action invoked', page);
143
- };
144
- return (
145
- <CheckYourAnswers
146
- pages={PAGES}
147
- hide_page_titles={true}
148
- onAction={ON_ACTION}
149
- onRowAction={ON_ROW_ACTION}
150
- />
151
- );
152
- }}
153
- </Story>
154
- </Canvas>
155
-
156
- ### With actions
157
-
158
- <Canvas>
159
- <Story
160
- name='With actions'
161
- parameters={{
162
- mockData: [
163
- {
164
- url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
165
- method: 'GET',
166
- status: 200,
167
- response: CIVIL_SERVANT,
168
- },
169
- {
170
- url: `${USER_PROFILE_DATA.urls.refData}/grade`,
171
- method: 'GET',
172
- status: 200,
173
- response: GRADE,
174
- },
175
- {
176
- url: `${USER_PROFILE_DATA.urls.refData}/team`,
177
- method: 'GET',
178
- status: 200,
179
- response: TEAMS,
180
- },
181
- ],
182
- }}
183
- >
184
- {() => {
185
- const DATA = { firstName: 'John', surname: 'Smith', age: 41 };
186
- const PAGES = Utils.FormPage.getAll(
187
- FIRST_FORM.pages,
188
- FIRST_FORM.components,
189
- { ...DATA }
190
- );
191
- const ACTIONS = FIRST_FORM.cya.actions;
192
- const ON_ACTION = (action, patch, onError) => {
193
- console.log('action invoked', action, patch);
194
- };
195
- const ON_ROW_ACTION = (page) => {
196
- console.log('row action invoked', page);
197
- };
198
- return (
199
- <CheckYourAnswers
200
- pages={PAGES}
201
- hide_page_titles={true}
202
- actions={ACTIONS}
203
- onAction={ON_ACTION}
204
- onRowAction={ON_ROW_ACTION}
205
- />
206
- );
207
- }}
208
- </Story>
209
- </Canvas>
210
-
211
- ### Read-only style
212
-
213
- <Canvas>
214
- <Story
215
- name='Read-only style'
216
- parameters={{
217
- mockData: [
218
- {
219
- url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
220
- method: 'GET',
221
- status: 200,
222
- response: CIVIL_SERVANT,
223
- },
224
- {
225
- url: `${USER_PROFILE_DATA.urls.refData}/grade`,
226
- method: 'GET',
227
- status: 200,
228
- response: GRADE,
229
- },
230
- {
231
- url: `${USER_PROFILE_DATA.urls.refData}/team`,
232
- method: 'GET',
233
- status: 200,
234
- response: TEAMS,
235
- },
236
- ],
237
- }}
238
- >
239
- {() => {
240
- const DATA = Utils.Data.setupForm(
241
- USER_PROFILE.pages,
242
- USER_PROFILE.components,
243
- USER_PROFILE_DATA
244
- );
245
- const PAGES = Utils.FormPage.getAll(
246
- USER_PROFILE.pages,
247
- USER_PROFILE.components,
248
- { ...DATA }
249
- );
250
- const ON_ACTION = (action, patch, onError) => {
251
- console.log('action invoked', action, patch);
252
- };
253
- const ON_ROW_ACTION = (page) => {
254
- console.log('row action invoked', page);
255
- };
256
- return (
257
- <CheckYourAnswers
258
- pages={PAGES}
259
- hide_page_titles={true}
260
- onAction={ON_ACTION}
261
- onRowAction={ON_ROW_ACTION}
262
- hide_title={true}
263
- summaryListClassModifiers='no-border'
264
- noChangeAction={true}
265
- />
266
- );
267
- }}
268
- </Story>
269
- </Canvas>
1
+ <!-- Global imports -->
2
+
3
+ import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
4
+ import {
5
+ Details,
6
+ Heading,
7
+ Link,
8
+ Tag,
9
+ } from '@ukhomeoffice/cop-react-components';
10
+ import withMock from 'storybook-addon-mock';
11
+
12
+ <!-- Local imports -->
13
+
14
+ import Utils from '../../utils';
15
+ import CheckYourAnswers from './CheckYourAnswers';
16
+
17
+ <!-- JSON documents -->
18
+
19
+ import CIVIL_SERVANT from '../../json/areYouACivilServant.json';
20
+ import GRADE from '../../json/grade.json';
21
+ import TEAMS from '../../json/team.json';
22
+ import USER_PROFILE_DATA from '../../json/userProfile.data.json';
23
+ import USER_PROFILE from '../../json/userProfile.json';
24
+ import FIRST_FORM from '../../json/firstForm.json';
25
+ import GROUP_OF_ROW from '../../json/groupOfRow.json';
26
+ import GROUP_OF_ROW_DATA from '../../json/groupOfRowData.json';
27
+
28
+ <Meta
29
+ title='Components/Check your answers'
30
+ id='D-CheckYourAnswers'
31
+ component={CheckYourAnswers}
32
+ decorators={[withMock]}
33
+ />
34
+
35
+ <Heading size='xl' caption='Components'>
36
+ Check your answers
37
+ </Heading>
38
+
39
+ Renders the **Check your answers** screen for a form.
40
+
41
+ <Canvas withToolbar>
42
+ <Story
43
+ name='Default'
44
+ parameters={{
45
+ mockData: [
46
+ {
47
+ url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
48
+ method: 'GET',
49
+ status: 200,
50
+ response: CIVIL_SERVANT,
51
+ },
52
+ {
53
+ url: `${USER_PROFILE_DATA.urls.refData}/grade`,
54
+ method: 'GET',
55
+ status: 200,
56
+ response: GRADE,
57
+ },
58
+ {
59
+ url: `${USER_PROFILE_DATA.urls.refData}/team`,
60
+ method: 'GET',
61
+ status: 200,
62
+ response: TEAMS,
63
+ },
64
+ ],
65
+ }}
66
+ >
67
+ {() => {
68
+ const DATA = Utils.Data.setupForm(
69
+ USER_PROFILE.pages,
70
+ USER_PROFILE.components,
71
+ USER_PROFILE_DATA
72
+ );
73
+ const PAGES = Utils.FormPage.getAll(
74
+ USER_PROFILE.pages,
75
+ USER_PROFILE.components,
76
+ { ...DATA }
77
+ );
78
+ const ON_ACTION = (action, patch, onError) => {
79
+ console.log('action invoked', action, patch);
80
+ };
81
+ const ON_ROW_ACTION = (page) => {
82
+ console.log('row action invoked', page);
83
+ };
84
+ return (
85
+ <CheckYourAnswers
86
+ pages={PAGES}
87
+ onAction={ON_ACTION}
88
+ onRowAction={ON_ROW_ACTION}
89
+ />
90
+ );
91
+ }}
92
+ </Story>
93
+ </Canvas>
94
+
95
+ <Details summary='Properties' className='no-indent'>
96
+ <ArgsTable of={CheckYourAnswers} />
97
+ </Details>
98
+
99
+ ## Variant
100
+
101
+ ### Without page titles
102
+
103
+ <Canvas>
104
+ <Story
105
+ name='No page titles'
106
+ parameters={{
107
+ mockData: [
108
+ {
109
+ url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
110
+ method: 'GET',
111
+ status: 200,
112
+ response: CIVIL_SERVANT,
113
+ },
114
+ {
115
+ url: `${USER_PROFILE_DATA.urls.refData}/grade`,
116
+ method: 'GET',
117
+ status: 200,
118
+ response: GRADE,
119
+ },
120
+ {
121
+ url: `${USER_PROFILE_DATA.urls.refData}/team`,
122
+ method: 'GET',
123
+ status: 200,
124
+ response: TEAMS,
125
+ },
126
+ ],
127
+ }}
128
+ >
129
+ {() => {
130
+ const DATA = Utils.Data.setupForm(
131
+ USER_PROFILE.pages,
132
+ USER_PROFILE.components,
133
+ USER_PROFILE_DATA
134
+ );
135
+ const PAGES = Utils.FormPage.getAll(
136
+ USER_PROFILE.pages,
137
+ USER_PROFILE.components,
138
+ { ...DATA }
139
+ );
140
+ const ON_ACTION = (action, patch, onError) => {
141
+ console.log('action invoked', action, patch);
142
+ };
143
+ const ON_ROW_ACTION = (page) => {
144
+ console.log('row action invoked', page);
145
+ };
146
+ return (
147
+ <CheckYourAnswers
148
+ pages={PAGES}
149
+ hide_page_titles={true}
150
+ onAction={ON_ACTION}
151
+ onRowAction={ON_ROW_ACTION}
152
+ />
153
+ );
154
+ }}
155
+ </Story>
156
+ </Canvas>
157
+
158
+ ### With actions
159
+
160
+ <Canvas>
161
+ <Story
162
+ name='With actions'
163
+ parameters={{
164
+ mockData: [
165
+ {
166
+ url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
167
+ method: 'GET',
168
+ status: 200,
169
+ response: CIVIL_SERVANT,
170
+ },
171
+ {
172
+ url: `${USER_PROFILE_DATA.urls.refData}/grade`,
173
+ method: 'GET',
174
+ status: 200,
175
+ response: GRADE,
176
+ },
177
+ {
178
+ url: `${USER_PROFILE_DATA.urls.refData}/team`,
179
+ method: 'GET',
180
+ status: 200,
181
+ response: TEAMS,
182
+ },
183
+ ],
184
+ }}
185
+ >
186
+ {() => {
187
+ const DATA = { firstName: 'John', surname: 'Smith', age: 41 };
188
+ const PAGES = Utils.FormPage.getAll(
189
+ FIRST_FORM.pages,
190
+ FIRST_FORM.components,
191
+ { ...DATA }
192
+ );
193
+ const ACTIONS = FIRST_FORM.cya.actions;
194
+ const ON_ACTION = (action, patch, onError) => {
195
+ console.log('action invoked', action, patch);
196
+ };
197
+ const ON_ROW_ACTION = (page) => {
198
+ console.log('row action invoked', page);
199
+ };
200
+ return (
201
+ <CheckYourAnswers
202
+ pages={PAGES}
203
+ hide_page_titles={true}
204
+ actions={ACTIONS}
205
+ onAction={ON_ACTION}
206
+ onRowAction={ON_ROW_ACTION}
207
+ />
208
+ );
209
+ }}
210
+ </Story>
211
+ </Canvas>
212
+
213
+ ### Read-only style
214
+
215
+ <Canvas>
216
+ <Story
217
+ name='Read-only style'
218
+ parameters={{
219
+ mockData: [
220
+ {
221
+ url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
222
+ method: 'GET',
223
+ status: 200,
224
+ response: CIVIL_SERVANT,
225
+ },
226
+ {
227
+ url: `${USER_PROFILE_DATA.urls.refData}/grade`,
228
+ method: 'GET',
229
+ status: 200,
230
+ response: GRADE,
231
+ },
232
+ {
233
+ url: `${USER_PROFILE_DATA.urls.refData}/team`,
234
+ method: 'GET',
235
+ status: 200,
236
+ response: TEAMS,
237
+ },
238
+ ],
239
+ }}
240
+ >
241
+ {() => {
242
+ const DATA = Utils.Data.setupForm(
243
+ USER_PROFILE.pages,
244
+ USER_PROFILE.components,
245
+ USER_PROFILE_DATA
246
+ );
247
+ const PAGES = Utils.FormPage.getAll(
248
+ USER_PROFILE.pages,
249
+ USER_PROFILE.components,
250
+ { ...DATA }
251
+ );
252
+ const ON_ACTION = (action, patch, onError) => {
253
+ console.log('action invoked', action, patch);
254
+ };
255
+ const ON_ROW_ACTION = (page) => {
256
+ console.log('row action invoked', page);
257
+ };
258
+ return (
259
+ <CheckYourAnswers
260
+ pages={PAGES}
261
+ hide_page_titles={true}
262
+ onAction={ON_ACTION}
263
+ onRowAction={ON_ROW_ACTION}
264
+ hide_title={true}
265
+ summaryListClassModifiers='no-border'
266
+ noChangeAction={true}
267
+ />
268
+ );
269
+ }}
270
+ </Story>
271
+ </Canvas>
272
+
273
+
274
+ ### Group of rows
275
+
276
+ <Canvas>
277
+ <Story
278
+ name='Group of rows'
279
+ parameters={{
280
+ mockData: [
281
+ {
282
+ url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
283
+ method: 'GET',
284
+ status: 200,
285
+ response: CIVIL_SERVANT,
286
+ },
287
+ {
288
+ url: `${USER_PROFILE_DATA.urls.refData}/grade`,
289
+ method: 'GET',
290
+ status: 200,
291
+ response: GRADE,
292
+ },
293
+ {
294
+ url: `${USER_PROFILE_DATA.urls.refData}/team`,
295
+ method: 'GET',
296
+ status: 200,
297
+ response: TEAMS,
298
+ },
299
+ ],
300
+ }}
301
+ >
302
+ {() => {
303
+ const DATA = Utils.Data.setupForm(
304
+ GROUP_OF_ROW.pages,
305
+ GROUP_OF_ROW.components,
306
+ GROUP_OF_ROW_DATA
307
+ );
308
+ const PAGES = Utils.FormPage.getAll(
309
+ GROUP_OF_ROW.pages,
310
+ GROUP_OF_ROW.components,
311
+ { ...DATA }
312
+ );
313
+ const CYA = GROUP_OF_ROW.cya;
314
+ const ON_ACTION = (action, patch, onError) => {
315
+ console.log('action invoked', action, patch);
316
+ };
317
+ const ON_ROW_ACTION = (page) => {
318
+ console.log('row action invoked', page);
319
+ };
320
+ return (
321
+ <CheckYourAnswers
322
+ pages={PAGES}
323
+ hide_page_titles={false}
324
+ onAction={ON_ACTION}
325
+ onRowAction={ON_ROW_ACTION}
326
+ groups={CYA.groups}
327
+ />
328
+ );
329
+ }}
330
+ </Story>
331
+ </Canvas>