@ukhomeoffice/cop-react-form-renderer 6.15.9-alpha → 6.15.9-delta

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.
@@ -28,7 +28,7 @@ const addValue = (key, value, multiMap) => {
28
28
  *
29
29
  * @param {Object} payload Javascript object from which the node will be deleted. Updated by the method.
30
30
  * @param {String} path A string containing a decimal point delimited path specifying the node to delete.
31
- * @return Nothing, obj above updated.
31
+ * @return {void}, obj above updated.
32
32
  */
33
33
  exports.addValue = addValue;
34
34
  const deleteNodeByPath = (payload, path) => {
@@ -88,15 +88,20 @@ const getNestedQuestionPath = (optionPath, nestedFieldId) => {
88
88
  /**
89
89
  * If the component has options, go through each option removing the data for any nested fields.
90
90
  * Required as nested options are in the payload at the same heirarchical level.
91
+ *
92
+ * There are occasions when a field shouldn't be removed from the payload, eg if a form is being used for 2 purposes
93
+ * eg the cop-reassign-task-to-rcc.json, and the field is only being hidden for display purposes. Allow these fields
94
+ * to be preserved with a property on the component.
91
95
 
92
96
  * @param {Object} payload Javascript object from which the node will be deleted. Updated by the method.
93
97
  * @param {String} path A string containing a decimal point delimited path specifying the node to delete.
94
98
  * @param {Object} component The form component representing the path being deleted
95
- * @return Nothing, obj above updated.
99
+ * @return {void}, obj above updated.
96
100
  */
97
101
  exports.getNestedQuestionPath = getNestedQuestionPath;
98
102
  const deleteNodeAndOptions = (payload, path, component) => {
99
103
  var _component$data;
104
+ if (component.preserveInPayload) return;
100
105
  deleteNodeByPath(payload, path);
101
106
  // If the component has options, go through each option removing the data for any nested fields. Required as nested options are in the payload at the same heirarchical level.
102
107
  if (component !== null && component !== void 0 && (_component$data = component.data) !== null && _component$data !== void 0 && _component$data.options) {
@@ -115,7 +120,7 @@ const deleteNodeAndOptions = (payload, path, component) => {
115
120
  * but added by the renderer to find the activeId. If so, remove these objects entirely as they have been pruned.
116
121
  *
117
122
  * @param {Array} array Array of objects. Each object which has only 1 remaining field called 'id' should be removed.
118
- * @return Nothing, array above updated.
123
+ * @return {void}, array above updated.
119
124
  */
120
125
  exports.deleteNodeAndOptions = deleteNodeAndOptions;
121
126
  const removeObjectWithOnlySingleIdField = array => {
@@ -238,11 +243,13 @@ exports.isShowEntity = isShowEntity;
238
243
  const findComponentDefinitionInForm = (pageComponentDef, componentByIdMap, componentByFieldIdMap) => {
239
244
  var _ref, _componentByIdMap$get;
240
245
  const componentInForm = (_ref = (_componentByIdMap$get = componentByIdMap.get(pageComponentDef.use)) !== null && _componentByIdMap$get !== void 0 ? _componentByIdMap$get : componentByFieldIdMap.get(pageComponentDef.use)) !== null && _ref !== void 0 ? _ref : pageComponentDef;
246
+
247
+ // Create clone of component, so processing can make changes to it without changing the form
248
+ const componentInFormClone = JSON.parse(JSON.stringify(componentInForm));
241
249
  if (pageComponentDef.use && pageComponentDef.show_when) {
242
- componentInForm.show_when = pageComponentDef.show_when;
250
+ componentInFormClone.show_when = pageComponentDef.show_when;
243
251
  }
244
- // Retun clone of component, so subsequent processing can make changes to it without changing the form
245
- return JSON.parse(JSON.stringify(componentInForm));
252
+ return componentInFormClone;
246
253
  };
247
254
 
248
255
  /**
@@ -254,7 +261,7 @@ const findComponentDefinitionInForm = (pageComponentDef, componentByIdMap, compo
254
261
  * @param {*} component The component definition being deleted that needs corresponding meta data also deleted
255
262
  * @param {*} collectionDataObject The payload containing the file data being deleted (for which the corresponding meta needs deleting)
256
263
  * @param {*} formData The entire payload, which will include the meta section
257
- * @returns Nothing, as the formData will be updated in situ
264
+ * @returns {void}, as the formData will be updated in situ
258
265
  */
259
266
  exports.findComponentDefinitionInForm = findComponentDefinitionInForm;
260
267
  const deleteCorrespondingMetaInfo = (component, collectionDataObject, formData) => {
@@ -335,6 +342,7 @@ const removeEmptyArraysAndUnusedCollectionIDs = payload => {
335
342
  * When the counter reaches 1 we know all other occurences of the component have been resolved
336
343
  * so it is safe to delete.
337
344
  *
345
+ *
338
346
  * @param {*} payload The form payload from which to delete the component data
339
347
  * @param {*} path The payload path of the component
340
348
  * @param {*} component The component whose data we should attempt to delete
@@ -30,6 +30,12 @@ const getCurrentTaskState = function (_ref) {
30
30
  if (currentPage) {
31
31
  return _models.TaskStates.TYPES.IN_PROGRESS;
32
32
  }
33
+ // If the user has clicked on the back link (see FormRenderer.jsx window.onpopstate event handler)
34
+ // the task will be incomplete and the currentPage deleted
35
+ // and the task state should be recognised as 'In progress'.
36
+ if (complete !== undefined && !complete && currentPage === undefined) {
37
+ return _models.TaskStates.TYPES.IN_PROGRESS;
38
+ }
33
39
  return defaultState;
34
40
  };
35
41
 
@@ -115,6 +115,26 @@ describe('components.FormRenderer.helpers.getUpdatedSectionStates', () => {
115
115
  expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.IN_PROGRESS);
116
116
  expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
117
117
  });
118
+ it("should set tasks to '".concat(_models.TaskStates.TYPES.IN_PROGRESS, "' if they have no current page and are not complete"), () => {
119
+ const SECTIONS = [{
120
+ name: 'Add event details',
121
+ tasks: [{
122
+ name: 'Date, location and mode details',
123
+ pages: ['eventDate', 'eventMode']
124
+ }, {
125
+ name: 'Officer and agency details',
126
+ pages: ['officeDetails']
127
+ }]
128
+ }];
129
+ const TASKS = {
130
+ 'Date, location and mode details': {
131
+ complete: false
132
+ }
133
+ };
134
+ const updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS);
135
+ expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.IN_PROGRESS);
136
+ expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
137
+ });
118
138
  it("should set the status of any tasks in a section with a failed show_when to '".concat(_models.TaskStates.TYPES.SKIPPED, "'"), () => {
119
139
  const SECTIONS = [{
120
140
  name: 'Add event details',
@@ -23,7 +23,8 @@ describe('utils.Component.get', () => {
23
23
  fieldId: FIELD_ID,
24
24
  label: LABEL,
25
25
  onChange: ON_CHANGE,
26
- 'data-testid': ID
26
+ 'data-testid': ID,
27
+ allowedTypes: []
27
28
  };
28
29
  const {
29
30
  container
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "6.15.9-alpha",
3
+ "version": "6.15.9-delta",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",
@@ -16,12 +16,12 @@
16
16
  "yalc-publish": "yarn compile-with-maps && cp -r src dist/src && yalc publish --push"
17
17
  },
18
18
  "dependencies": {
19
- "@ukhomeoffice/cop-react-components": "4.7.11",
19
+ "@ukhomeoffice/cop-react-components": "4.7.16",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^5.0.0",
23
- "web-vitals": "^1.0.1",
24
- "uuid": "^8.1.0"
23
+ "uuid": "^8.1.0",
24
+ "web-vitals": "^1.0.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@babel/cli": "^7.15.4",