@ukhomeoffice/cop-react-form-renderer 1.0.0-gamma → 2.1.0
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/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +16 -5
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +199 -79
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +44 -0
- package/dist/components/FormPage/FormPage.js +8 -2
- package/dist/components/FormPage/FormPage.test.js +3 -3
- package/dist/components/FormRenderer/FormRenderer.js +44 -16
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +115 -49
- package/dist/components/FormRenderer/FormRenderer.test.js +40 -0
- package/dist/components/FormRenderer/handlers/getPageId.js +1 -10
- package/dist/components/FormRenderer/handlers/getPageId.test.js +5 -31
- package/dist/components/FormRenderer/handlers/handlers.test.js +2 -2
- package/dist/components/FormRenderer/helpers/getNextPageId.js +33 -26
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +89 -7
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +27 -0
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +209 -0
- package/dist/components/FormRenderer/helpers/index.js +4 -1
- package/dist/components/PageActions/ActionButton.test.js +1 -1
- package/dist/components/PageActions/PageActions.stories.mdx +1 -1
- package/dist/components/PageActions/PageActions.test.js +5 -5
- package/dist/components/SummaryList/RowAction.js +1 -1
- package/dist/components/SummaryList/RowAction.test.js +6 -6
- package/dist/components/SummaryList/SummaryList.js +8 -5
- package/dist/components/SummaryList/SummaryList.scss +10 -2
- package/dist/components/SummaryList/SummaryList.stories.mdx +64 -10
- package/dist/components/SummaryList/SummaryList.test.js +54 -0
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -2
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +4 -4
- package/dist/components/index.js +8 -0
- package/dist/index.js +8 -0
- package/dist/json/areYouACivilServant.json +7 -0
- package/dist/json/firstForm.json +94 -0
- package/dist/json/grade.json +108 -0
- package/dist/json/saveAndContinue.json +98 -0
- package/dist/json/team.json +17351 -0
- package/dist/json/userProfile.data.json +14 -0
- package/dist/json/userProfile.json +276 -0
- package/dist/models/ComponentTypes.js +7 -1
- package/dist/models/PageAction.js +9 -7
- package/dist/utils/CheckYourAnswers/getCYAAction.js +24 -3
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +62 -15
- package/dist/utils/CheckYourAnswers/getCYARow.js +8 -2
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -5
- package/dist/utils/Component/getComponent.js +32 -0
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +75 -0
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +129 -0
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +129 -0
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +80 -0
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +33 -0
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +45 -0
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +31 -0
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +80 -0
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +125 -0
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +80 -0
- package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +76 -0
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +14 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/Data/refDataToOptions.js +4 -0
- package/dist/utils/Data/refDataToOptions.test.js +30 -0
- package/dist/utils/FormPage/getEditableComponents.js +28 -0
- package/dist/utils/FormPage/getEditableComponents.test.js +75 -0
- package/dist/utils/FormPage/getFormPage.js +5 -1
- package/dist/utils/FormPage/getPageActions.js +66 -0
- package/dist/utils/FormPage/getPageActions.test.js +89 -0
- package/dist/utils/FormPage/index.js +7 -1
- package/dist/utils/FormPage/showFormPage.js +81 -0
- package/dist/utils/FormPage/showFormPage.test.js +131 -0
- package/dist/utils/Validate/validateComponent.js +5 -3
- package/dist/utils/Validate/validateRequired.js +11 -0
- package/dist/utils/Validate/validateRequired.test.js +12 -0
- package/package.json +15 -10
- package/dist/index.test.js +0 -18
- package/dist/utils/Component/getComponent.test.js +0 -329
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -36,3 +36,15 @@ Runs Storybook on [http://localhost:6007](http://localhost:6007), which showcase
|
|
|
36
36
|
### `yarn storybook:build`
|
|
37
37
|
|
|
38
38
|
Builds Storybook for production to the `storybook-static` folder.
|
|
39
|
+
|
|
40
|
+
# Using the Service
|
|
41
|
+
## Versioning
|
|
42
|
+
For versioning this project uses SemVer.
|
|
43
|
+
|
|
44
|
+
## Authors
|
|
45
|
+
This project is authored by the Home Office.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
This project is licensed under the MIT license. For details please see [License](./LICENSE).
|
|
49
|
+
|
|
50
|
+
This project contains public sector information licensed under the Open Government Licence v3.0. (http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/)
|
|
@@ -61,7 +61,10 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
61
61
|
_onAction = _ref.onAction,
|
|
62
62
|
onRowAction = _ref.onRowAction,
|
|
63
63
|
hide_page_titles = _ref.hide_page_titles,
|
|
64
|
-
hide_actions = _ref.hide_actions
|
|
64
|
+
hide_actions = _ref.hide_actions,
|
|
65
|
+
hide_title = _ref.hide_title,
|
|
66
|
+
summaryListClassModifiers = _ref.summaryListClassModifiers,
|
|
67
|
+
noChangeAction = _ref.noChangeAction;
|
|
65
68
|
|
|
66
69
|
var _useState = (0, _react.useState)([]),
|
|
67
70
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -109,7 +112,7 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
109
112
|
|
|
110
113
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
111
114
|
className: DEFAULT_CLASS
|
|
112
|
-
}, title && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, {
|
|
115
|
+
}, title && !hide_title && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, {
|
|
113
116
|
key: "heading"
|
|
114
117
|
}, title), errors && errors.length > 0 && /*#__PURE__*/_react.default.createElement(_copReactComponents.ErrorSummary, {
|
|
115
118
|
errors: errors
|
|
@@ -120,7 +123,9 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
120
123
|
key: pageIndex
|
|
121
124
|
}, !hide_page_titles && page.title && /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, page.title), /*#__PURE__*/_react.default.createElement(_SummaryList.default, {
|
|
122
125
|
className: className,
|
|
123
|
-
rows: page.rows
|
|
126
|
+
rows: page.rows,
|
|
127
|
+
classModifiers: summaryListClassModifiers,
|
|
128
|
+
noChangeAction: noChangeAction
|
|
124
129
|
}));
|
|
125
130
|
}), !hide_actions && /*#__PURE__*/_react.default.createElement(_PageActions.default, {
|
|
126
131
|
actions: actions,
|
|
@@ -137,12 +142,18 @@ CheckYourAnswers.propTypes = {
|
|
|
137
142
|
onAction: _propTypes.default.func.isRequired,
|
|
138
143
|
onRowAction: _propTypes.default.func.isRequired,
|
|
139
144
|
hide_page_titles: _propTypes.default.bool,
|
|
140
|
-
hide_actions: _propTypes.default.bool
|
|
145
|
+
hide_actions: _propTypes.default.bool,
|
|
146
|
+
hide_title: _propTypes.default.bool,
|
|
147
|
+
summaryListClassModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
148
|
+
noChangeAction: _propTypes.default.bool
|
|
141
149
|
};
|
|
142
150
|
CheckYourAnswers.defaultProps = {
|
|
143
151
|
title: DEFAULT_TITLE,
|
|
144
152
|
hide_page_titles: false,
|
|
145
|
-
hide_actions: false
|
|
153
|
+
hide_actions: false,
|
|
154
|
+
hide_title: false,
|
|
155
|
+
summaryListClassModifiers: null,
|
|
156
|
+
noChangeAction: false
|
|
146
157
|
};
|
|
147
158
|
var _default = CheckYourAnswers;
|
|
148
159
|
exports.default = _default;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
<!-- Global imports -->
|
|
2
|
+
|
|
2
3
|
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Details,
|
|
6
|
+
Heading,
|
|
7
|
+
Link,
|
|
8
|
+
Tag,
|
|
9
|
+
} from '@ukhomeoffice/cop-react-components';
|
|
4
10
|
import withMock from 'storybook-addon-mock';
|
|
5
11
|
|
|
6
12
|
<!-- Local imports -->
|
|
13
|
+
|
|
7
14
|
import Utils from '../../utils';
|
|
8
15
|
import CheckYourAnswers from './CheckYourAnswers';
|
|
9
16
|
|
|
10
17
|
<!-- JSON documents -->
|
|
18
|
+
|
|
11
19
|
import CIVIL_SERVANT from '../../json/areYouACivilServant.json';
|
|
12
20
|
import GRADE from '../../json/grade.json';
|
|
13
21
|
import TEAMS from '../../json/team.json';
|
|
@@ -15,38 +23,56 @@ import USER_PROFILE_DATA from '../../json/userProfile.data.json';
|
|
|
15
23
|
import USER_PROFILE from '../../json/userProfile.json';
|
|
16
24
|
import FIRST_FORM from '../../json/firstForm.json';
|
|
17
25
|
|
|
18
|
-
<Meta
|
|
26
|
+
<Meta
|
|
27
|
+
title='Components/Check your answers'
|
|
28
|
+
id='D-CheckYourAnswers'
|
|
29
|
+
component={CheckYourAnswers}
|
|
30
|
+
decorators={[withMock]}
|
|
31
|
+
/>
|
|
19
32
|
|
|
20
|
-
<Heading size=
|
|
33
|
+
<Heading size='xl' caption='Components'>
|
|
34
|
+
Check your answers
|
|
35
|
+
</Heading>
|
|
21
36
|
|
|
22
37
|
Renders the **Check your answers** screen for a form.
|
|
23
38
|
|
|
24
39
|
<Canvas withToolbar>
|
|
25
|
-
<Story
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
>
|
|
47
65
|
{() => {
|
|
48
|
-
const DATA = Utils.Data.setupForm(
|
|
49
|
-
|
|
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
|
+
);
|
|
50
76
|
const ON_ACTION = (action, patch, onError) => {
|
|
51
77
|
console.log('action invoked', action, patch);
|
|
52
78
|
};
|
|
@@ -54,45 +80,61 @@ Renders the **Check your answers** screen for a form.
|
|
|
54
80
|
console.log('row action invoked', page);
|
|
55
81
|
};
|
|
56
82
|
return (
|
|
57
|
-
<CheckYourAnswers
|
|
83
|
+
<CheckYourAnswers
|
|
84
|
+
pages={PAGES}
|
|
85
|
+
onAction={ON_ACTION}
|
|
86
|
+
onRowAction={ON_ROW_ACTION}
|
|
87
|
+
/>
|
|
58
88
|
);
|
|
59
89
|
}}
|
|
60
90
|
</Story>
|
|
61
91
|
</Canvas>
|
|
62
92
|
|
|
63
|
-
<Details summary=
|
|
64
|
-
<ArgsTable of={
|
|
93
|
+
<Details summary='Properties' className='no-indent'>
|
|
94
|
+
<ArgsTable of={CheckYourAnswers} />
|
|
65
95
|
</Details>
|
|
66
96
|
|
|
67
97
|
## Variant
|
|
98
|
+
|
|
68
99
|
### Without page titles
|
|
69
100
|
|
|
70
101
|
<Canvas>
|
|
71
|
-
<Story
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
+
>
|
|
93
127
|
{() => {
|
|
94
|
-
const DATA = Utils.Data.setupForm(
|
|
95
|
-
|
|
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
|
+
);
|
|
96
138
|
const ON_ACTION = (action, patch, onError) => {
|
|
97
139
|
console.log('action invoked', action, patch);
|
|
98
140
|
};
|
|
@@ -100,7 +142,12 @@ Renders the **Check your answers** screen for a form.
|
|
|
100
142
|
console.log('row action invoked', page);
|
|
101
143
|
};
|
|
102
144
|
return (
|
|
103
|
-
<CheckYourAnswers
|
|
145
|
+
<CheckYourAnswers
|
|
146
|
+
pages={PAGES}
|
|
147
|
+
hide_page_titles={true}
|
|
148
|
+
onAction={ON_ACTION}
|
|
149
|
+
onRowAction={ON_ROW_ACTION}
|
|
150
|
+
/>
|
|
104
151
|
);
|
|
105
152
|
}}
|
|
106
153
|
</Story>
|
|
@@ -109,31 +156,38 @@ Renders the **Check your answers** screen for a form.
|
|
|
109
156
|
### With actions
|
|
110
157
|
|
|
111
158
|
<Canvas>
|
|
112
|
-
<Story
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
+
>
|
|
134
184
|
{() => {
|
|
135
185
|
const DATA = { firstName: 'John', surname: 'Smith', age: 41 };
|
|
136
|
-
const PAGES = Utils.FormPage.getAll(
|
|
186
|
+
const PAGES = Utils.FormPage.getAll(
|
|
187
|
+
FIRST_FORM.pages,
|
|
188
|
+
FIRST_FORM.components,
|
|
189
|
+
{ ...DATA }
|
|
190
|
+
);
|
|
137
191
|
const ACTIONS = FIRST_FORM.cya.actions;
|
|
138
192
|
const ON_ACTION = (action, patch, onError) => {
|
|
139
193
|
console.log('action invoked', action, patch);
|
|
@@ -142,7 +196,73 @@ Renders the **Check your answers** screen for a form.
|
|
|
142
196
|
console.log('row action invoked', page);
|
|
143
197
|
};
|
|
144
198
|
return (
|
|
145
|
-
<CheckYourAnswers
|
|
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
|
+
/>
|
|
146
266
|
);
|
|
147
267
|
}}
|
|
148
268
|
</Story>
|
|
@@ -328,5 +328,49 @@ describe('components', function () {
|
|
|
328
328
|
}
|
|
329
329
|
}, _callee10);
|
|
330
330
|
})));
|
|
331
|
+
it('should show no title if is set to hidden', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
|
|
332
|
+
var cya, _cya$childNodes4, names, _names$childNodes2, firstName, surname;
|
|
333
|
+
|
|
334
|
+
return regeneratorRuntime.wrap(function _callee12$(_context12) {
|
|
335
|
+
while (1) {
|
|
336
|
+
switch (_context12.prev = _context12.next) {
|
|
337
|
+
case 0:
|
|
338
|
+
_context12.next = 2;
|
|
339
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() {
|
|
340
|
+
return regeneratorRuntime.wrap(function _callee11$(_context11) {
|
|
341
|
+
while (1) {
|
|
342
|
+
switch (_context11.prev = _context11.next) {
|
|
343
|
+
case 0:
|
|
344
|
+
(0, _reactDom.render)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
345
|
+
pages: PAGES,
|
|
346
|
+
onRowAction: ON_ROW_ACTION,
|
|
347
|
+
onAction: ON_ACTION,
|
|
348
|
+
hide_title: true
|
|
349
|
+
}), container);
|
|
350
|
+
|
|
351
|
+
case 1:
|
|
352
|
+
case "end":
|
|
353
|
+
return _context11.stop();
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}, _callee11);
|
|
357
|
+
})));
|
|
358
|
+
|
|
359
|
+
case 2:
|
|
360
|
+
cya = checkCYA(container);
|
|
361
|
+
_cya$childNodes4 = _slicedToArray(cya.childNodes, 1), names = _cya$childNodes4[0];
|
|
362
|
+
expect(names.tagName).toEqual('DL');
|
|
363
|
+
expect(names.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
|
|
364
|
+
_names$childNodes2 = _slicedToArray(names.childNodes, 2), firstName = _names$childNodes2[0], surname = _names$childNodes2[1];
|
|
365
|
+
checkRow(firstName, 'First name', 'John', false);
|
|
366
|
+
checkRow(surname, 'Last name', 'Smith', false);
|
|
367
|
+
|
|
368
|
+
case 9:
|
|
369
|
+
case "end":
|
|
370
|
+
return _context12.stop();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}, _callee12);
|
|
374
|
+
})));
|
|
331
375
|
});
|
|
332
376
|
});
|
|
@@ -79,6 +79,10 @@ var FormPage = function FormPage(_ref) {
|
|
|
79
79
|
});
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
var onError = function onError(errors) {
|
|
83
|
+
setErrors(errors);
|
|
84
|
+
};
|
|
85
|
+
|
|
82
86
|
var classes = _utils.default.classBuilder(classBlock, classModifiers, className);
|
|
83
87
|
|
|
84
88
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -86,7 +90,9 @@ var FormPage = function FormPage(_ref) {
|
|
|
86
90
|
key: page.id
|
|
87
91
|
}, page.title && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, page.title), errors && errors.length > 0 && /*#__PURE__*/_react.default.createElement(_copReactComponents.ErrorSummary, {
|
|
88
92
|
errors: errors
|
|
89
|
-
}), page.components.
|
|
93
|
+
}), page.components.filter(function (c) {
|
|
94
|
+
return _utils.default.Component.show(c, page.formData);
|
|
95
|
+
}).map(function (component, index) {
|
|
90
96
|
return /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
91
97
|
key: index,
|
|
92
98
|
component: component,
|
|
@@ -96,7 +102,7 @@ var FormPage = function FormPage(_ref) {
|
|
|
96
102
|
}), /*#__PURE__*/_react.default.createElement(_PageActions.default, {
|
|
97
103
|
actions: page.actions,
|
|
98
104
|
onAction: function onAction(action) {
|
|
99
|
-
return _onAction(action, patch,
|
|
105
|
+
return _onAction(action, patch, onError);
|
|
100
106
|
}
|
|
101
107
|
}));
|
|
102
108
|
};
|
|
@@ -36,7 +36,7 @@ describe('components', function () {
|
|
|
36
36
|
id: 'pageId',
|
|
37
37
|
title: 'Page 1',
|
|
38
38
|
components: [TEXT],
|
|
39
|
-
actions: [
|
|
39
|
+
actions: [_models.PageAction.TYPES.SUBMIT],
|
|
40
40
|
formData: {
|
|
41
41
|
text: VALUE
|
|
42
42
|
}
|
|
@@ -93,10 +93,10 @@ describe('components', function () {
|
|
|
93
93
|
expect(input.value).toEqual(VALUE);
|
|
94
94
|
buttonGroup = page.childNodes[2];
|
|
95
95
|
expect(buttonGroup.tagName).toEqual('DIV');
|
|
96
|
-
expect(buttonGroup.classList).toContain('
|
|
96
|
+
expect(buttonGroup.classList).toContain('hods-button-group');
|
|
97
97
|
button = buttonGroup.childNodes[0];
|
|
98
98
|
expect(button.tagName).toEqual('BUTTON');
|
|
99
|
-
expect(button.classList).toContain('
|
|
99
|
+
expect(button.classList).toContain('hods-button');
|
|
100
100
|
expect(button.textContent).toEqual(_ActionButton.DEFAULT_LABEL);
|
|
101
101
|
|
|
102
102
|
case 31:
|
|
@@ -69,7 +69,10 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
69
69
|
_hooks = _ref.hooks,
|
|
70
70
|
classBlock = _ref.classBlock,
|
|
71
71
|
classModifiers = _ref.classModifiers,
|
|
72
|
-
className = _ref.className
|
|
72
|
+
className = _ref.className,
|
|
73
|
+
hide_title = _ref.hide_title,
|
|
74
|
+
summaryListClassModifiers = _ref.summaryListClassModifiers,
|
|
75
|
+
noChangeAction = _ref.noChangeAction;
|
|
73
76
|
|
|
74
77
|
// Set up the initial states.
|
|
75
78
|
var _useState = (0, _react.useState)({}),
|
|
@@ -111,12 +114,26 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
111
114
|
}, [_hooks, addHook]); // Setup data.
|
|
112
115
|
|
|
113
116
|
(0, _react.useEffect)(function () {
|
|
114
|
-
|
|
117
|
+
if (components && _pages && _data) {
|
|
118
|
+
var _data$formStatus;
|
|
119
|
+
|
|
120
|
+
setData(_utils.default.Data.setupForm(_pages, components, _data));
|
|
121
|
+
|
|
122
|
+
if ((_data$formStatus = _data.formStatus) !== null && _data$formStatus !== void 0 && _data$formStatus.page) {
|
|
123
|
+
setPageId(_data.formStatus.page);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
115
126
|
}, [components, _pages, _data, setData]); // Setup pages.
|
|
116
127
|
|
|
117
128
|
(0, _react.useEffect)(function () {
|
|
118
129
|
setPages(_utils.default.FormPage.getAll(_pages, components, _objectSpread({}, data)));
|
|
119
|
-
}, [components, _pages, data, setPages]); // Setup
|
|
130
|
+
}, [components, _pages, data, setPages]); // Setup initial pageId.
|
|
131
|
+
|
|
132
|
+
(0, _react.useEffect)(function () {
|
|
133
|
+
setPageId(function (prev) {
|
|
134
|
+
return prev || _helpers.default.getNextPageId(type, pages);
|
|
135
|
+
});
|
|
136
|
+
}, [type, pages, setPageId]); // Setup hub.
|
|
120
137
|
|
|
121
138
|
(0, _react.useEffect)(function () {
|
|
122
139
|
setHub(_utils.default.Hub.get(type, _hub, components, _objectSpread({}, data)));
|
|
@@ -140,15 +157,17 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
140
157
|
// Check to see whether the action is able to proceed, which in
|
|
141
158
|
// in the case of a submission will validate the fields in the page.
|
|
142
159
|
if (_helpers.default.canActionProceed(action, formState.page, onError)) {
|
|
143
|
-
if (action.type ===
|
|
160
|
+
if (action.type === _models.PageAction.TYPES.NAVIGATE) {
|
|
144
161
|
_handlers.default.navigate(action, pageId, onPageChange);
|
|
145
162
|
} else {
|
|
146
|
-
//
|
|
163
|
+
// Save draft or submit.
|
|
147
164
|
var submissionData = _utils.default.Format.form({
|
|
148
165
|
pages: pages,
|
|
149
166
|
components: components
|
|
150
167
|
}, _objectSpread(_objectSpread({}, data), patch), _models.EventTypes.SUBMIT);
|
|
151
168
|
|
|
169
|
+
submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, submissionData);
|
|
170
|
+
|
|
152
171
|
if (patch) {
|
|
153
172
|
setData(submissionData);
|
|
154
173
|
} // Now submit the data to the backend...
|
|
@@ -157,12 +176,11 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
157
176
|
hooks.onSubmit(action.type, submissionData, function (response) {
|
|
158
177
|
// The backend response may well contain data we need so apply it.
|
|
159
178
|
setData(function (prev) {
|
|
160
|
-
|
|
161
|
-
});
|
|
179
|
+
var next = _objectSpread(_objectSpread({}, prev), response);
|
|
162
180
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
181
|
+
onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, next));
|
|
182
|
+
return next;
|
|
183
|
+
});
|
|
166
184
|
}, function (errors) {
|
|
167
185
|
_handlers.default.submissionError(errors, onError);
|
|
168
186
|
});
|
|
@@ -187,12 +205,13 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
187
205
|
components: components
|
|
188
206
|
}, _objectSpread({}, data), _models.EventTypes.SUBMIT);
|
|
189
207
|
|
|
208
|
+
submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action);
|
|
190
209
|
setData(submissionData); // Now submit the data to the backend...
|
|
191
210
|
|
|
192
211
|
hooks.onSubmit(action.type, submissionData, function () {
|
|
193
|
-
hooks.onFormComplete();
|
|
212
|
+
return hooks.onFormComplete();
|
|
194
213
|
}, function (errors) {
|
|
195
|
-
_handlers.default.submissionError(errors, onError);
|
|
214
|
+
return _handlers.default.submissionError(errors, onError);
|
|
196
215
|
});
|
|
197
216
|
}
|
|
198
217
|
}
|
|
@@ -202,11 +221,14 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
202
221
|
|
|
203
222
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
204
223
|
className: classes()
|
|
205
|
-
}, title && pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, title), formState.cya && /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, _extends({
|
|
224
|
+
}, title && !hide_title && pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, title), formState.cya && /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, _extends({
|
|
206
225
|
pages: pages
|
|
207
226
|
}, cya, formState.cya, {
|
|
208
227
|
onAction: onCYAAction,
|
|
209
|
-
onRowAction: onCYARowAction
|
|
228
|
+
onRowAction: onCYARowAction,
|
|
229
|
+
summaryListClassModifiers: summaryListClassModifiers,
|
|
230
|
+
hide_title: hide_title,
|
|
231
|
+
noChangeAction: noChangeAction
|
|
210
232
|
})), formState.page && /*#__PURE__*/_react.default.createElement(_FormPage.default, {
|
|
211
233
|
page: formState.page,
|
|
212
234
|
onAction: onPageAction
|
|
@@ -231,14 +253,20 @@ FormRenderer.propTypes = {
|
|
|
231
253
|
}),
|
|
232
254
|
classBlock: _propTypes.default.string,
|
|
233
255
|
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
234
|
-
className: _propTypes.default.string
|
|
256
|
+
className: _propTypes.default.string,
|
|
257
|
+
hide_title: _propTypes.default.bool,
|
|
258
|
+
summaryListClassModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
259
|
+
noChangeAction: _propTypes.default.bool
|
|
235
260
|
};
|
|
236
261
|
FormRenderer.defaultProps = {
|
|
237
262
|
type: _models.FormTypes.HUB,
|
|
238
263
|
components: [],
|
|
239
264
|
pages: [],
|
|
240
265
|
classBlock: DEFAULT_CLASS,
|
|
241
|
-
classModifiers: []
|
|
266
|
+
classModifiers: [],
|
|
267
|
+
hide_title: false,
|
|
268
|
+
summaryListClassModifiers: [],
|
|
269
|
+
noChangeAction: false
|
|
242
270
|
};
|
|
243
271
|
var _default = FormRenderer;
|
|
244
272
|
exports.default = _default;
|