@ukhomeoffice/cop-react-form-renderer 5.0.0-alpha → 5.0.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/CheckYourAnswers/Answer.js +18 -7
- package/dist/components/CheckYourAnswers/Answer.test.js +137 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +70 -46
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +410 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +551 -0
- package/dist/components/CollectionPage/CollectionPage.js +15 -10
- package/dist/components/CollectionPage/CollectionPage.test.js +382 -0
- package/dist/components/FormComponent/Collection.js +91 -48
- package/dist/components/FormComponent/Collection.scss +2 -1
- package/dist/components/FormComponent/Collection.test.js +807 -0
- package/dist/components/FormComponent/Container.js +35 -16
- package/dist/components/FormComponent/Container.test.js +370 -0
- package/dist/components/FormComponent/FormComponent.js +39 -13
- package/dist/components/FormComponent/FormComponent.stories.mdx +184 -0
- package/dist/components/FormComponent/FormComponent.test.js +226 -0
- package/dist/components/FormComponent/helpers/addLabel.js +5 -4
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +16 -0
- package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +29 -0
- package/dist/components/FormComponent/helpers/index.js +8 -1
- package/dist/components/FormPage/FormPage.js +69 -30
- package/dist/components/FormPage/FormPage.stories.mdx +155 -0
- package/dist/components/FormPage/FormPage.test.js +330 -0
- package/dist/components/FormRenderer/FormRenderer.js +142 -228
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +183 -0
- package/dist/components/FormRenderer/FormRenderer.test.js +968 -0
- package/dist/components/FormRenderer/handlers/index.js +1 -2
- package/dist/components/FormRenderer/handlers/navigate.js +3 -1
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +35 -14
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +88 -5
- package/dist/components/FormRenderer/helpers/getCYA.js +11 -2
- package/dist/components/FormRenderer/helpers/getNextPageId.js +13 -7
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +10 -2
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +2 -2
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +6 -2
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +171 -51
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +307 -24
- package/dist/components/FormRenderer/helpers/index.js +1 -2
- package/dist/components/FormRenderer/onCYAAction.js +108 -0
- package/dist/components/FormRenderer/onCYAAction.test.js +583 -0
- package/dist/components/FormRenderer/onPageAction.js +145 -0
- package/dist/components/FormRenderer/onPageAction.test.js +678 -0
- package/dist/components/FormRenderer/onTaskAction.js +48 -0
- package/dist/components/FormRenderer/onTaskAction.test.js +217 -0
- package/dist/components/PageActions/ActionButton.js +0 -3
- package/dist/components/PageActions/ActionButton.test.js +93 -0
- package/dist/components/PageActions/PageActions.js +2 -2
- package/dist/components/PageActions/PageActions.stories.mdx +74 -0
- package/dist/components/PageActions/PageActions.test.js +132 -0
- package/dist/components/SummaryList/GroupAction.js +2 -2
- package/dist/components/SummaryList/GroupAction.test.js +80 -0
- package/dist/components/SummaryList/RowAction.js +2 -2
- package/dist/components/SummaryList/RowAction.test.js +80 -0
- package/dist/components/SummaryList/SummaryList.js +29 -12
- package/dist/components/SummaryList/SummaryList.scss +19 -0
- package/dist/components/SummaryList/SummaryList.stories.mdx +90 -0
- package/dist/components/SummaryList/SummaryList.test.js +400 -0
- package/dist/components/SummaryList/SummaryListHeadingRow.js +30 -0
- package/dist/components/SummaryList/SummaryListRow.js +5 -2
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +2 -1
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -1
- package/dist/components/TaskList/Task.js +3 -3
- package/dist/components/TaskList/Task.test.js +167 -0
- package/dist/components/TaskList/TaskList.js +73 -22
- package/dist/components/TaskList/TaskList.stories.mdx +164 -0
- package/dist/components/TaskList/TaskList.test.js +389 -0
- package/dist/components/TaskList/TaskState.js +2 -2
- package/dist/components/TaskList/TaskState.test.js +86 -0
- package/dist/components/index.js +14 -0
- package/dist/context/HooksContext/HooksContext.js +72 -8
- package/dist/context/HooksContext/HooksContext.test.js +44 -0
- package/dist/context/ValidationContext/ValidationContext.js +38 -28
- package/dist/context/ValidationContext/ValidationContext.test.js +84 -0
- package/dist/hooks/useAxios.js +10 -12
- package/dist/hooks/useGetRequest.js +48 -49
- package/dist/hooks/useRefData.js +7 -4
- package/dist/index.js +34 -1
- package/dist/json/addressDetails.json +149 -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/group.data.json +21 -0
- package/dist/json/group.json +402 -0
- package/dist/json/groupOfRow.json +137 -0
- package/dist/json/groupOfRowData.json +15 -0
- package/dist/json/port.json +346 -0
- package/dist/json/saveAndContinue.json +98 -0
- package/dist/json/sublocation.json +859 -0
- package/dist/json/taskList.json +265 -0
- package/dist/json/team.json +17351 -0
- package/dist/json/terminal.json +81 -0
- package/dist/json/userProfile.data.json +21 -0
- package/dist/json/userProfile.json +276 -0
- package/dist/models/ComponentTypes.js +8 -0
- package/dist/models/PageAction.js +4 -1
- package/dist/models/TaskStates.js +10 -2
- package/dist/models/index.js +16 -1
- package/dist/setupTests.js +46 -0
- package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +121 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +6 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +71 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +6 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +55 -0
- package/dist/utils/CheckYourAnswers/getCYARow.js +14 -11
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +291 -0
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +4 -1
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +70 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +15 -10
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +288 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +94 -36
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +414 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +21 -7
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +486 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -3
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +346 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +19 -3
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +143 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +5 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +40 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +53 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +25 -17
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +130 -0
- package/dist/utils/Component/addShowWhen.js +44 -0
- package/dist/utils/Component/addShowWhen.test.js +216 -0
- package/dist/utils/Component/applyToComponentTree.js +71 -0
- package/dist/utils/Component/applyToComponentTree.test.js +127 -0
- package/dist/utils/Component/cleanAttributes.js +8 -2
- package/dist/utils/Component/cleanAttributes.test.js +68 -0
- package/dist/utils/Component/elevateNestedComponents.js +4 -1
- package/dist/utils/Component/elevateNestedComponents.test.js +122 -0
- package/dist/utils/Component/getComponent.js +80 -11
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +4 -4
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +25 -24
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +66 -5
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +9 -7
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +44 -0
- package/dist/utils/Component/getComponentTests/{getComponent.textarea.test.js → getComponent.multifile.test.js} +29 -21
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +159 -83
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +43 -0
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +55 -5
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +3 -9
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +109 -0
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +7 -7
- package/dist/utils/Component/getDefaultValue.js +4 -1
- package/dist/utils/Component/getDefaultValue.test.js +50 -0
- package/dist/utils/Component/index.js +2 -0
- package/dist/utils/Component/isEditable.js +2 -2
- package/dist/utils/Component/isEditable.test.js +43 -0
- package/dist/utils/Component/optionIsSelected.js +22 -0
- package/dist/utils/Component/optionIsSelected.test.js +42 -0
- package/dist/utils/Component/setupContainerComponentsPath.js +40 -0
- package/dist/utils/Component/setupContainerComponentsPath.test.js +78 -0
- package/dist/utils/Component/showComponent.test.js +156 -0
- package/dist/utils/Component/wrapInFormGroup.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.test.js +61 -0
- package/dist/utils/Condition/meetsCondition.js +74 -4
- package/dist/utils/Condition/meetsCondition.test.js +763 -0
- package/dist/utils/Condition/meetsOneCondition.js +1 -1
- package/dist/utils/Condition/meetsOneCondition.test.js +100 -0
- package/dist/utils/Condition/setupConditions.js +6 -3
- package/dist/utils/Condition/setupConditions.test.js +33 -0
- package/dist/utils/Container/getEditableComponents.test.js +135 -0
- package/dist/utils/Container/setupNesting.js +21 -2
- package/dist/utils/Container/setupNesting.test.js +145 -0
- package/dist/utils/Container/showContainer.test.js +178 -0
- package/dist/utils/Data/applyFormula.js +20 -11
- package/dist/utils/Data/applyFormula.test.js +263 -0
- package/dist/utils/Data/getAutocompleteSource.js +6 -2
- package/dist/utils/Data/getAutocompleteSource.test.js +352 -0
- package/dist/utils/Data/getDataPath.test.js +48 -0
- package/dist/utils/Data/getOptions.js +17 -3
- package/dist/utils/Data/getOptions.test.js +140 -0
- package/dist/utils/Data/getSourceData.js +2 -2
- package/dist/utils/Data/getSourceData.test.js +153 -0
- package/dist/utils/Data/refDataToOptions.js +4 -1
- package/dist/utils/Data/refDataToOptions.test.js +196 -0
- package/dist/utils/Data/setDataItem.test.js +110 -0
- package/dist/utils/Data/setupFormData.js +39 -16
- package/dist/utils/Data/setupFormData.test.js +410 -0
- package/dist/utils/Data/setupRefDataUrlForComponent.js +4 -1
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +131 -0
- package/dist/utils/FormPage/applyConditionalProperties.js +35 -0
- package/dist/utils/FormPage/applyConditionalProperties.test.js +61 -0
- package/dist/utils/FormPage/getFormPage.js +5 -2
- package/dist/utils/FormPage/getFormPage.test.js +206 -0
- package/dist/utils/FormPage/getFormPages.js +4 -1
- package/dist/utils/FormPage/getFormPages.test.js +97 -0
- package/dist/utils/FormPage/getPageActions.js +8 -4
- package/dist/utils/FormPage/getPageActions.test.js +114 -0
- package/dist/utils/FormPage/getParagraphFromText.test.js +27 -0
- package/dist/utils/FormPage/index.js +2 -0
- package/dist/utils/FormPage/showFormPage.js +2 -2
- package/dist/utils/FormPage/showFormPage.test.js +180 -0
- package/dist/utils/FormPage/showFormPageCYA.js +1 -0
- package/dist/utils/FormPage/showFormPageCYA.test.js +28 -0
- package/dist/utils/FormPage/useComponent.js +29 -14
- package/dist/utils/FormPage/useComponent.test.js +167 -0
- package/dist/utils/Format/formatData.test.js +45 -0
- package/dist/utils/Format/formatDataForComponent.js +2 -1
- package/dist/utils/Format/formatDataForComponent.test.js +142 -0
- package/dist/utils/Format/formatDataForForm.js +4 -1
- package/dist/utils/Format/formatDataForForm.test.js +81 -0
- package/dist/utils/Format/formatDataForPage.test.js +99 -0
- package/dist/utils/Hub/getFormHub.test.js +105 -0
- package/dist/utils/Meta/documents/getDocuments.test.js +4 -1
- package/dist/utils/Meta/documents/index.js +2 -2
- package/dist/utils/Meta/documents/setDocumentsForField.js +31 -0
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +59 -0
- package/dist/utils/Operate/checkValueIsTruthy.test.js +42 -0
- package/dist/utils/Operate/getFirstOf.js +31 -0
- package/dist/utils/Operate/getFirstOf.test.js +86 -0
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +163 -0
- package/dist/utils/Operate/persistValueInFormData.js +2 -1
- package/dist/utils/Operate/persistValueInFormData.test.js +115 -0
- package/dist/utils/Operate/runPageOperations.js +3 -1
- package/dist/utils/Operate/runPageOperations.test.js +105 -0
- package/dist/utils/Operate/setValueInFormData.test.js +44 -0
- package/dist/utils/Operate/shouldRun.js +16 -13
- package/dist/utils/Operate/shouldRun.test.js +66 -0
- package/dist/utils/Validate/additional/conditionallyRequired.js +24 -0
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +73 -0
- package/dist/utils/Validate/additional/index.js +13 -4
- package/dist/utils/Validate/additional/mustBeAfter.js +8 -6
- package/dist/utils/Validate/additional/mustBeAfter.test.js +15 -1
- package/dist/utils/Validate/additional/mustBeBefore.js +9 -5
- package/dist/utils/Validate/additional/mustBeBefore.test.js +14 -0
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +1 -1
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +6 -3
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +22 -0
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +56 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +1 -1
- package/dist/utils/Validate/additional/mustBeInThePast.js +5 -5
- package/dist/utils/Validate/additional/mustBeLessThan.js +7 -6
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +11 -1
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +9 -5
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +10 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +1 -0
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +4 -1
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +19 -0
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +36 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +29 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +52 -0
- package/dist/utils/Validate/additional/utils.js +18 -18
- package/dist/utils/Validate/index.js +6 -0
- package/dist/utils/Validate/validateCollection.js +20 -5
- package/dist/utils/Validate/validateCollection.test.js +125 -0
- package/dist/utils/Validate/validateComponent.js +36 -20
- package/dist/utils/Validate/validateComponent.test.js +365 -0
- package/dist/utils/Validate/validateContainer.js +9 -3
- package/dist/utils/Validate/validateContainer.test.js +75 -0
- package/dist/utils/Validate/validateDate.js +4 -3
- package/dist/utils/Validate/validateDate.test.js +114 -0
- package/dist/utils/Validate/validateEmail.js +14 -1
- package/dist/utils/Validate/validateEmail.test.js +74 -0
- package/dist/utils/Validate/validateMultifile.js +32 -0
- package/dist/utils/Validate/validateMultifile.test.js +47 -0
- package/dist/utils/Validate/validatePage.js +12 -6
- package/dist/utils/Validate/validatePage.test.js +472 -0
- package/dist/utils/Validate/validateRegex.js +2 -5
- package/dist/utils/Validate/validateRegex.test.js +42 -0
- package/dist/utils/Validate/validateRequired.js +2 -4
- package/dist/utils/Validate/validateRequired.test.js +63 -0
- package/dist/utils/Validate/validateTextArea.js +37 -0
- package/dist/utils/Validate/validateTextArea.test.js +42 -0
- package/dist/utils/Validate/validateTime.js +2 -2
- package/dist/utils/Validate/validateTime.test.js +59 -0
- package/dist/utils/index.js +4 -1
- package/package.json +35 -50
- package/dist/utils/Meta/documents/setDocumentForField.js +0 -29
- package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -49
|
@@ -4,28 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
8
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
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
|
+
/* eslint-disable no-param-reassign */
|
|
14
|
+
|
|
12
15
|
var createMasterPage = function createMasterPage(page) {
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
return {
|
|
17
|
+
id: page.id,
|
|
18
|
+
name: page.name,
|
|
19
|
+
collection: _objectSpread({
|
|
20
|
+
masterPage: true
|
|
21
|
+
}, page.collection),
|
|
22
|
+
formData: _objectSpread({}, page.formData),
|
|
23
|
+
collectionPages: [page]
|
|
24
|
+
};
|
|
16
25
|
};
|
|
17
26
|
var mergeIntoMasterPage = function mergeIntoMasterPage(page, masterPage) {
|
|
18
27
|
masterPage.collection = _objectSpread(_objectSpread({}, masterPage.collection), page.collection);
|
|
19
|
-
masterPage.
|
|
20
|
-
masterPage.
|
|
28
|
+
masterPage.formData = _objectSpread(_objectSpread({}, masterPage.formData), page.formData);
|
|
29
|
+
masterPage.collectionPages = [].concat(masterPage.collectionPages, [page]);
|
|
21
30
|
};
|
|
22
31
|
|
|
23
32
|
/**
|
|
24
33
|
* Loop over an array of pages, merging any CollectionPages into a
|
|
25
34
|
* single master page for that collection. A master page is created
|
|
26
35
|
* for each unique collection.name that exists.
|
|
27
|
-
* These master pages contain all the
|
|
28
|
-
*
|
|
36
|
+
* These master pages contain all the pages that are needed to
|
|
37
|
+
* represent an item in that collection.
|
|
29
38
|
* The master page for each collection is positioned at the index
|
|
30
39
|
* of the first CollectionPage in that collection.
|
|
31
40
|
* @param { array } pages Array of pages in the form.
|
|
@@ -35,19 +44,18 @@ var mergeCollectionPages = function mergeCollectionPages(pages) {
|
|
|
35
44
|
var masterPages = {};
|
|
36
45
|
return pages.map(function (page) {
|
|
37
46
|
var _page$collection;
|
|
38
|
-
if ((_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name
|
|
47
|
+
if (page !== null && page !== void 0 && (_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name) {
|
|
39
48
|
if (!masterPages[page.collection.name]) {
|
|
40
49
|
// If no master page exists for this collection.name, then
|
|
41
50
|
// we kick one off using this page as a template.
|
|
42
51
|
masterPages[page.collection.name] = createMasterPage(page);
|
|
43
52
|
return masterPages[page.collection.name];
|
|
44
|
-
} else {
|
|
45
|
-
// If a master page already exists for this collection.name
|
|
46
|
-
// then we just merge this page into it and remove this page
|
|
47
|
-
// from the array.
|
|
48
|
-
mergeIntoMasterPage(page, masterPages[page.collection.name]);
|
|
49
|
-
return null;
|
|
50
53
|
}
|
|
54
|
+
// If a master page already exists for this collection.name
|
|
55
|
+
// then we just merge this page into it and remove this page
|
|
56
|
+
// from the array.
|
|
57
|
+
mergeIntoMasterPage(page, masterPages[page.collection.name]);
|
|
58
|
+
return null;
|
|
51
59
|
}
|
|
52
60
|
return page;
|
|
53
61
|
}).filter(function (page) {
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _mergeCollectionPages = _interopRequireDefault(require("./mergeCollectionPages"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
// Local imports
|
|
6
|
+
|
|
7
|
+
describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
8
|
+
var TEXT_COMP = {
|
|
9
|
+
id: 'testText',
|
|
10
|
+
fieldId: 'testText',
|
|
11
|
+
type: 'text'
|
|
12
|
+
};
|
|
13
|
+
var DATE_COMP = {
|
|
14
|
+
id: 'testDate',
|
|
15
|
+
fieldId: 'testDate',
|
|
16
|
+
type: 'date'
|
|
17
|
+
};
|
|
18
|
+
it('should return the same array if no pages belong to collections', function () {
|
|
19
|
+
var PAGES = [{
|
|
20
|
+
id: 'page1'
|
|
21
|
+
}, {
|
|
22
|
+
id: 'page2'
|
|
23
|
+
}];
|
|
24
|
+
expect((0, _mergeCollectionPages.default)(PAGES)).toEqual(PAGES);
|
|
25
|
+
});
|
|
26
|
+
it('should merge pages from the same collection into a single page', function () {
|
|
27
|
+
var PAGES = [{
|
|
28
|
+
id: 'page1',
|
|
29
|
+
collection: {
|
|
30
|
+
name: 'collection'
|
|
31
|
+
},
|
|
32
|
+
components: [TEXT_COMP]
|
|
33
|
+
}, {
|
|
34
|
+
id: 'page2',
|
|
35
|
+
collection: {
|
|
36
|
+
name: 'collection'
|
|
37
|
+
},
|
|
38
|
+
components: [DATE_COMP]
|
|
39
|
+
}];
|
|
40
|
+
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
41
|
+
expect(RESULT.length).toEqual(1);
|
|
42
|
+
expect(RESULT[0]).toMatchObject({
|
|
43
|
+
id: 'page1',
|
|
44
|
+
collection: {
|
|
45
|
+
name: 'collection',
|
|
46
|
+
masterPage: true
|
|
47
|
+
},
|
|
48
|
+
formData: {},
|
|
49
|
+
collectionPages: PAGES
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it('should leave non-collection pages unaffected', function () {
|
|
53
|
+
var PAGES = [{
|
|
54
|
+
id: 'page1',
|
|
55
|
+
collection: {
|
|
56
|
+
name: 'collection'
|
|
57
|
+
},
|
|
58
|
+
components: [TEXT_COMP]
|
|
59
|
+
}, {
|
|
60
|
+
id: 'page2',
|
|
61
|
+
collection: {
|
|
62
|
+
name: 'collection'
|
|
63
|
+
},
|
|
64
|
+
components: [DATE_COMP]
|
|
65
|
+
}, {
|
|
66
|
+
id: 'page3'
|
|
67
|
+
}];
|
|
68
|
+
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
69
|
+
expect(RESULT.length).toEqual(2);
|
|
70
|
+
expect(RESULT[0]).toEqual({
|
|
71
|
+
id: 'page1',
|
|
72
|
+
collection: {
|
|
73
|
+
name: 'collection',
|
|
74
|
+
masterPage: true
|
|
75
|
+
},
|
|
76
|
+
formData: {},
|
|
77
|
+
collectionPages: [PAGES[0], PAGES[1]]
|
|
78
|
+
});
|
|
79
|
+
expect(RESULT[1]).toEqual({
|
|
80
|
+
id: 'page3'
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
it('should handle multiple collections', function () {
|
|
84
|
+
var PAGES = [{
|
|
85
|
+
id: 'page1',
|
|
86
|
+
collection: {
|
|
87
|
+
name: 'collection1'
|
|
88
|
+
},
|
|
89
|
+
components: []
|
|
90
|
+
}, {
|
|
91
|
+
id: 'page2',
|
|
92
|
+
collection: {
|
|
93
|
+
name: 'collection1'
|
|
94
|
+
},
|
|
95
|
+
components: []
|
|
96
|
+
}, {
|
|
97
|
+
id: 'page3',
|
|
98
|
+
collection: {
|
|
99
|
+
name: 'collection2'
|
|
100
|
+
},
|
|
101
|
+
components: []
|
|
102
|
+
}, {
|
|
103
|
+
id: 'page4',
|
|
104
|
+
collection: {
|
|
105
|
+
name: 'collection2'
|
|
106
|
+
},
|
|
107
|
+
components: []
|
|
108
|
+
}];
|
|
109
|
+
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
110
|
+
expect(RESULT.length).toEqual(2);
|
|
111
|
+
expect(RESULT[0]).toEqual({
|
|
112
|
+
id: 'page1',
|
|
113
|
+
collection: {
|
|
114
|
+
name: 'collection1',
|
|
115
|
+
masterPage: true
|
|
116
|
+
},
|
|
117
|
+
formData: {},
|
|
118
|
+
collectionPages: [PAGES[0], PAGES[1]]
|
|
119
|
+
});
|
|
120
|
+
expect(RESULT[1]).toEqual({
|
|
121
|
+
id: 'page3',
|
|
122
|
+
collection: {
|
|
123
|
+
name: 'collection2',
|
|
124
|
+
masterPage: true
|
|
125
|
+
},
|
|
126
|
+
formData: {},
|
|
127
|
+
collectionPages: [PAGES[2], PAGES[3]]
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
8
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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
|
+
* Adds a show_when to a component.
|
|
15
|
+
* If the component has no show_when, then an array is created
|
|
16
|
+
* with condition as the only entry.
|
|
17
|
+
* If the component has existing show_whens then condition is
|
|
18
|
+
* appended to the existing array.
|
|
19
|
+
* @param {*} component The component to add the show_when to.
|
|
20
|
+
* @param {*} condition The show_when condition to add.
|
|
21
|
+
* @returns The component with the new show_when added.
|
|
22
|
+
* null if component or condition are invalid.
|
|
23
|
+
*/
|
|
24
|
+
var addShowWhen = function addShowWhen(component, condition) {
|
|
25
|
+
if (!component) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
if (!condition) {
|
|
29
|
+
return component;
|
|
30
|
+
}
|
|
31
|
+
var result = _objectSpread({}, component);
|
|
32
|
+
if (result.show_when) {
|
|
33
|
+
if (Array.isArray(condition)) {
|
|
34
|
+
result.show_when = Array.isArray(result.show_when) ? [].concat(condition, result.show_when) : [].concat(condition, [result.show_when]);
|
|
35
|
+
} else {
|
|
36
|
+
result.show_when = Array.isArray(result.show_when) ? [].concat(result.show_when, [condition]) : [result.show_when, condition];
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
result.show_when = condition;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
var _default = addShowWhen;
|
|
44
|
+
exports.default = _default;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _addShowWhen = _interopRequireDefault(require("./addShowWhen"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
// Local imports
|
|
6
|
+
|
|
7
|
+
describe('utils.Component.addShowWhen', function () {
|
|
8
|
+
var NEW_SHOW_WHEN = {
|
|
9
|
+
field: 'field',
|
|
10
|
+
op: '=',
|
|
11
|
+
value: 'value'
|
|
12
|
+
};
|
|
13
|
+
it('should return null when component is undefined', function () {
|
|
14
|
+
var result = (0, _addShowWhen.default)(undefined, {});
|
|
15
|
+
expect(result).toEqual(null);
|
|
16
|
+
});
|
|
17
|
+
it('should return null when component is null', function () {
|
|
18
|
+
var result = (0, _addShowWhen.default)(null, {});
|
|
19
|
+
expect(result).toEqual(null);
|
|
20
|
+
});
|
|
21
|
+
it('should return component when condition is undefined', function () {
|
|
22
|
+
var COMPONENT = {
|
|
23
|
+
alpha: 'bravo'
|
|
24
|
+
};
|
|
25
|
+
var result = (0, _addShowWhen.default)(COMPONENT, undefined);
|
|
26
|
+
expect(result).toEqual({
|
|
27
|
+
alpha: 'bravo'
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it('should return component when condition is null', function () {
|
|
31
|
+
var COMPONENT = {
|
|
32
|
+
alpha: 'bravo'
|
|
33
|
+
};
|
|
34
|
+
var result = (0, _addShowWhen.default)(COMPONENT, null);
|
|
35
|
+
expect(result).toEqual({
|
|
36
|
+
alpha: 'bravo'
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it('should add the show_when to a component with no existing show_whens', function () {
|
|
40
|
+
var COMPONENT = {
|
|
41
|
+
alpha: 'bravo'
|
|
42
|
+
};
|
|
43
|
+
var result = (0, _addShowWhen.default)(COMPONENT, NEW_SHOW_WHEN);
|
|
44
|
+
expect(result).toEqual({
|
|
45
|
+
alpha: 'bravo',
|
|
46
|
+
show_when: NEW_SHOW_WHEN
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
it('should add the array type show_when to a component with no existing show_whens', function () {
|
|
50
|
+
var NEW_ARRAY_SHOW_WHEN = [{
|
|
51
|
+
field: 'abc',
|
|
52
|
+
op: '=',
|
|
53
|
+
value: 'bcd'
|
|
54
|
+
}, {
|
|
55
|
+
field: 'cde',
|
|
56
|
+
op: '=',
|
|
57
|
+
value: 'efg'
|
|
58
|
+
}];
|
|
59
|
+
var COMPONENT = {
|
|
60
|
+
alpha: 'bravo'
|
|
61
|
+
};
|
|
62
|
+
var result = (0, _addShowWhen.default)(COMPONENT, NEW_ARRAY_SHOW_WHEN);
|
|
63
|
+
expect(result).toEqual({
|
|
64
|
+
alpha: 'bravo',
|
|
65
|
+
show_when: NEW_ARRAY_SHOW_WHEN
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
it('should add the show_when to a component with a single show_when', function () {
|
|
69
|
+
var COMPONENT = {
|
|
70
|
+
alpha: 'bravo',
|
|
71
|
+
show_when: {
|
|
72
|
+
field: 'abc',
|
|
73
|
+
op: '=',
|
|
74
|
+
value: 'bcd'
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var result = (0, _addShowWhen.default)(COMPONENT, NEW_SHOW_WHEN);
|
|
78
|
+
expect(result).toEqual({
|
|
79
|
+
alpha: 'bravo',
|
|
80
|
+
show_when: [{
|
|
81
|
+
field: 'abc',
|
|
82
|
+
op: '=',
|
|
83
|
+
value: 'bcd'
|
|
84
|
+
}, NEW_SHOW_WHEN]
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('should add the show_when to a component with an array of show_whens', function () {
|
|
88
|
+
var COMPONENT = {
|
|
89
|
+
alpha: 'bravo',
|
|
90
|
+
show_when: [{
|
|
91
|
+
field: 'abc',
|
|
92
|
+
op: '=',
|
|
93
|
+
value: 'bcd'
|
|
94
|
+
}, {
|
|
95
|
+
field: 'cde',
|
|
96
|
+
op: '=',
|
|
97
|
+
value: 'efg'
|
|
98
|
+
}]
|
|
99
|
+
};
|
|
100
|
+
var result = (0, _addShowWhen.default)(COMPONENT, NEW_SHOW_WHEN);
|
|
101
|
+
expect(result).toEqual({
|
|
102
|
+
alpha: 'bravo',
|
|
103
|
+
show_when: [{
|
|
104
|
+
field: 'abc',
|
|
105
|
+
op: '=',
|
|
106
|
+
value: 'bcd'
|
|
107
|
+
}, {
|
|
108
|
+
field: 'cde',
|
|
109
|
+
op: '=',
|
|
110
|
+
value: 'efg'
|
|
111
|
+
}, NEW_SHOW_WHEN]
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
it('should add the or type show_when to a component with no existing show_whens in an object not an array', function () {
|
|
115
|
+
var COMPONENT = {
|
|
116
|
+
alpha: 'bravo'
|
|
117
|
+
};
|
|
118
|
+
var SHOW_WHEN_OR = {
|
|
119
|
+
type: 'or',
|
|
120
|
+
condition: [{
|
|
121
|
+
field: 'field1',
|
|
122
|
+
op: '=',
|
|
123
|
+
values: 1
|
|
124
|
+
}, {
|
|
125
|
+
field: 'field2',
|
|
126
|
+
op: '=',
|
|
127
|
+
value: 2
|
|
128
|
+
}]
|
|
129
|
+
};
|
|
130
|
+
var result = (0, _addShowWhen.default)(COMPONENT, SHOW_WHEN_OR);
|
|
131
|
+
expect(result).toEqual({
|
|
132
|
+
alpha: 'bravo',
|
|
133
|
+
show_when: SHOW_WHEN_OR
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
it('should add an array of show_whens to a component with an array of show_whens', function () {
|
|
137
|
+
var NEW_ARRAY_SHOW_WHEN = [{
|
|
138
|
+
field: 'hij',
|
|
139
|
+
op: '=',
|
|
140
|
+
value: 'klm'
|
|
141
|
+
}, {
|
|
142
|
+
field: 'nop',
|
|
143
|
+
op: '=',
|
|
144
|
+
value: 'qrs'
|
|
145
|
+
}];
|
|
146
|
+
var COMPONENT = {
|
|
147
|
+
alpha: 'bravo',
|
|
148
|
+
show_when: [{
|
|
149
|
+
field: 'abc',
|
|
150
|
+
op: '=',
|
|
151
|
+
value: 'bcd'
|
|
152
|
+
}, {
|
|
153
|
+
field: 'cde',
|
|
154
|
+
op: '=',
|
|
155
|
+
value: 'efg'
|
|
156
|
+
}]
|
|
157
|
+
};
|
|
158
|
+
var result = (0, _addShowWhen.default)(COMPONENT, NEW_ARRAY_SHOW_WHEN);
|
|
159
|
+
expect(result).toEqual({
|
|
160
|
+
alpha: 'bravo',
|
|
161
|
+
show_when: [{
|
|
162
|
+
field: 'hij',
|
|
163
|
+
op: '=',
|
|
164
|
+
value: 'klm'
|
|
165
|
+
}, {
|
|
166
|
+
field: 'nop',
|
|
167
|
+
op: '=',
|
|
168
|
+
value: 'qrs'
|
|
169
|
+
}, {
|
|
170
|
+
field: 'abc',
|
|
171
|
+
op: '=',
|
|
172
|
+
value: 'bcd'
|
|
173
|
+
}, {
|
|
174
|
+
field: 'cde',
|
|
175
|
+
op: '=',
|
|
176
|
+
value: 'efg'
|
|
177
|
+
}]
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
it('should add an array of show_whens to a component with a single show_when', function () {
|
|
181
|
+
var NEW_ARRAY_SHOW_WHEN = [{
|
|
182
|
+
field: 'hij',
|
|
183
|
+
op: '=',
|
|
184
|
+
value: 'klm'
|
|
185
|
+
}, {
|
|
186
|
+
field: 'nop',
|
|
187
|
+
op: '=',
|
|
188
|
+
value: 'qrs'
|
|
189
|
+
}];
|
|
190
|
+
var COMPONENT = {
|
|
191
|
+
alpha: 'bravo',
|
|
192
|
+
show_when: {
|
|
193
|
+
field: 'abc',
|
|
194
|
+
op: '=',
|
|
195
|
+
value: 'bcd'
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
var result = (0, _addShowWhen.default)(COMPONENT, NEW_ARRAY_SHOW_WHEN);
|
|
199
|
+
expect(result).toEqual({
|
|
200
|
+
alpha: 'bravo',
|
|
201
|
+
show_when: [{
|
|
202
|
+
field: 'hij',
|
|
203
|
+
op: '=',
|
|
204
|
+
value: 'klm'
|
|
205
|
+
}, {
|
|
206
|
+
field: 'nop',
|
|
207
|
+
op: '=',
|
|
208
|
+
value: 'qrs'
|
|
209
|
+
}, {
|
|
210
|
+
field: 'abc',
|
|
211
|
+
op: '=',
|
|
212
|
+
value: 'bcd'
|
|
213
|
+
}]
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _models = require("../../models");
|
|
8
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
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); }
|
|
14
|
+
/**
|
|
15
|
+
* Call a callback on a component and all of its child/nested components.
|
|
16
|
+
* At each stage, the value of the component is set to the returned value
|
|
17
|
+
* from the callback.
|
|
18
|
+
*
|
|
19
|
+
* @param {*} root The root component to call the callback on.
|
|
20
|
+
* @param {*} callback The callback to call. It should take a single
|
|
21
|
+
* component as an argument and return the new
|
|
22
|
+
* desired value for that component.
|
|
23
|
+
* @returns The result of calling callback on root.
|
|
24
|
+
* null if root is not valid.
|
|
25
|
+
* root if callback is not valid.
|
|
26
|
+
*/
|
|
27
|
+
var applyToComponentTree = function applyToComponentTree(root, callback) {
|
|
28
|
+
var _root$data;
|
|
29
|
+
if (!root) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (!callback) {
|
|
33
|
+
return root;
|
|
34
|
+
}
|
|
35
|
+
var result = _objectSpread({}, root);
|
|
36
|
+
switch (root.type) {
|
|
37
|
+
case _models.ComponentTypes.CONTAINER:
|
|
38
|
+
result.components.forEach(function (c, index, containerArray) {
|
|
39
|
+
var array = containerArray;
|
|
40
|
+
array[index] = applyToComponentTree(c, callback);
|
|
41
|
+
});
|
|
42
|
+
break;
|
|
43
|
+
case _models.ComponentTypes.COLLECTION:
|
|
44
|
+
result.item.forEach(function (c, index, collectionArray) {
|
|
45
|
+
var array = collectionArray;
|
|
46
|
+
array[index] = applyToComponentTree(c, callback);
|
|
47
|
+
});
|
|
48
|
+
break;
|
|
49
|
+
case _models.ComponentTypes.CHECKBOXES:
|
|
50
|
+
case _models.ComponentTypes.RADIOS:
|
|
51
|
+
if (!((_root$data = root.data) !== null && _root$data !== void 0 && _root$data.options)) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
result.data = _objectSpread({}, root.data);
|
|
55
|
+
result.data.options = root.data.options.map(function (option) {
|
|
56
|
+
var newOption = _objectSpread({}, option);
|
|
57
|
+
if (option.nested) {
|
|
58
|
+
newOption.nested = option.nested.map(function (c) {
|
|
59
|
+
return applyToComponentTree(c, callback);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return newOption;
|
|
63
|
+
});
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
return callback(result);
|
|
69
|
+
};
|
|
70
|
+
var _default = applyToComponentTree;
|
|
71
|
+
exports.default = _default;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _applyToComponentTree = _interopRequireDefault(require("./applyToComponentTree"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
6
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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.Component.applyToComponentTree', function () {
|
|
12
|
+
var SINGLE_COMP = {
|
|
13
|
+
type: 'text',
|
|
14
|
+
label: 'alpha'
|
|
15
|
+
};
|
|
16
|
+
var CONTAINER = {
|
|
17
|
+
type: 'container',
|
|
18
|
+
label: 'bravo',
|
|
19
|
+
components: [{
|
|
20
|
+
type: 'text',
|
|
21
|
+
label: 'charlie'
|
|
22
|
+
}]
|
|
23
|
+
};
|
|
24
|
+
var COLLECTION = {
|
|
25
|
+
type: 'collection',
|
|
26
|
+
label: 'delta',
|
|
27
|
+
item: [{
|
|
28
|
+
type: 'text',
|
|
29
|
+
label: 'echo'
|
|
30
|
+
}]
|
|
31
|
+
};
|
|
32
|
+
var COMP_WITH_NESTED = {
|
|
33
|
+
type: 'radios',
|
|
34
|
+
label: 'foxtrot',
|
|
35
|
+
data: {
|
|
36
|
+
options: [{
|
|
37
|
+
nested: [{
|
|
38
|
+
type: 'text',
|
|
39
|
+
label: 'golf'
|
|
40
|
+
}]
|
|
41
|
+
}, {
|
|
42
|
+
nested: [{
|
|
43
|
+
type: 'text',
|
|
44
|
+
label: 'hotel'
|
|
45
|
+
}]
|
|
46
|
+
}]
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var CALLBACK = function CALLBACK(component) {
|
|
50
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
51
|
+
label: component.label.toUpperCase()
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
it('should return null when root is undefined', function () {
|
|
55
|
+
var result = (0, _applyToComponentTree.default)(undefined, CALLBACK);
|
|
56
|
+
expect(result).toEqual(null);
|
|
57
|
+
});
|
|
58
|
+
it('should return null when root is null', function () {
|
|
59
|
+
var result = (0, _applyToComponentTree.default)(null, CALLBACK);
|
|
60
|
+
expect(result).toEqual(null);
|
|
61
|
+
});
|
|
62
|
+
it('should return root when callback is undefined', function () {
|
|
63
|
+
var result = (0, _applyToComponentTree.default)({
|
|
64
|
+
type: 'text'
|
|
65
|
+
}, undefined);
|
|
66
|
+
expect(result).toEqual({
|
|
67
|
+
type: 'text'
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
it('should return root when callback is null', function () {
|
|
71
|
+
var result = (0, _applyToComponentTree.default)({
|
|
72
|
+
type: 'text'
|
|
73
|
+
}, null);
|
|
74
|
+
expect(result).toEqual({
|
|
75
|
+
type: 'text'
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
it('should correctly call callback on a single component', function () {
|
|
79
|
+
var result = (0, _applyToComponentTree.default)(SINGLE_COMP, CALLBACK);
|
|
80
|
+
expect(result).toEqual({
|
|
81
|
+
type: 'text',
|
|
82
|
+
label: 'ALPHA'
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
it('should correctly call callback on a container component', function () {
|
|
86
|
+
var result = (0, _applyToComponentTree.default)(CONTAINER, CALLBACK);
|
|
87
|
+
expect(result).toEqual({
|
|
88
|
+
type: 'container',
|
|
89
|
+
label: 'BRAVO',
|
|
90
|
+
components: [{
|
|
91
|
+
type: 'text',
|
|
92
|
+
label: 'CHARLIE'
|
|
93
|
+
}]
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
it('should correctly call callback on a collection component', function () {
|
|
97
|
+
var result = (0, _applyToComponentTree.default)(COLLECTION, CALLBACK);
|
|
98
|
+
expect(result).toEqual({
|
|
99
|
+
type: 'collection',
|
|
100
|
+
label: 'DELTA',
|
|
101
|
+
item: [{
|
|
102
|
+
type: 'text',
|
|
103
|
+
label: 'ECHO'
|
|
104
|
+
}]
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
it('should correctly call callback on a component with nested components', function () {
|
|
108
|
+
var result = (0, _applyToComponentTree.default)(COMP_WITH_NESTED, CALLBACK);
|
|
109
|
+
expect(result).toEqual({
|
|
110
|
+
type: 'radios',
|
|
111
|
+
label: 'FOXTROT',
|
|
112
|
+
data: {
|
|
113
|
+
options: [{
|
|
114
|
+
nested: [{
|
|
115
|
+
type: 'text',
|
|
116
|
+
label: 'GOLF'
|
|
117
|
+
}]
|
|
118
|
+
}, {
|
|
119
|
+
nested: [{
|
|
120
|
+
type: 'text',
|
|
121
|
+
label: 'HOTEL'
|
|
122
|
+
}]
|
|
123
|
+
}]
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|