@ukhomeoffice/cop-react-form-renderer 5.28.1 → 5.29.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/dist/components/CollectionSummary/BannerStrip.js +59 -0
- package/dist/components/CollectionSummary/BannerStrip.scss +47 -0
- package/dist/components/CollectionSummary/BannerStrip.test.js +111 -0
- package/dist/components/CollectionSummary/CollectionSummary.js +182 -0
- package/dist/components/CollectionSummary/CollectionSummary.scss +21 -0
- package/dist/components/CollectionSummary/CollectionSummary.test.js +121 -0
- package/dist/components/CollectionSummary/Confirmation.js +58 -0
- package/dist/components/CollectionSummary/Confirmation.scss +14 -0
- package/dist/components/CollectionSummary/Confirmation.test.js +102 -0
- package/dist/components/CollectionSummary/SummaryCard.js +274 -0
- package/dist/components/CollectionSummary/SummaryCard.scss +244 -0
- package/dist/components/CollectionSummary/SummaryCard.test.js +1164 -0
- package/dist/components/CollectionSummary/index.js +10 -0
- package/dist/components/FormComponent/FormComponent.js +19 -3
- package/dist/components/FormPage/FormPage.js +10 -3
- package/dist/components/FormRenderer/FormRenderer.js +1 -0
- package/dist/components/FormRenderer/onPageAction.js +5 -14
- package/dist/components/FormRenderer/onPageAction.test.js +3 -6
- package/dist/models/ComponentTypes.js +2 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +1 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +4 -21
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +32 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +68 -0
- package/dist/utils/CollectionPage/getQuickEditPage.js +74 -0
- package/dist/utils/CollectionPage/getQuickEditPage.test.js +109 -0
- package/dist/utils/CollectionPage/index.js +4 -0
- package/dist/utils/CollectionPage/removeCollectionPageEntry.js +36 -0
- package/dist/utils/CollectionPage/removeCollectionPageEntry.test.js +61 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _CollectionSummary = _interopRequireDefault(require("./CollectionSummary"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
var _default = _CollectionSummary.default;
|
|
10
|
+
exports.default = _default;
|
|
@@ -11,10 +11,11 @@ var _hooks = require("../../hooks");
|
|
|
11
11
|
var _models = require("../../models");
|
|
12
12
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
13
13
|
var _wrapInFormGroup = _interopRequireDefault(require("../../utils/Component/wrapInFormGroup"));
|
|
14
|
+
var _CollectionSummary = _interopRequireDefault(require("../CollectionSummary"));
|
|
14
15
|
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
15
16
|
var _Container = _interopRequireDefault(require("./Container"));
|
|
16
17
|
var _helpers = require("./helpers");
|
|
17
|
-
var _excluded = ["component", "value", "formData", "wrap", "onChange", "onTopLevelChange"]; // Global imports
|
|
18
|
+
var _excluded = ["component", "value", "formData", "wrap", "onAction", "onChange", "onTopLevelChange", "pages"]; // Global imports
|
|
18
19
|
// Local imports
|
|
19
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
21
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -38,8 +39,10 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
38
39
|
value = _ref.value,
|
|
39
40
|
formData = _ref.formData,
|
|
40
41
|
wrap = _ref.wrap,
|
|
42
|
+
onAction = _ref.onAction,
|
|
41
43
|
onChange = _ref.onChange,
|
|
42
44
|
onTopLevelChange = _ref.onTopLevelChange,
|
|
45
|
+
pages = _ref.pages,
|
|
43
46
|
attrs = _objectWithoutProperties(_ref, _excluded);
|
|
44
47
|
var _useHooks = (0, _hooks.useHooks)(),
|
|
45
48
|
hooks = _useHooks.hooks;
|
|
@@ -109,6 +112,15 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
109
112
|
formData: formData
|
|
110
113
|
}));
|
|
111
114
|
}
|
|
115
|
+
if (component.type === _models.ComponentTypes.COLLECTION_SUMMARY) {
|
|
116
|
+
return /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, _extends({}, attrs, {
|
|
117
|
+
config: component,
|
|
118
|
+
formData: formData,
|
|
119
|
+
onAction: onAction,
|
|
120
|
+
onChange: onChange,
|
|
121
|
+
pages: pages
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
112
124
|
var changeMetaDocuments = function changeMetaDocuments(document) {
|
|
113
125
|
var componentPath = component.full_path || component.fieldId;
|
|
114
126
|
if (component.pageCollection) {
|
|
@@ -185,15 +197,19 @@ FormComponent.propTypes = {
|
|
|
185
197
|
}), _propTypes.default.arrayOf(_propTypes.default.shape({}))]),
|
|
186
198
|
formData: _propTypes.default.shape({}),
|
|
187
199
|
wrap: _propTypes.default.bool,
|
|
200
|
+
onAction: _propTypes.default.func,
|
|
188
201
|
onChange: _propTypes.default.func,
|
|
189
|
-
onTopLevelChange: _propTypes.default.func
|
|
202
|
+
onTopLevelChange: _propTypes.default.func,
|
|
203
|
+
pages: _propTypes.default.arrayOf(_propTypes.default.shape({}))
|
|
190
204
|
};
|
|
191
205
|
FormComponent.defaultProps = {
|
|
192
206
|
formData: null,
|
|
207
|
+
onAction: undefined,
|
|
193
208
|
onChange: undefined,
|
|
194
209
|
onTopLevelChange: undefined,
|
|
195
210
|
value: null,
|
|
196
|
-
wrap: true
|
|
211
|
+
wrap: true,
|
|
212
|
+
pages: []
|
|
197
213
|
};
|
|
198
214
|
var _default = FormComponent;
|
|
199
215
|
exports.default = _default;
|
|
@@ -34,6 +34,7 @@ exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
|
34
34
|
var FormPage = function FormPage(_ref) {
|
|
35
35
|
var _formPage$actions, _page$actions;
|
|
36
36
|
var page = _ref.page,
|
|
37
|
+
pages = _ref.pages,
|
|
37
38
|
_onAction = _ref.onAction,
|
|
38
39
|
onWrapperChange = _ref.onWrapperChange,
|
|
39
40
|
onTopLevelChange = _ref.onTopLevelChange,
|
|
@@ -97,10 +98,14 @@ var FormPage = function FormPage(_ref) {
|
|
|
97
98
|
return /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
98
99
|
key: index,
|
|
99
100
|
component: component,
|
|
101
|
+
onAction: function onAction(action) {
|
|
102
|
+
return _onAction(action, patch, patchLabel);
|
|
103
|
+
},
|
|
100
104
|
onChange: onWrapperChange || onPageChange,
|
|
101
105
|
onTopLevelChange: onTopLevelChange || onPageChange,
|
|
102
106
|
value: page.formData[component.fieldId] || patch[component.fieldId],
|
|
103
|
-
formData: page.formData
|
|
107
|
+
formData: page.formData,
|
|
108
|
+
pages: pages
|
|
104
109
|
});
|
|
105
110
|
});
|
|
106
111
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -145,7 +150,8 @@ FormPage.propTypes = {
|
|
|
145
150
|
required: _propTypes.default.bool,
|
|
146
151
|
actions: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape({}), _propTypes.default.string])),
|
|
147
152
|
formData: _propTypes.default.shape({}).isRequired
|
|
148
|
-
}).isRequired
|
|
153
|
+
}).isRequired,
|
|
154
|
+
pages: _propTypes.default.arrayOf(_propTypes.default.shape({}))
|
|
149
155
|
};
|
|
150
156
|
FormPage.defaultProps = {
|
|
151
157
|
classBlock: DEFAULT_CLASS,
|
|
@@ -154,7 +160,8 @@ FormPage.defaultProps = {
|
|
|
154
160
|
hashLink: false,
|
|
155
161
|
onChange: undefined,
|
|
156
162
|
onTopLevelChange: undefined,
|
|
157
|
-
onWrapperChange: undefined
|
|
163
|
+
onWrapperChange: undefined,
|
|
164
|
+
pages: []
|
|
158
165
|
};
|
|
159
166
|
var _default = FormPage;
|
|
160
167
|
exports.default = _default;
|
|
@@ -347,6 +347,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
347
347
|
formData: data
|
|
348
348
|
})), formState.page && !formState.cya && !formState.page.collection && /*#__PURE__*/_react.default.createElement(_FormPage.default, {
|
|
349
349
|
page: formState.page,
|
|
350
|
+
pages: [].concat(pages),
|
|
350
351
|
onAction: function onAction(action, patch, patchLabel) {
|
|
351
352
|
(0, _onPageAction.default)(action, patch, patchLabel, hooks, data, formState, validate, onPageChange, type, pages, components, pageId, setPagePoint, currentTask, setData, hubDetails, setSubmitted, addErrors);
|
|
352
353
|
},
|
|
@@ -82,20 +82,11 @@ var onPageAction = function onPageAction(action, patch, patchLabel, hooks, data,
|
|
|
82
82
|
;
|
|
83
83
|
break;
|
|
84
84
|
case _models.PageAction.TYPES.COLLECTION_REMOVE:
|
|
85
|
-
var activeId = form.page.formData["".concat(action.collection, "ActiveId")];
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
form.page.formData["".concat(action.collection, "LastRemoved")] = _objectSpread({}, entry);
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
;
|
|
95
|
-
return entry;
|
|
96
|
-
}).filter(function (e) {
|
|
97
|
-
return !!e;
|
|
98
|
-
});
|
|
85
|
+
var activeId = action.targetId || form.page.formData["".concat(action.collection.split('.').pop(), "ActiveId")];
|
|
86
|
+
var removedEntry = _utils.default.CollectionPage.removeEntry(action.collection, formState.page.formData, activeId);
|
|
87
|
+
if (action.recordRemoval) {
|
|
88
|
+
form.page.formData["".concat(action.collection.split('.').pop(), "LastRemoved")] = _objectSpread({}, removedEntry);
|
|
89
|
+
}
|
|
99
90
|
break;
|
|
100
91
|
default:
|
|
101
92
|
break;
|
|
@@ -80,7 +80,7 @@ jest.mock('../../utils', function () {
|
|
|
80
80
|
return data;
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
|
-
CollectionPage: {
|
|
83
|
+
CollectionPage: _objectSpread(_objectSpread({}, originalModule.default.CollectionPage), {}, {
|
|
84
84
|
duplicateActiveEntryCalls: 0,
|
|
85
85
|
duplicateActiveEntryResult: true,
|
|
86
86
|
duplicateActiveEntry: function duplicateActiveEntry() {
|
|
@@ -90,14 +90,11 @@ jest.mock('../../utils', function () {
|
|
|
90
90
|
addEntryCalls: 0,
|
|
91
91
|
addEntryResult: true,
|
|
92
92
|
addEntry: function addEntry(collectionName, formData) {
|
|
93
|
-
|
|
94
|
-
// the mock one so it's just stubbed.
|
|
95
|
-
// eslint-disable-next-line no-param-reassign
|
|
96
|
-
formData["".concat(collectionName, "ActiveId")] = '1';
|
|
93
|
+
originalModule.default.CollectionPage.addEntry(collectionName, formData);
|
|
97
94
|
this.addEntryCalls += 1;
|
|
98
95
|
return this.addEntryResult;
|
|
99
96
|
}
|
|
100
|
-
},
|
|
97
|
+
}),
|
|
101
98
|
reset: function reset() {
|
|
102
99
|
this.Format.formCalls = 0;
|
|
103
100
|
this.CollectionPage.duplicateActiveEntryCalls = 0;
|
|
@@ -9,6 +9,7 @@ var TYPE_AUTOCOMPLETE = 'autocomplete';
|
|
|
9
9
|
var TYPE_CALCULATION = 'calculation';
|
|
10
10
|
var TYPE_CHECKBOXES = 'checkboxes';
|
|
11
11
|
var TYPE_COLLECTION = 'collection';
|
|
12
|
+
var TYPE_COLLECTION_SUMMARY = 'collection-summary';
|
|
12
13
|
var TYPE_CONTAINER = 'container';
|
|
13
14
|
var TYPE_DATE = 'date';
|
|
14
15
|
var TYPE_DETAILS = 'details';
|
|
@@ -33,6 +34,7 @@ var ComponentTypes = {
|
|
|
33
34
|
CALCULATION: TYPE_CALCULATION,
|
|
34
35
|
CHECKBOXES: TYPE_CHECKBOXES,
|
|
35
36
|
COLLECTION: TYPE_COLLECTION,
|
|
37
|
+
COLLECTION_SUMMARY: TYPE_COLLECTION_SUMMARY,
|
|
36
38
|
CONTAINER: TYPE_CONTAINER,
|
|
37
39
|
DATE: TYPE_DATE,
|
|
38
40
|
DETAILS: TYPE_DETAILS,
|
|
@@ -12,7 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
12
12
|
/* eslint-disable no-console */
|
|
13
13
|
// Local imports
|
|
14
14
|
|
|
15
|
-
var EXCLUDE_FROM_CYA = [_models.ComponentTypes.ALERT, _models.ComponentTypes.HEADING, _models.ComponentTypes.HTML, _models.ComponentTypes.INSET_TEXT];
|
|
15
|
+
var EXCLUDE_FROM_CYA = [_models.ComponentTypes.ALERT, _models.ComponentTypes.COLLECTION_SUMMARY, _models.ComponentTypes.HEADING, _models.ComponentTypes.HTML, _models.ComponentTypes.INSET_TEXT];
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Determines whether a given component should display on the Check your answers screen.
|
|
@@ -4,15 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
8
|
-
var
|
|
7
|
+
var _getCollectionPageActiveId = _interopRequireDefault(require("./getCollectionPageActiveId"));
|
|
8
|
+
var _duplicateCollectionPageEntry = _interopRequireDefault(require("./duplicateCollectionPageEntry"));
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
11
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
10
|
/**
|
|
17
11
|
* Duplicates the currently active entry in a named collection's data.
|
|
18
12
|
* Once duplicated, the new entry is set as the active entry.
|
|
@@ -25,19 +19,8 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
25
19
|
* @return true if the entry ws successfully duplicated, false if not.
|
|
26
20
|
*/
|
|
27
21
|
var duplicateCollectionPageActiveEntry = function duplicateCollectionPageActiveEntry(collectionName, formData) {
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
var currentEntry = collectionData === null || collectionData === void 0 ? void 0 : collectionData[currentIndex];
|
|
31
|
-
if (!currentEntry) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
var newEntry = _objectSpread(_objectSpread({}, currentEntry), {}, {
|
|
35
|
-
id: Date.now().toString()
|
|
36
|
-
});
|
|
37
|
-
collectionData.push(newEntry);
|
|
38
|
-
// eslint-disable-next-line no-param-reassign
|
|
39
|
-
formData["".concat(collectionName.split('.').pop(), "ActiveId")] = newEntry.id;
|
|
40
|
-
return true;
|
|
22
|
+
var currentEntryId = (0, _getCollectionPageActiveId.default)(collectionName, formData);
|
|
23
|
+
return (0, _duplicateCollectionPageEntry.default)(collectionName, formData, currentEntryId);
|
|
41
24
|
};
|
|
42
25
|
var _default = duplicateCollectionPageActiveEntry;
|
|
43
26
|
exports.default = _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _getCollectionPageData = _interopRequireDefault(require("./getCollectionPageData"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
+
var duplicateCollectionPageEntry = function duplicateCollectionPageEntry(collectionName, formData, entryId) {
|
|
16
|
+
var collectionData = (0, _getCollectionPageData.default)(collectionName, formData);
|
|
17
|
+
var entryToDuplicate = collectionData === null || collectionData === void 0 ? void 0 : collectionData.find(function (entry) {
|
|
18
|
+
return entry.id === entryId;
|
|
19
|
+
});
|
|
20
|
+
if (!entryToDuplicate) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
var newEntry = _objectSpread(_objectSpread({}, entryToDuplicate), {}, {
|
|
24
|
+
id: Date.now().toString()
|
|
25
|
+
});
|
|
26
|
+
collectionData.push(newEntry);
|
|
27
|
+
// eslint-disable-next-line no-param-reassign
|
|
28
|
+
formData["".concat(collectionName.split('.').pop(), "ActiveId")] = newEntry.id;
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
31
|
+
var _default = duplicateCollectionPageEntry;
|
|
32
|
+
exports.default = _default;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _duplicateCollectionPageEntry = _interopRequireDefault(require("./duplicateCollectionPageEntry"));
|
|
4
|
+
var _getCollectionPageActiveId = _interopRequireDefault(require("./getCollectionPageActiveId"));
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
7
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
9
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
+
describe('utils.CollectionPage.duplicateCollectionPageEntry', function () {
|
|
11
|
+
var COLLECTION_NAME = 'testCollection';
|
|
12
|
+
var OBJ = {
|
|
13
|
+
id: '1',
|
|
14
|
+
value: 'value'
|
|
15
|
+
};
|
|
16
|
+
it('should duplicate the active entry if one exists', function () {
|
|
17
|
+
var _FORM_DATA;
|
|
18
|
+
var FORM_DATA = (_FORM_DATA = {}, _defineProperty(_FORM_DATA, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA, COLLECTION_NAME, [OBJ]), _FORM_DATA);
|
|
19
|
+
(0, _duplicateCollectionPageEntry.default)(COLLECTION_NAME, FORM_DATA, '1');
|
|
20
|
+
expect(FORM_DATA[COLLECTION_NAME].length).toEqual(2);
|
|
21
|
+
expect(FORM_DATA[COLLECTION_NAME][1].value).toEqual(FORM_DATA[COLLECTION_NAME][0].value);
|
|
22
|
+
expect(FORM_DATA[COLLECTION_NAME][1].id).toBeTruthy();
|
|
23
|
+
expect(FORM_DATA[COLLECTION_NAME][1].id === '1').toBeFalsy();
|
|
24
|
+
expect(FORM_DATA["".concat(COLLECTION_NAME, "ActiveId")]).toBeTruthy();
|
|
25
|
+
expect(FORM_DATA["".concat(COLLECTION_NAME, "ActiveId")] === '1').toBeFalsy();
|
|
26
|
+
});
|
|
27
|
+
it('should duplicate entries in nested collections correctly', function () {
|
|
28
|
+
var FORM_DATA = {
|
|
29
|
+
parentsActiveId: '2',
|
|
30
|
+
childrenActiveId: '2',
|
|
31
|
+
parents: [{
|
|
32
|
+
id: '1',
|
|
33
|
+
children: [{
|
|
34
|
+
id: '1',
|
|
35
|
+
value: 'Alpha'
|
|
36
|
+
}]
|
|
37
|
+
}, {
|
|
38
|
+
id: '2',
|
|
39
|
+
children: [{
|
|
40
|
+
id: '1',
|
|
41
|
+
value: 'Alpha'
|
|
42
|
+
}, {
|
|
43
|
+
id: '2',
|
|
44
|
+
value: 'Duplicate me!'
|
|
45
|
+
}]
|
|
46
|
+
}]
|
|
47
|
+
};
|
|
48
|
+
(0, _duplicateCollectionPageEntry.default)('parents.children', FORM_DATA, '2');
|
|
49
|
+
expect(FORM_DATA.parents[1].children.length).toEqual(3);
|
|
50
|
+
expect(FORM_DATA.parents[1].children[2].value).toEqual(FORM_DATA.parents[1].children[1].value);
|
|
51
|
+
expect(FORM_DATA.parents[1].children[2].id).toBeTruthy();
|
|
52
|
+
expect(FORM_DATA.parents[1].children[2].id === FORM_DATA.parents[1].children[1].id).toBeFalsy();
|
|
53
|
+
expect((0, _getCollectionPageActiveId.default)('parents.children', FORM_DATA)).toBeTruthy();
|
|
54
|
+
expect((0, _getCollectionPageActiveId.default)('parents.children', FORM_DATA) === '2').toBeFalsy();
|
|
55
|
+
});
|
|
56
|
+
it('should do nothing if an entry with the given id does not exist', function () {
|
|
57
|
+
var _FORM_DATA2, _expect$toEqual;
|
|
58
|
+
var FORM_DATA = (_FORM_DATA2 = {}, _defineProperty(_FORM_DATA2, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA2, COLLECTION_NAME, [OBJ]), _FORM_DATA2);
|
|
59
|
+
;
|
|
60
|
+
(0, _duplicateCollectionPageEntry.default)(COLLECTION_NAME, FORM_DATA, '0');
|
|
61
|
+
expect(FORM_DATA).toEqual((_expect$toEqual = {}, _defineProperty(_expect$toEqual, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_expect$toEqual, COLLECTION_NAME, [OBJ]), _expect$toEqual));
|
|
62
|
+
});
|
|
63
|
+
it('should do nothing if the collection does not exist', function () {
|
|
64
|
+
var FORM_DATA = {};
|
|
65
|
+
(0, _duplicateCollectionPageEntry.default)(COLLECTION_NAME, FORM_DATA, '1');
|
|
66
|
+
expect(FORM_DATA).toEqual({});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
+
/**
|
|
14
|
+
* Generates a new renderable page configuration containing just the components specified in the config.
|
|
15
|
+
* Page is intended for rendering within a CollectionSummarys QuickEdit section.
|
|
16
|
+
* @param {object} config object specifying which components should be rendered, may extend in the future to allow futher configuration
|
|
17
|
+
* Expected object structure:
|
|
18
|
+
* {
|
|
19
|
+
"components": [
|
|
20
|
+
{
|
|
21
|
+
"use": "exampleComponent"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"use": "exampleComponent2"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
* @param {array} pages all the pages in the form
|
|
29
|
+
* @returns Page suitble for rendering in a QuickEdit
|
|
30
|
+
*/
|
|
31
|
+
var getQuickEditPage = function getQuickEditPage(config, pages, entryData) {
|
|
32
|
+
if (!config || !pages) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Create array of full component definitions
|
|
37
|
+
var components = config.components;
|
|
38
|
+
var componentsRaised = components.map(function (component) {
|
|
39
|
+
return component.use;
|
|
40
|
+
});
|
|
41
|
+
var fullComponents = [];
|
|
42
|
+
pages.forEach(function (page) {
|
|
43
|
+
var _page$components;
|
|
44
|
+
(_page$components = page.components) === null || _page$components === void 0 ? void 0 : _page$components.forEach(function (component) {
|
|
45
|
+
if (componentsRaised.includes(component.id)) {
|
|
46
|
+
var providedConfig = components.find(function (c) {
|
|
47
|
+
return c.use === component.id;
|
|
48
|
+
});
|
|
49
|
+
fullComponents.push(_objectSpread(_objectSpread({}, component), providedConfig));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Put components and actions onto page object
|
|
55
|
+
var pageToReturn = _objectSpread({}, pages[0]);
|
|
56
|
+
pageToReturn.components = fullComponents;
|
|
57
|
+
pageToReturn.actions = [{
|
|
58
|
+
type: 'save',
|
|
59
|
+
label: 'Save',
|
|
60
|
+
validate: true,
|
|
61
|
+
classModifiers: 'primary'
|
|
62
|
+
}, {
|
|
63
|
+
type: 'cancel',
|
|
64
|
+
label: 'Cancel',
|
|
65
|
+
classModifiers: 'secondary'
|
|
66
|
+
}];
|
|
67
|
+
|
|
68
|
+
// Need to have the collection data at the top level
|
|
69
|
+
pageToReturn.formData = _objectSpread(_objectSpread({}, pageToReturn.formData), entryData);
|
|
70
|
+
delete pageToReturn.title;
|
|
71
|
+
return pageToReturn;
|
|
72
|
+
};
|
|
73
|
+
var _default = getQuickEditPage;
|
|
74
|
+
exports.default = _default;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getQuickEditPage = _interopRequireDefault(require("./getQuickEditPage"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
6
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
10
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
11
|
+
describe('Utils.CollectionPage.getQuickEditPage', function () {
|
|
12
|
+
var pages = [{
|
|
13
|
+
id: 'parentPage',
|
|
14
|
+
name: 'parentPage',
|
|
15
|
+
title: 'Parent',
|
|
16
|
+
collection: {
|
|
17
|
+
name: 'parents',
|
|
18
|
+
labels: {
|
|
19
|
+
item: 'Parent'
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
components: [{
|
|
23
|
+
id: 'testText',
|
|
24
|
+
type: 'text',
|
|
25
|
+
label: 'Test text',
|
|
26
|
+
fieldId: 'testText',
|
|
27
|
+
required: true,
|
|
28
|
+
use: 'testText',
|
|
29
|
+
cya_label: 'Test text',
|
|
30
|
+
full_path: 'testText'
|
|
31
|
+
}],
|
|
32
|
+
formData: {
|
|
33
|
+
businessKey: 'DEV-20230915-705',
|
|
34
|
+
parentsActiveId: '1694777136455',
|
|
35
|
+
id: '1694777136455',
|
|
36
|
+
parents: [{
|
|
37
|
+
id: '1694777136455',
|
|
38
|
+
testText: 'test'
|
|
39
|
+
}]
|
|
40
|
+
},
|
|
41
|
+
index: 1
|
|
42
|
+
}];
|
|
43
|
+
var config = {
|
|
44
|
+
components: [{
|
|
45
|
+
use: 'testText'
|
|
46
|
+
}]
|
|
47
|
+
};
|
|
48
|
+
var expectedOutput = {
|
|
49
|
+
id: 'parentPage',
|
|
50
|
+
name: 'parentPage',
|
|
51
|
+
collection: {
|
|
52
|
+
name: 'parents',
|
|
53
|
+
labels: {
|
|
54
|
+
item: 'Parent'
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
components: [{
|
|
58
|
+
id: 'testText',
|
|
59
|
+
type: 'text',
|
|
60
|
+
label: 'Test text',
|
|
61
|
+
fieldId: 'testText',
|
|
62
|
+
required: true,
|
|
63
|
+
use: 'testText',
|
|
64
|
+
cya_label: 'Test text',
|
|
65
|
+
full_path: 'testText'
|
|
66
|
+
}],
|
|
67
|
+
formData: {
|
|
68
|
+
businessKey: 'DEV-20230915-705',
|
|
69
|
+
parentsActiveId: '1694777136455',
|
|
70
|
+
id: '1694777136455',
|
|
71
|
+
parents: [{
|
|
72
|
+
id: '1694777136455',
|
|
73
|
+
testText: 'test'
|
|
74
|
+
}],
|
|
75
|
+
testText: 'test'
|
|
76
|
+
},
|
|
77
|
+
index: 1,
|
|
78
|
+
actions: [{
|
|
79
|
+
type: 'save',
|
|
80
|
+
label: 'Save',
|
|
81
|
+
validate: true,
|
|
82
|
+
classModifiers: 'primary'
|
|
83
|
+
}, {
|
|
84
|
+
type: 'cancel',
|
|
85
|
+
label: 'Cancel',
|
|
86
|
+
classModifiers: 'secondary'
|
|
87
|
+
}]
|
|
88
|
+
};
|
|
89
|
+
it('should return a quick edit page', function () {
|
|
90
|
+
var createdPage = (0, _getQuickEditPage.default)(config, pages, {
|
|
91
|
+
testText: 'test'
|
|
92
|
+
});
|
|
93
|
+
expect(createdPage).toEqual(expectedOutput);
|
|
94
|
+
});
|
|
95
|
+
it('should return a quick edit page with overridden component properties', function () {
|
|
96
|
+
var configWithOverride = {
|
|
97
|
+
components: [{
|
|
98
|
+
use: 'testText',
|
|
99
|
+
label: 'override'
|
|
100
|
+
}]
|
|
101
|
+
};
|
|
102
|
+
var createdPage = (0, _getQuickEditPage.default)(configWithOverride, pages, {
|
|
103
|
+
testText: 'test'
|
|
104
|
+
});
|
|
105
|
+
var expectedOutputOverride = _objectSpread({}, expectedOutput);
|
|
106
|
+
expectedOutputOverride.components[0].label = 'override';
|
|
107
|
+
expect(createdPage).toEqual(expectedOutput);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _addCollectionPageEntry = _interopRequireDefault(require("./addCollectionPageEntry"));
|
|
8
8
|
var _duplicateCollectionPageActiveEntry = _interopRequireDefault(require("./duplicateCollectionPageActiveEntry"));
|
|
9
|
+
var _duplicateCollectionPageEntry = _interopRequireDefault(require("./duplicateCollectionPageEntry"));
|
|
9
10
|
var _getCollectionPageActiveId = _interopRequireDefault(require("./getCollectionPageActiveId"));
|
|
10
11
|
var _getCollectionPageActiveIndex = _interopRequireDefault(require("./getCollectionPageActiveIndex"));
|
|
11
12
|
var _getCollectionPageData = _interopRequireDefault(require("./getCollectionPageData"));
|
|
12
13
|
var _mergeCollectionPages = _interopRequireDefault(require("./mergeCollectionPages"));
|
|
14
|
+
var _removeCollectionPageEntry = _interopRequireDefault(require("./removeCollectionPageEntry"));
|
|
13
15
|
var _setCollectionPageData = _interopRequireDefault(require("./setCollectionPageData"));
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
// Local imports
|
|
@@ -17,10 +19,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
19
|
var CollectionPage = {
|
|
18
20
|
addEntry: _addCollectionPageEntry.default,
|
|
19
21
|
duplicateActiveEntry: _duplicateCollectionPageActiveEntry.default,
|
|
22
|
+
duplicateEntry: _duplicateCollectionPageEntry.default,
|
|
20
23
|
getActiveId: _getCollectionPageActiveId.default,
|
|
21
24
|
getActiveIndex: _getCollectionPageActiveIndex.default,
|
|
22
25
|
getData: _getCollectionPageData.default,
|
|
23
26
|
mergePages: _mergeCollectionPages.default,
|
|
27
|
+
removeEntry: _removeCollectionPageEntry.default,
|
|
24
28
|
setData: _setCollectionPageData.default
|
|
25
29
|
};
|
|
26
30
|
var _default = CollectionPage;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _getCollectionPageData = _interopRequireDefault(require("./getCollectionPageData"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
// Local imports.
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Removes an entry with a given id from a collection.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} collectionName The name of the collection to delete the entry from.
|
|
15
|
+
* @param {object} formData The top-level formData object.
|
|
16
|
+
* @param {string} id The id of the entry to be deleted.
|
|
17
|
+
* @returns null if the target entry could not be deleted.
|
|
18
|
+
* The deleted entry if it was deleted successfully.
|
|
19
|
+
*/
|
|
20
|
+
var removeCollectionPageEntry = function removeCollectionPageEntry(collectionName, formData, id) {
|
|
21
|
+
var collectionData = (0, _getCollectionPageData.default)(collectionName, formData);
|
|
22
|
+
if (!collectionData) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
var indexToDelete = collectionData.findIndex(function (entry) {
|
|
26
|
+
return entry.id === id;
|
|
27
|
+
});
|
|
28
|
+
if (indexToDelete === -1) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
var deletedEntry = collectionData[indexToDelete];
|
|
32
|
+
collectionData.splice(indexToDelete, 1);
|
|
33
|
+
return deletedEntry;
|
|
34
|
+
};
|
|
35
|
+
var _default = removeCollectionPageEntry;
|
|
36
|
+
exports.default = _default;
|