@ukhomeoffice/cop-react-form-renderer 6.0.6-peter → 6.6.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.
- package/dist/components/CheckYourAnswers/CheckYourAnswers.scss +2 -2
- package/dist/components/CollectionPage/CollectionPage.js +8 -2
- package/dist/components/CollectionSummary/BannerStrip.js +3 -2
- package/dist/components/CollectionSummary/BannerStrip.scss +2 -2
- package/dist/components/CollectionSummary/BannerStrip.test.js +39 -4
- package/dist/components/CollectionSummary/CollectionSummary.js +82 -63
- package/dist/components/CollectionSummary/CollectionSummary.scss +1 -1
- package/dist/components/CollectionSummary/CollectionSummary.test.js +40 -80
- package/dist/components/CollectionSummary/Confirmation.scss +1 -1
- package/dist/components/CollectionSummary/RenderListView.js +23 -19
- package/dist/components/CollectionSummary/RenderListView.scss +11 -2
- package/dist/components/CollectionSummary/RenderListView.test.js +14 -4
- package/dist/components/CollectionSummary/SummaryCard.js +61 -40
- package/dist/components/CollectionSummary/SummaryCard.scss +2 -1
- package/dist/components/CollectionSummary/SummaryCard.test.js +193 -150
- package/dist/components/CollectionSummary/SummaryCardDetails.js +70 -13
- package/dist/components/CollectionSummary/SummaryCardDetails.scss +45 -8
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +174 -26
- package/dist/components/CollectionSummary/SummaryCardValidationContext.js +15 -5
- package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +5 -4
- package/dist/components/FormComponent/Collection.js +24 -17
- package/dist/components/FormComponent/Collection.test.js +138 -0
- package/dist/components/FormComponent/FormComponent.js +12 -0
- package/dist/components/FormPage/FormPage.scss +1 -1
- package/dist/components/FormRenderer/FormRenderer.js +7 -4
- package/dist/components/FormRenderer/FormRenderer.scss +1 -1
- package/dist/components/FormRenderer/helpers/index.js +1 -3
- package/dist/components/FormRenderer/onPageAction.js +7 -9
- package/dist/components/FormRenderer/onPageAction.test.js +18 -9
- package/dist/components/SummaryList/SummaryList.scss +2 -2
- package/dist/components/TaskList/TaskList.scss +1 -1
- package/dist/context/ValidationContext/ValidationContext.js +49 -5
- package/dist/context/ValidationContext/ValidationContext.test.js +16 -7
- package/dist/hooks/useRefData.js +1 -1
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +1 -2
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +5 -0
- package/dist/utils/CollectionPage/addCollectionPageEntry.js +1 -2
- package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +4 -24
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +22 -2
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +39 -4
- package/dist/utils/CollectionPage/getErrorsForCollection.js +55 -0
- package/dist/utils/CollectionPage/getErrorsForCollection.test.js +155 -0
- package/dist/utils/CollectionPage/getQuickEditPage.js +14 -5
- package/dist/utils/CollectionPage/getQuickEditPage.test.js +14 -29
- package/dist/utils/CollectionPage/index.js +2 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +0 -1
- package/dist/utils/CollectionPage/setCollectionPageData.js +9 -4
- package/dist/utils/CollectionPage/setCollectionPageData.test.js +18 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/Condition/meetsCondition.js +18 -0
- package/dist/utils/Condition/meetsCondition.test.js +100 -0
- package/dist/utils/Data/getOptions.js +10 -0
- package/dist/utils/Data/getOptions.test.js +73 -0
- package/dist/utils/Data/nestInRefdataOptions.js +49 -0
- package/dist/utils/Data/nestInRefdataOptions.test.js +236 -0
- package/dist/utils/Validate/additional/mustBeUniqueInCollection.js +4 -0
- package/dist/utils/Validate/additional/mustBeUniqueInCollection.test.js +36 -0
- package/dist/utils/Validate/validateContainer.js +3 -1
- package/dist/utils/Validate/validateContainer.test.js +33 -0
- package/dist/utils/Validate/validateEmail.js +1 -1
- package/dist/utils/Validate/validatePage.js +10 -1
- package/dist/utils/Validate/validatePage.test.js +69 -0
- package/package.json +4 -4
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/component-used-in-multiple-pages-data.json +0 -4
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/component-used-in-multiple-pages-form.json +0 -61
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-collection-data-removed.json +0 -4
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-collections.json +0 -8
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-components-removed.json +0 -3
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-components.json +0 -5
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-entire-collection-removed.json +0 -3
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-nested-component-removed.json +0 -10
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-nested-components.json +0 -11
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-for-nested-components.json +0 -96
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-collections-delete-entire.json +0 -47
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-collections.json +0 -46
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-components.json +0 -48
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +0 -175
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.test.js +0 -113
- package/dist/components/FormRenderer/helpers/deleteNodeByPath.js +0 -20
- package/dist/components/FormRenderer/helpers/deleteNodeByPath.test.js +0 -56
|
@@ -719,4 +719,73 @@ describe('utils.Validate.Page', function () {
|
|
|
719
719
|
});
|
|
720
720
|
});
|
|
721
721
|
});
|
|
722
|
+
describe('when there are queued errors', function () {
|
|
723
|
+
it('should return any errors queued for a component as well as errors found during validation', function () {
|
|
724
|
+
var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true)];
|
|
725
|
+
var PAGE = {
|
|
726
|
+
components: COMPONENTS,
|
|
727
|
+
formData: null
|
|
728
|
+
};
|
|
729
|
+
var QUEUED_ERRORS = [{
|
|
730
|
+
id: 'a',
|
|
731
|
+
error: 'Error queued for Alpha 1'
|
|
732
|
+
}, {
|
|
733
|
+
id: 'a',
|
|
734
|
+
error: 'Error queued for Alpha 2'
|
|
735
|
+
}];
|
|
736
|
+
var RESULT = (0, _validatePage.default)(PAGE, QUEUED_ERRORS);
|
|
737
|
+
expect(RESULT.length).toEqual(3);
|
|
738
|
+
expect(RESULT[0]).toEqual(_objectSpread({}, QUEUED_ERRORS[0]));
|
|
739
|
+
expect(RESULT[1]).toEqual(_objectSpread({}, QUEUED_ERRORS[1]));
|
|
740
|
+
expect(RESULT[2]).toEqual({
|
|
741
|
+
id: 'a',
|
|
742
|
+
error: 'Alpha is required'
|
|
743
|
+
});
|
|
744
|
+
});
|
|
745
|
+
it('should return any errors queued for a component even if no errors are found during validation', function () {
|
|
746
|
+
var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true)];
|
|
747
|
+
var PAGE = {
|
|
748
|
+
components: COMPONENTS,
|
|
749
|
+
formData: {
|
|
750
|
+
a: 'Value'
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
var QUEUED_ERRORS = [{
|
|
754
|
+
id: 'a',
|
|
755
|
+
error: 'Error queued for Alpha 1'
|
|
756
|
+
}, {
|
|
757
|
+
id: 'a',
|
|
758
|
+
error: 'Error queued for Alpha 2'
|
|
759
|
+
}];
|
|
760
|
+
var RESULT = (0, _validatePage.default)(PAGE, QUEUED_ERRORS);
|
|
761
|
+
expect(RESULT.length).toEqual(2);
|
|
762
|
+
expect(RESULT[0]).toEqual(_objectSpread({}, QUEUED_ERRORS[0]));
|
|
763
|
+
expect(RESULT[1]).toEqual(_objectSpread({}, QUEUED_ERRORS[1]));
|
|
764
|
+
});
|
|
765
|
+
it('should return any queued errors if the component is not shown', function () {
|
|
766
|
+
var COMPONENTS = [_objectSpread(_objectSpread({}, setup('a', _models.ComponentTypes.TEXT, 'Alpha', true)), {}, {
|
|
767
|
+
show_when: [{
|
|
768
|
+
field: 'b',
|
|
769
|
+
op: '=',
|
|
770
|
+
value: 'yes'
|
|
771
|
+
}]
|
|
772
|
+
})];
|
|
773
|
+
var PAGE = {
|
|
774
|
+
components: COMPONENTS,
|
|
775
|
+
formData: {
|
|
776
|
+
a: 'Value',
|
|
777
|
+
b: 'no'
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
var QUEUED_ERRORS = [{
|
|
781
|
+
id: 'a',
|
|
782
|
+
error: 'Error queued for Alpha 1'
|
|
783
|
+
}, {
|
|
784
|
+
id: 'a',
|
|
785
|
+
error: 'Error queued for Alpha 2'
|
|
786
|
+
}];
|
|
787
|
+
var RESULT = (0, _validatePage.default)(PAGE, QUEUED_ERRORS);
|
|
788
|
+
expect(RESULT.length).toEqual(0);
|
|
789
|
+
});
|
|
790
|
+
});
|
|
722
791
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "^
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "^4.0.0",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
|
-
"govuk-frontend": "^
|
|
22
|
+
"govuk-frontend": "^5.0.0",
|
|
23
23
|
"web-vitals": "^1.0.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"eslint-config-airbnb": "^19.0.4",
|
|
49
49
|
"eslint-config-prettier": "^8.6.0",
|
|
50
50
|
"html-react-parser": "^0.10.5",
|
|
51
|
-
"node-sass": "^6.0.1",
|
|
52
51
|
"prop-types": "^15.8.1",
|
|
53
52
|
"react": "^16.13.1",
|
|
54
53
|
"react-dom": "^16.13.1",
|
|
55
54
|
"react-scripts": "4.0.3",
|
|
55
|
+
"sass": "^1.69.5",
|
|
56
56
|
"storybook-addon-mock": "^2.0.1"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"components": [
|
|
3
|
-
{
|
|
4
|
-
"id": "componentA",
|
|
5
|
-
"type": "radios",
|
|
6
|
-
"label": "Field A",
|
|
7
|
-
"fieldId": "fieldA",
|
|
8
|
-
"required": true
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"id": "componentB",
|
|
12
|
-
"type": "collection",
|
|
13
|
-
"label": "Component B",
|
|
14
|
-
"fieldId": "componentB"
|
|
15
|
-
}
|
|
16
|
-
],
|
|
17
|
-
"pages": [
|
|
18
|
-
{
|
|
19
|
-
"id": "pageA",
|
|
20
|
-
"show_when": {
|
|
21
|
-
"op": "=",
|
|
22
|
-
"field": "componentA",
|
|
23
|
-
"value": "hide"
|
|
24
|
-
},
|
|
25
|
-
"components": [
|
|
26
|
-
{
|
|
27
|
-
"id": "componentB",
|
|
28
|
-
"use": "componentB"
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"id": "pageB",
|
|
34
|
-
"show_when": {
|
|
35
|
-
"op": "=",
|
|
36
|
-
"field": "componentA",
|
|
37
|
-
"value": "show"
|
|
38
|
-
},
|
|
39
|
-
"components": [
|
|
40
|
-
{
|
|
41
|
-
"id": "componentB",
|
|
42
|
-
"use": "componentB"
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"id": "pageC",
|
|
48
|
-
"show_when": {
|
|
49
|
-
"op": "=",
|
|
50
|
-
"field": "componentA",
|
|
51
|
-
"value": "hide"
|
|
52
|
-
},
|
|
53
|
-
"components": [
|
|
54
|
-
{
|
|
55
|
-
"id": "componentB",
|
|
56
|
-
"use": "componentB"
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "example-form",
|
|
3
|
-
"version": "0.0.1",
|
|
4
|
-
"name": "example-form",
|
|
5
|
-
"title": "Example form",
|
|
6
|
-
"type": "form",
|
|
7
|
-
"components": [
|
|
8
|
-
{
|
|
9
|
-
"id": "alpha",
|
|
10
|
-
"fieldId": "alpha",
|
|
11
|
-
"label": "Alpha",
|
|
12
|
-
"type": "text"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"id": "bravo",
|
|
16
|
-
"fieldId": "bravo",
|
|
17
|
-
"label": "Bravo",
|
|
18
|
-
"type": "text"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"id": "person",
|
|
22
|
-
"fieldId": "person",
|
|
23
|
-
"type": "container",
|
|
24
|
-
"components": [
|
|
25
|
-
{
|
|
26
|
-
"id": "charlie",
|
|
27
|
-
"fieldId": "charlie",
|
|
28
|
-
"label": "Charlie",
|
|
29
|
-
"type": "text",
|
|
30
|
-
"show_when": {
|
|
31
|
-
"op": "=",
|
|
32
|
-
"field": "bravo",
|
|
33
|
-
"value": "bravo"
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"id": "delta",
|
|
38
|
-
"fieldId": "delta",
|
|
39
|
-
"label": "Delta",
|
|
40
|
-
"type": "text",
|
|
41
|
-
"show_when": {
|
|
42
|
-
"op": "=",
|
|
43
|
-
"field": "bravo",
|
|
44
|
-
"value": "another"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"id": "gamma",
|
|
51
|
-
"fieldId": "gamma",
|
|
52
|
-
"label": "Gamma",
|
|
53
|
-
"type": "text"
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
"id": "epsilon",
|
|
57
|
-
"fieldId": "epsilon",
|
|
58
|
-
"label": "Epsilon",
|
|
59
|
-
"type": "text"
|
|
60
|
-
}
|
|
61
|
-
],
|
|
62
|
-
"pages": [
|
|
63
|
-
{
|
|
64
|
-
"id": "general",
|
|
65
|
-
"name": "general",
|
|
66
|
-
"title": "General information",
|
|
67
|
-
"components": [
|
|
68
|
-
{
|
|
69
|
-
"use": "alpha"
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"use": "bravo"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"use": "person"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"use": "gamma"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
"use": "epsilon"
|
|
82
|
-
}
|
|
83
|
-
],
|
|
84
|
-
"actions": [
|
|
85
|
-
"submit",
|
|
86
|
-
{
|
|
87
|
-
"type": "cancel",
|
|
88
|
-
"page": "",
|
|
89
|
-
"validate": false,
|
|
90
|
-
"classModifiers": "secondary",
|
|
91
|
-
"label": "Cancel"
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
}
|
|
95
|
-
]
|
|
96
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "form-with-collection",
|
|
3
|
-
"components": [
|
|
4
|
-
{
|
|
5
|
-
"id": "componentA",
|
|
6
|
-
"fieldId": "componentA"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"id": "itemCategory",
|
|
10
|
-
"fieldId": "itemCategory"
|
|
11
|
-
}
|
|
12
|
-
],
|
|
13
|
-
"pages": [
|
|
14
|
-
{
|
|
15
|
-
"id": "pageA",
|
|
16
|
-
"name": "Page A",
|
|
17
|
-
"components": [
|
|
18
|
-
{
|
|
19
|
-
"use": "componentA"
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"id": "pageB",
|
|
25
|
-
"deleteCollectionWhenHidden": true,
|
|
26
|
-
"collection": {
|
|
27
|
-
"name": "componentAs",
|
|
28
|
-
"labels": {
|
|
29
|
-
"item": "Component A ${index}"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"name": "pageB",
|
|
33
|
-
"show_when": [
|
|
34
|
-
{
|
|
35
|
-
"op": "=",
|
|
36
|
-
"field": "componentA",
|
|
37
|
-
"value": true
|
|
38
|
-
}
|
|
39
|
-
],
|
|
40
|
-
"components": [
|
|
41
|
-
{
|
|
42
|
-
"use": "itemCategory"
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
}
|
package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-collections.json
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "form-with-collection",
|
|
3
|
-
"components": [
|
|
4
|
-
{
|
|
5
|
-
"id": "componentA",
|
|
6
|
-
"fieldId": "componentA"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"id": "itemCategory",
|
|
10
|
-
"fieldId": "itemCategory"
|
|
11
|
-
}
|
|
12
|
-
],
|
|
13
|
-
"pages": [
|
|
14
|
-
{
|
|
15
|
-
"id": "pageA",
|
|
16
|
-
"name": "Page A",
|
|
17
|
-
"components": [
|
|
18
|
-
{
|
|
19
|
-
"use": "componentA"
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"id": "pageB",
|
|
25
|
-
"collection": {
|
|
26
|
-
"name": "componentAs",
|
|
27
|
-
"labels": {
|
|
28
|
-
"item": "Component A ${index}"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"name": "pageB",
|
|
32
|
-
"show_when": [
|
|
33
|
-
{
|
|
34
|
-
"op": "=",
|
|
35
|
-
"field": "componentA",
|
|
36
|
-
"value": true
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
"components": [
|
|
40
|
-
{
|
|
41
|
-
"use": "itemCategory"
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
}
|
package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-components.json
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "form-with-components",
|
|
3
|
-
"components": [
|
|
4
|
-
{
|
|
5
|
-
"id": "componentA",
|
|
6
|
-
"fieldId": "componentA"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"id": "componentB",
|
|
10
|
-
"fieldId": "componentB",
|
|
11
|
-
"show_when": [
|
|
12
|
-
{
|
|
13
|
-
"op": "=",
|
|
14
|
-
"field": "componentA",
|
|
15
|
-
"value": "show"
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"id": "componentC",
|
|
21
|
-
"fieldId": "componentC",
|
|
22
|
-
"show_when": [
|
|
23
|
-
{
|
|
24
|
-
"op": "=",
|
|
25
|
-
"field": "componentA",
|
|
26
|
-
"value": "show"
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
}
|
|
30
|
-
],
|
|
31
|
-
"pages": [
|
|
32
|
-
{
|
|
33
|
-
"id": "pageA",
|
|
34
|
-
"name": "Page A",
|
|
35
|
-
"components": [
|
|
36
|
-
{
|
|
37
|
-
"use": "componentA"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"use": "componentB"
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
"use": "componentC"
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _showComponent = _interopRequireDefault(require("../../../utils/Component/showComponent"));
|
|
8
|
-
var _mergeCollectionPages = _interopRequireDefault(require("../../../utils/CollectionPage/mergeCollectionPages"));
|
|
9
|
-
var _deleteNodeByPath = _interopRequireDefault(require("./deleteNodeByPath"));
|
|
10
|
-
var _optionIsSelected = _interopRequireDefault(require("../../../utils/Component/optionIsSelected"));
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
/* eslint-disable no-param-reassign */
|
|
13
|
-
|
|
14
|
-
var recurseCheckForHiddenComponents = function recurseCheckForHiddenComponents(component, formData, path, candidateComponentForDeletion) {
|
|
15
|
-
path = path ? "".concat(path, ".").concat(component.fieldId) : component.fieldId;
|
|
16
|
-
if (component) {
|
|
17
|
-
if (component.components) {
|
|
18
|
-
var _component$components;
|
|
19
|
-
(_component$components = component.components) === null || _component$components === void 0 || _component$components.forEach(function (c) {
|
|
20
|
-
recurseCheckForHiddenComponents(c, formData, path, candidateComponentForDeletion);
|
|
21
|
-
});
|
|
22
|
-
} else if ((0, _showComponent.default)(component, formData)) {
|
|
23
|
-
var _component$data;
|
|
24
|
-
if (component !== null && component !== void 0 && (_component$data = component.data) !== null && _component$data !== void 0 && _component$data.options) {
|
|
25
|
-
var _component$data2;
|
|
26
|
-
component === null || component === void 0 || (_component$data2 = component.data) === null || _component$data2 === void 0 || (_component$data2 = _component$data2.options) === null || _component$data2 === void 0 || _component$data2.forEach(function (option) {
|
|
27
|
-
if (!(0, _optionIsSelected.default)(formData[component.id], option) && option.nested) {
|
|
28
|
-
option.nested.forEach(function (nested) {
|
|
29
|
-
path = nested.fieldId;
|
|
30
|
-
if (path) {
|
|
31
|
-
candidateComponentForDeletion.set(path, component);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
} else if (!(0, _showComponent.default)(component, formData)) {
|
|
38
|
-
if (path) {
|
|
39
|
-
candidateComponentForDeletion.set(path, component);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var buildListOfComponentsUsedInVisiblePages = function buildListOfComponentsUsedInVisiblePages(page, form, formData, componentsUsedInVisiblePagesIds) {
|
|
45
|
-
var _page$components;
|
|
46
|
-
(_page$components = page.components) === null || _page$components === void 0 || _page$components.forEach(function (component) {
|
|
47
|
-
var _ref, _form$components$find;
|
|
48
|
-
var componentObj = (_ref = (_form$components$find = form.components.find(function (c) {
|
|
49
|
-
return c.fieldId === component.use;
|
|
50
|
-
})) !== null && _form$components$find !== void 0 ? _form$components$find : form.components.find(function (c) {
|
|
51
|
-
return c.id === component.use;
|
|
52
|
-
})) !== null && _ref !== void 0 ? _ref : component;
|
|
53
|
-
if (page && (0, _showComponent.default)(page, formData)) {
|
|
54
|
-
if (componentObj && (0, _showComponent.default)(componentObj, formData)) {
|
|
55
|
-
if (componentObj.fieldId) {
|
|
56
|
-
componentsUsedInVisiblePagesIds.push(componentObj.fieldId);
|
|
57
|
-
} else if (componentObj.id) {
|
|
58
|
-
componentsUsedInVisiblePagesIds.push(componentObj.id);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
var recurseDeleteComponents = function recurseDeleteComponents(component, formData, path, checkIfComponentHidden) {
|
|
65
|
-
path = path ? "".concat(path, ".").concat(component.fieldId) : component.fieldId;
|
|
66
|
-
if (component) {
|
|
67
|
-
if (component.components) {
|
|
68
|
-
var _component$components2;
|
|
69
|
-
(_component$components2 = component.components) === null || _component$components2 === void 0 || _component$components2.forEach(function (c) {
|
|
70
|
-
recurseDeleteComponents(c, formData, path, checkIfComponentHidden);
|
|
71
|
-
});
|
|
72
|
-
} else if (checkIfComponentHidden) {
|
|
73
|
-
if (!(0, _showComponent.default)(component, formData)) {
|
|
74
|
-
delete formData[path];
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
delete formData[path];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
var markComponentsForDeletion = function markComponentsForDeletion(page, form, formData, candidateComponentForDeletion, componentsUsedInVisiblePages) {
|
|
82
|
-
var _page$components2;
|
|
83
|
-
if (page.disableClearWhenHidden) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
(_page$components2 = page.components) === null || _page$components2 === void 0 || _page$components2.forEach(function (component) {
|
|
87
|
-
var _ref2, _form$components$find2;
|
|
88
|
-
var componentObj = (_ref2 = (_form$components$find2 = form.components.find(function (c) {
|
|
89
|
-
return c.fieldId === component.use;
|
|
90
|
-
})) !== null && _form$components$find2 !== void 0 ? _form$components$find2 : form.components.find(function (c) {
|
|
91
|
-
return c.id === component.use;
|
|
92
|
-
})) !== null && _ref2 !== void 0 ? _ref2 : component;
|
|
93
|
-
if (page && (0, _showComponent.default)(page, formData)) {
|
|
94
|
-
buildListOfComponentsUsedInVisiblePages(page, form, formData, componentsUsedInVisiblePages);
|
|
95
|
-
recurseCheckForHiddenComponents(componentObj, formData, null, candidateComponentForDeletion);
|
|
96
|
-
} else if (componentObj.fieldId) {
|
|
97
|
-
candidateComponentForDeletion.set(componentObj.fieldId, componentObj);
|
|
98
|
-
} else if (componentObj.id) {
|
|
99
|
-
candidateComponentForDeletion.set(componentObj.id, componentObj);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
var deleteHiddenComponent = function deleteHiddenComponent(page, form, collectionData, formData) {
|
|
104
|
-
if (page.disableClearWhenHidden) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (page && (0, _showComponent.default)(page, formData)) {
|
|
108
|
-
var _page$components3;
|
|
109
|
-
(_page$components3 = page.components) === null || _page$components3 === void 0 || _page$components3.forEach(function (component) {
|
|
110
|
-
var _ref3, _form$components$find3;
|
|
111
|
-
var componentObj = (_ref3 = (_form$components$find3 = form.components.find(function (c) {
|
|
112
|
-
return c.fieldId === component.use;
|
|
113
|
-
})) !== null && _form$components$find3 !== void 0 ? _form$components$find3 : form.components.find(function (c) {
|
|
114
|
-
return c.id === component.use;
|
|
115
|
-
})) !== null && _ref3 !== void 0 ? _ref3 : component;
|
|
116
|
-
recurseDeleteComponents(componentObj, collectionData, null, true);
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
119
|
-
var _page$components4;
|
|
120
|
-
// recursively delete all components on the page
|
|
121
|
-
(_page$components4 = page.components) === null || _page$components4 === void 0 || _page$components4.forEach(function (component) {
|
|
122
|
-
var _ref4, _form$components$find4;
|
|
123
|
-
var componentObj = (_ref4 = (_form$components$find4 = form.components.find(function (c) {
|
|
124
|
-
return c.fieldId === component.use;
|
|
125
|
-
})) !== null && _form$components$find4 !== void 0 ? _form$components$find4 : form.components.find(function (c) {
|
|
126
|
-
return c.id === component.use;
|
|
127
|
-
})) !== null && _ref4 !== void 0 ? _ref4 : component;
|
|
128
|
-
recurseDeleteComponents(componentObj, collectionData, null, false);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
function clearUncompletedRoutesForCollections(formData, page, form) {
|
|
133
|
-
var _page$collection;
|
|
134
|
-
var collectionDatas = formData[page === null || page === void 0 || (_page$collection = page.collection) === null || _page$collection === void 0 ? void 0 : _page$collection.name];
|
|
135
|
-
if (collectionDatas) {
|
|
136
|
-
collectionDatas.forEach(function (collectionData) {
|
|
137
|
-
var _page$childPages;
|
|
138
|
-
/* eslint-disable consistent-return */
|
|
139
|
-
(_page$childPages = page.childPages) === null || _page$childPages === void 0 || _page$childPages.forEach(function (childPage) {
|
|
140
|
-
if (childPage.deleteCollectionWhenHidden) {
|
|
141
|
-
if (childPage && !(0, _showComponent.default)(childPage, formData)) {
|
|
142
|
-
delete formData[childPage.collection.name];
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
deleteHiddenComponent(childPage, form, collectionData, formData);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
var clearOutUncompletedRoutes = function clearOutUncompletedRoutes(form, formData) {
|
|
152
|
-
if (form.disableClearWhenHidden) {
|
|
153
|
-
return formData;
|
|
154
|
-
}
|
|
155
|
-
var condensedPages = (0, _mergeCollectionPages.default)(form.pages);
|
|
156
|
-
var candidateComponentForDeletion = new Map();
|
|
157
|
-
var componentsUsedInVisiblePagesIds = [];
|
|
158
|
-
condensedPages === null || condensedPages === void 0 || condensedPages.forEach(function (page) {
|
|
159
|
-
var _page$collection2;
|
|
160
|
-
if (page !== null && page !== void 0 && (_page$collection2 = page.collection) !== null && _page$collection2 !== void 0 && _page$collection2.name) {
|
|
161
|
-
clearUncompletedRoutesForCollections(formData, page, form);
|
|
162
|
-
} else {
|
|
163
|
-
markComponentsForDeletion(page, form, formData, candidateComponentForDeletion, componentsUsedInVisiblePagesIds);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
componentsUsedInVisiblePagesIds = [].concat(new Set(componentsUsedInVisiblePagesIds));
|
|
167
|
-
componentsUsedInVisiblePagesIds.forEach(function (componentId) {
|
|
168
|
-
return candidateComponentForDeletion.delete(componentId);
|
|
169
|
-
});
|
|
170
|
-
candidateComponentForDeletion.forEach(function (val, key) {
|
|
171
|
-
(0, _deleteNodeByPath.default)(formData, key);
|
|
172
|
-
});
|
|
173
|
-
return formData;
|
|
174
|
-
};
|
|
175
|
-
var _default = exports.default = clearOutUncompletedRoutes;
|