@ukhomeoffice/cop-react-form-renderer 5.14.2 → 5.14.4
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 +15 -15
- package/dist/components/CheckYourAnswers/Answer.test.js +94 -128
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +99 -129
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +291 -501
- package/dist/components/CheckYourAnswers/index.js +2 -3
- package/dist/components/CollectionPage/CollectionPage.js +64 -58
- package/dist/components/CollectionPage/CollectionPage.test.js +212 -238
- package/dist/components/CollectionPage/index.js +2 -3
- package/dist/components/FormComponent/Collection.js +77 -113
- package/dist/components/FormComponent/Collection.test.js +688 -787
- package/dist/components/FormComponent/Container.js +44 -43
- package/dist/components/FormComponent/Container.test.js +316 -346
- package/dist/components/FormComponent/FormComponent.js +58 -64
- package/dist/components/FormComponent/FormComponent.test.js +180 -219
- package/dist/components/FormComponent/helpers/addLabel.js +5 -9
- package/dist/components/FormComponent/helpers/getComponentDisabled.js +2 -3
- package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +8 -8
- package/dist/components/FormComponent/helpers/getComponentError.js +4 -7
- package/dist/components/FormComponent/helpers/getComponentError.test.js +15 -15
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +2 -2
- package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +7 -7
- package/dist/components/FormComponent/helpers/index.js +5 -5
- package/dist/components/FormComponent/index.js +2 -3
- package/dist/components/FormPage/FormPage.js +65 -79
- package/dist/components/FormPage/FormPage.test.js +134 -170
- package/dist/components/FormPage/index.js +2 -3
- package/dist/components/FormRenderer/FormRenderer.js +151 -193
- package/dist/components/FormRenderer/FormRenderer.test.js +598 -920
- package/dist/components/FormRenderer/handlers/cyaAction.js +4 -5
- package/dist/components/FormRenderer/handlers/getPageId.js +2 -5
- package/dist/components/FormRenderer/handlers/getPageId.test.js +15 -15
- package/dist/components/FormRenderer/handlers/handlers.test.js +33 -33
- package/dist/components/FormRenderer/handlers/index.js +3 -4
- package/dist/components/FormRenderer/handlers/navigate.js +5 -6
- package/dist/components/FormRenderer/handlers/submissionError.js +2 -3
- package/dist/components/FormRenderer/helpers/canActionProceed.js +2 -3
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +10 -10
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +2 -5
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +17 -21
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +19 -27
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +17 -17
- package/dist/components/FormRenderer/helpers/getCYA.js +6 -9
- package/dist/components/FormRenderer/helpers/getCYA.test.js +12 -12
- package/dist/components/FormRenderer/helpers/getFormState.js +7 -10
- package/dist/components/FormRenderer/helpers/getFormState.test.js +11 -11
- package/dist/components/FormRenderer/helpers/getNextPageId.js +19 -34
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +68 -68
- package/dist/components/FormRenderer/helpers/getPage.js +3 -6
- package/dist/components/FormRenderer/helpers/getPage.test.js +12 -12
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +9 -13
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +15 -15
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +12 -13
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +98 -92
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +66 -66
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +72 -79
- package/dist/components/FormRenderer/helpers/index.js +3 -4
- package/dist/components/FormRenderer/index.js +2 -3
- package/dist/components/FormRenderer/onCYAAction.js +52 -62
- package/dist/components/FormRenderer/onCYAAction.test.js +146 -138
- package/dist/components/FormRenderer/onPageAction.js +48 -47
- package/dist/components/FormRenderer/onPageAction.test.js +219 -205
- package/dist/components/FormRenderer/onTaskAction.js +12 -17
- package/dist/components/FormRenderer/onTaskAction.test.js +94 -89
- package/dist/components/PageActions/ActionButton.js +15 -19
- package/dist/components/PageActions/ActionButton.test.js +58 -79
- package/dist/components/PageActions/PageActions.js +12 -13
- package/dist/components/PageActions/PageActions.test.js +88 -116
- package/dist/components/PageActions/index.js +2 -3
- package/dist/components/SummaryList/GroupAction.js +15 -23
- package/dist/components/SummaryList/GroupAction.test.js +41 -37
- package/dist/components/SummaryList/RowAction.js +14 -19
- package/dist/components/SummaryList/RowAction.test.js +41 -37
- package/dist/components/SummaryList/SummaryList.js +25 -30
- package/dist/components/SummaryList/SummaryList.test.js +160 -182
- package/dist/components/SummaryList/SummaryListHeadingRow.js +9 -8
- package/dist/components/SummaryList/SummaryListRow.js +9 -8
- package/dist/components/SummaryList/SummaryListTitleRow.js +8 -7
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +5 -8
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +24 -24
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +5 -8
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +24 -24
- package/dist/components/SummaryList/helpers/index.js +2 -2
- package/dist/components/SummaryList/index.js +2 -3
- package/dist/components/TaskList/Task.js +22 -33
- package/dist/components/TaskList/Task.test.js +84 -77
- package/dist/components/TaskList/TaskList.js +46 -75
- package/dist/components/TaskList/TaskList.test.js +118 -113
- package/dist/components/TaskList/TaskState.js +9 -9
- package/dist/components/TaskList/TaskState.test.js +56 -49
- package/dist/components/TaskList/index.js +2 -3
- package/dist/components/index.js +8 -8
- package/dist/context/HooksContext/HooksContext.js +59 -85
- package/dist/context/HooksContext/HooksContext.test.js +28 -36
- package/dist/context/HooksContext/index.js +4 -6
- package/dist/context/ValidationContext/ValidationContext.js +35 -76
- package/dist/context/ValidationContext/ValidationContext.test.js +50 -61
- package/dist/context/ValidationContext/index.js +4 -6
- package/dist/context/index.js +3 -3
- package/dist/hooks/index.js +10 -11
- package/dist/hooks/useAxios.js +17 -43
- package/dist/hooks/useGetRequest.js +61 -106
- package/dist/hooks/useHooks.js +2 -5
- package/dist/hooks/useRefData.js +29 -45
- package/dist/hooks/useValidation.js +2 -5
- package/dist/index.js +15 -17
- package/dist/models/CollectionLabels.js +2 -3
- package/dist/models/ComponentTypes.js +25 -26
- package/dist/models/EventTypes.js +5 -6
- package/dist/models/FormPages.js +5 -6
- package/dist/models/FormTypes.js +9 -10
- package/dist/models/HubFormats.js +4 -5
- package/dist/models/PageAction.js +45 -42
- package/dist/models/TaskStates.js +30 -31
- package/dist/models/index.js +11 -12
- package/dist/setupTests.js +20 -24
- package/dist/utils/CheckYourAnswers/getCYAAction.js +6 -7
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +53 -55
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +18 -20
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +21 -23
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +17 -21
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +18 -20
- package/dist/utils/CheckYourAnswers/getCYARow.js +8 -10
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +72 -72
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +20 -27
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +16 -17
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +41 -47
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +72 -75
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +71 -78
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +133 -114
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +27 -23
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +112 -106
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +16 -23
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +77 -83
- package/dist/utils/CheckYourAnswers/index.js +3 -4
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +7 -9
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +25 -25
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +9 -16
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +19 -20
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +4 -8
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +15 -15
- package/dist/utils/CollectionPage/index.js +3 -4
- package/dist/utils/CollectionPage/mergeCollectionPages.js +26 -29
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +15 -15
- package/dist/utils/Component/addShowWhen.js +5 -10
- package/dist/utils/Component/addShowWhen.test.js +38 -38
- package/dist/utils/Component/applyToComponentTree.js +20 -22
- package/dist/utils/Component/applyToComponentTree.test.js +28 -33
- package/dist/utils/Component/cleanAttributes.js +11 -16
- package/dist/utils/Component/cleanAttributes.test.js +17 -18
- package/dist/utils/Component/elevateNestedComponents.js +7 -9
- package/dist/utils/Component/elevateNestedComponents.test.js +19 -19
- package/dist/utils/Component/getComponent.js +91 -99
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +19 -18
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +51 -63
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +41 -49
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +33 -37
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +21 -19
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +23 -27
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +12 -11
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +18 -16
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +10 -9
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +18 -16
- package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +24 -27
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +156 -175
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +18 -16
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +59 -73
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +19 -23
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +35 -41
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +24 -32
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +10 -9
- package/dist/utils/Component/getDefaultValue.js +7 -9
- package/dist/utils/Component/getDefaultValue.test.js +14 -14
- package/dist/utils/Component/index.js +3 -4
- package/dist/utils/Component/isEditable.js +3 -7
- package/dist/utils/Component/isEditable.test.js +14 -15
- package/dist/utils/Component/optionIsSelected.js +2 -3
- package/dist/utils/Component/optionIsSelected.test.js +10 -10
- package/dist/utils/Component/setupContainerComponentsPath.js +30 -33
- package/dist/utils/Component/setupContainerComponentsPath.test.js +16 -16
- package/dist/utils/Component/showComponent.js +4 -6
- package/dist/utils/Component/showComponent.test.js +29 -29
- package/dist/utils/Component/wrapInFormGroup.js +6 -6
- package/dist/utils/Condition/index.js +3 -4
- package/dist/utils/Condition/meetsAllConditions.js +9 -10
- package/dist/utils/Condition/meetsAllConditions.test.js +18 -18
- package/dist/utils/Condition/meetsCondition.js +19 -27
- package/dist/utils/Condition/meetsCondition.test.js +377 -377
- package/dist/utils/Condition/meetsOneCondition.js +7 -8
- package/dist/utils/Condition/meetsOneCondition.test.js +17 -17
- package/dist/utils/Condition/setupConditions.js +15 -21
- package/dist/utils/Condition/setupConditions.test.js +8 -8
- package/dist/utils/Container/getEditableComponents.js +5 -8
- package/dist/utils/Container/getEditableComponents.test.js +44 -46
- package/dist/utils/Container/index.js +3 -4
- package/dist/utils/Container/setupNesting.js +17 -24
- package/dist/utils/Container/setupNesting.test.js +28 -31
- package/dist/utils/Container/showContainer.js +5 -10
- package/dist/utils/Container/showContainer.test.js +31 -31
- package/dist/utils/Data/applyFormula.js +41 -52
- package/dist/utils/Data/applyFormula.test.js +26 -26
- package/dist/utils/Data/getAutocompleteSource.js +11 -14
- package/dist/utils/Data/getAutocompleteSource.test.js +59 -59
- package/dist/utils/Data/getDataPath.js +21 -32
- package/dist/utils/Data/getDataPath.test.js +20 -20
- package/dist/utils/Data/getOptions.js +22 -28
- package/dist/utils/Data/getOptions.test.js +21 -21
- package/dist/utils/Data/getSourceData.js +7 -21
- package/dist/utils/Data/getSourceData.test.js +85 -81
- package/dist/utils/Data/index.js +3 -4
- package/dist/utils/Data/refDataToOptions.js +12 -17
- package/dist/utils/Data/refDataToOptions.test.js +20 -20
- package/dist/utils/Data/setDataItem.js +8 -10
- package/dist/utils/Data/setDataItem.test.js +38 -38
- package/dist/utils/Data/setupFormData.js +32 -48
- package/dist/utils/Data/setupFormData.test.js +99 -98
- package/dist/utils/Data/setupRefDataUrlForComponent.js +22 -30
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +28 -28
- package/dist/utils/FormPage/applyConditionalProperties.js +7 -12
- package/dist/utils/FormPage/applyConditionalProperties.test.js +16 -19
- package/dist/utils/FormPage/getFormPage.js +17 -19
- package/dist/utils/FormPage/getFormPage.test.js +49 -48
- package/dist/utils/FormPage/getFormPages.js +9 -15
- package/dist/utils/FormPage/getFormPages.test.js +22 -25
- package/dist/utils/FormPage/getPageActions.js +11 -19
- package/dist/utils/FormPage/getPageActions.test.js +33 -33
- package/dist/utils/FormPage/getParagraphFromText.js +6 -9
- package/dist/utils/FormPage/getParagraphFromText.test.js +7 -7
- package/dist/utils/FormPage/index.js +3 -4
- package/dist/utils/FormPage/showFormPage.js +5 -10
- package/dist/utils/FormPage/showFormPage.test.js +33 -33
- package/dist/utils/FormPage/showFormPageCYA.js +4 -5
- package/dist/utils/FormPage/showFormPageCYA.test.js +9 -9
- package/dist/utils/FormPage/useComponent.js +21 -29
- package/dist/utils/FormPage/useComponent.test.js +71 -73
- package/dist/utils/Format/formatData.js +2 -3
- package/dist/utils/Format/formatData.test.js +19 -19
- package/dist/utils/Format/formatDataForComponent.js +6 -9
- package/dist/utils/Format/formatDataForComponent.test.js +50 -78
- package/dist/utils/Format/formatDataForForm.js +7 -10
- package/dist/utils/Format/formatDataForForm.test.js +14 -17
- package/dist/utils/Format/formatDataForPage.js +4 -7
- package/dist/utils/Format/formatDataForPage.test.js +20 -25
- package/dist/utils/Format/index.js +3 -4
- package/dist/utils/Hub/getFormHub.js +3 -4
- package/dist/utils/Hub/getFormHub.test.js +29 -32
- package/dist/utils/Hub/index.js +3 -4
- package/dist/utils/Meta/constants.js +2 -4
- package/dist/utils/Meta/documents/getDocuments.js +2 -6
- package/dist/utils/Meta/documents/getDocuments.test.js +25 -17
- package/dist/utils/Meta/documents/index.js +3 -4
- package/dist/utils/Meta/documents/setDocumentsForField.js +16 -19
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +69 -35
- package/dist/utils/Meta/index.js +3 -4
- package/dist/utils/Operate/checkValueIsTruthy.js +5 -6
- package/dist/utils/Operate/checkValueIsTruthy.test.js +17 -17
- package/dist/utils/Operate/getFirstOf.js +9 -10
- package/dist/utils/Operate/getFirstOf.test.js +33 -33
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +13 -14
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +47 -53
- package/dist/utils/Operate/index.js +3 -4
- package/dist/utils/Operate/persistValueInFormData.js +7 -8
- package/dist/utils/Operate/persistValueInFormData.test.js +23 -21
- package/dist/utils/Operate/runPageOperations.js +10 -11
- package/dist/utils/Operate/runPageOperations.test.js +36 -37
- package/dist/utils/Operate/setValueInFormData.js +6 -7
- package/dist/utils/Operate/setValueInFormData.test.js +17 -17
- package/dist/utils/Operate/shouldRun.js +9 -10
- package/dist/utils/Operate/shouldRun.test.js +22 -28
- package/dist/utils/Validate/additional/conditionallyRequired.js +5 -7
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +19 -19
- package/dist/utils/Validate/additional/index.js +8 -9
- package/dist/utils/Validate/additional/index.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeAfter.js +4 -5
- package/dist/utils/Validate/additional/mustBeAfter.test.js +41 -41
- package/dist/utils/Validate/additional/mustBeBefore.js +4 -5
- package/dist/utils/Validate/additional/mustBeBefore.test.js +29 -29
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +8 -14
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +34 -38
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +3 -4
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +19 -19
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +5 -6
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeInThePast.js +6 -7
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +13 -13
- package/dist/utils/Validate/additional/mustBeLessThan.js +3 -4
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +18 -18
- package/dist/utils/Validate/additional/mustBeLongerThan.js +2 -3
- package/dist/utils/Validate/additional/mustBeLongerThan.test.js +17 -17
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +3 -4
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +21 -21
- package/dist/utils/Validate/additional/mustBeShorterThan.js +2 -3
- package/dist/utils/Validate/additional/mustBeShorterThan.test.js +17 -17
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +4 -7
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +15 -17
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +2 -3
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +13 -13
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +4 -7
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +29 -27
- package/dist/utils/Validate/additional/utils.js +9 -25
- package/dist/utils/Validate/index.js +3 -4
- package/dist/utils/Validate/validateCollection.js +22 -29
- package/dist/utils/Validate/validateCollection.test.js +85 -77
- package/dist/utils/Validate/validateComponent.js +19 -19
- package/dist/utils/Validate/validateComponent.test.js +169 -147
- package/dist/utils/Validate/validateContainer.js +16 -22
- package/dist/utils/Validate/validateContainer.test.js +52 -48
- package/dist/utils/Validate/validateDate.js +14 -21
- package/dist/utils/Validate/validateDate.test.js +28 -29
- package/dist/utils/Validate/validateEmail.js +8 -11
- package/dist/utils/Validate/validateEmail.test.js +26 -26
- package/dist/utils/Validate/validateMultifile.js +6 -10
- package/dist/utils/Validate/validateMultifile.test.js +17 -18
- package/dist/utils/Validate/validatePage.js +20 -22
- package/dist/utils/Validate/validatePage.test.js +146 -143
- package/dist/utils/Validate/validateRegex.js +6 -10
- package/dist/utils/Validate/validateRegex.test.js +17 -17
- package/dist/utils/Validate/validateRequired.js +6 -9
- package/dist/utils/Validate/validateRequired.test.js +19 -19
- package/dist/utils/Validate/validateTextArea.js +6 -9
- package/dist/utils/Validate/validateTextArea.test.js +21 -21
- package/dist/utils/Validate/validateTime.js +8 -16
- package/dist/utils/Validate/validateTime.test.js +15 -15
- package/dist/utils/index.js +10 -12
- package/package.json +9 -6
|
@@ -5,13 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _getCollectionPageActiveIndex = _interopRequireDefault(require("./getCollectionPageActiveIndex"));
|
|
8
|
-
function _interopRequireDefault(
|
|
9
|
-
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); }
|
|
10
|
-
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; }
|
|
11
|
-
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; }
|
|
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); }
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
9
|
/**
|
|
16
10
|
* Duplicates the currently active entry in a named collection's data.
|
|
17
11
|
* Once duplicated, the new entry is set as the active entry.
|
|
@@ -19,20 +13,19 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
19
13
|
* @param {object} formData A page's form data containing the collection's data.
|
|
20
14
|
* @return true if the entry ws successfully duplicated, false if not.
|
|
21
15
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var currentEntry = (_formData$collectionN = formData[collectionName]) === null || _formData$collectionN === void 0 ? void 0 : _formData$collectionN[currentIndex];
|
|
16
|
+
const duplicateCollectionPageActiveEntry = (collectionName, formData) => {
|
|
17
|
+
const currentIndex = (0, _getCollectionPageActiveIndex.default)(collectionName, formData);
|
|
18
|
+
const currentEntry = formData[collectionName]?.[currentIndex];
|
|
26
19
|
if (!currentEntry) {
|
|
27
20
|
return false;
|
|
28
21
|
}
|
|
29
|
-
|
|
22
|
+
const newEntry = {
|
|
23
|
+
...currentEntry,
|
|
30
24
|
id: Date.now().toString()
|
|
31
|
-
}
|
|
25
|
+
};
|
|
32
26
|
formData[collectionName].push(newEntry);
|
|
33
27
|
// eslint-disable-next-line no-param-reassign
|
|
34
|
-
formData[
|
|
28
|
+
formData[`${collectionName}ActiveId`] = newEntry.id;
|
|
35
29
|
return true;
|
|
36
30
|
};
|
|
37
|
-
var _default = duplicateCollectionPageActiveEntry;
|
|
38
|
-
exports.default = _default;
|
|
31
|
+
var _default = exports.default = duplicateCollectionPageActiveEntry;
|
|
@@ -1,39 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _duplicateCollectionPageActiveEntry = _interopRequireDefault(require("./duplicateCollectionPageActiveEntry"));
|
|
4
|
-
function _interopRequireDefault(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
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); }
|
|
9
|
-
describe('utils.CollectionPage.duplicateCollectionPageActiveEntry', function () {
|
|
10
|
-
var COLLECTION_NAME = 'testCollection';
|
|
11
|
-
var OBJ = {
|
|
4
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
5
|
+
describe('utils.CollectionPage.duplicateCollectionPageActiveEntry', () => {
|
|
6
|
+
const COLLECTION_NAME = 'testCollection';
|
|
7
|
+
const OBJ = {
|
|
12
8
|
id: '1',
|
|
13
9
|
value: 'value'
|
|
14
10
|
};
|
|
15
|
-
it('should duplicate the active entry if one exists',
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
it('should duplicate the active entry if one exists', () => {
|
|
12
|
+
const FORM_DATA = {
|
|
13
|
+
[`${COLLECTION_NAME}ActiveId`]: '1',
|
|
14
|
+
[COLLECTION_NAME]: [OBJ]
|
|
15
|
+
};
|
|
18
16
|
(0, _duplicateCollectionPageActiveEntry.default)(COLLECTION_NAME, FORM_DATA);
|
|
19
17
|
expect(FORM_DATA[COLLECTION_NAME].length).toEqual(2);
|
|
20
18
|
expect(FORM_DATA[COLLECTION_NAME][1].value).toEqual(FORM_DATA[COLLECTION_NAME][0].value);
|
|
21
19
|
expect(FORM_DATA[COLLECTION_NAME][1].id).toBeTruthy();
|
|
22
20
|
expect(FORM_DATA[COLLECTION_NAME][1].id === '1').toBeFalsy();
|
|
23
|
-
expect(FORM_DATA[
|
|
24
|
-
expect(FORM_DATA[
|
|
21
|
+
expect(FORM_DATA[`${COLLECTION_NAME}ActiveId`]).toBeTruthy();
|
|
22
|
+
expect(FORM_DATA[`${COLLECTION_NAME}ActiveId`] === '1').toBeFalsy();
|
|
25
23
|
});
|
|
26
|
-
it('should do nothing if there is no active entry',
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
it('should do nothing if there is no active entry', () => {
|
|
25
|
+
const FORM_DATA = {
|
|
26
|
+
[`${COLLECTION_NAME}ActiveId`]: '2',
|
|
27
|
+
[COLLECTION_NAME]: [OBJ]
|
|
28
|
+
};
|
|
29
29
|
(0, _duplicateCollectionPageActiveEntry.default)(COLLECTION_NAME, FORM_DATA);
|
|
30
30
|
expect(FORM_DATA[COLLECTION_NAME].length).toEqual(1);
|
|
31
31
|
expect(FORM_DATA[COLLECTION_NAME][0]).toEqual(OBJ);
|
|
32
|
-
expect(FORM_DATA[
|
|
32
|
+
expect(FORM_DATA[`${COLLECTION_NAME}ActiveId`]).toEqual('2'); // Shouldn't have changed.
|
|
33
33
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var FORM_DATA = {};
|
|
34
|
+
it('should do nothing if the collection does not exist', () => {
|
|
35
|
+
const FORM_DATA = {};
|
|
37
36
|
(0, _duplicateCollectionPageActiveEntry.default)(COLLECTION_NAME, FORM_DATA);
|
|
38
37
|
expect(FORM_DATA).toEqual({});
|
|
39
38
|
});
|
|
@@ -10,19 +10,15 @@ exports.default = void 0;
|
|
|
10
10
|
* @param {object} formData A page's form data containing the collection's data.
|
|
11
11
|
* @returns The index of the active entry, or null if there isn't one.
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
var _formData$collectionN;
|
|
13
|
+
const getCollectionPageActiveIndex = (collectionName, formData) => {
|
|
15
14
|
if (!collectionName) {
|
|
16
15
|
return null;
|
|
17
16
|
}
|
|
18
|
-
|
|
17
|
+
const id = formData?.[`${collectionName}ActiveId`];
|
|
19
18
|
if (!id) {
|
|
20
19
|
return null;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
return item.id === id;
|
|
24
|
-
});
|
|
21
|
+
const activeIndex = formData[collectionName]?.findIndex(item => item.id === id);
|
|
25
22
|
return activeIndex > -1 ? activeIndex : null;
|
|
26
23
|
};
|
|
27
|
-
var _default = getCollectionPageActiveIndex;
|
|
28
|
-
exports.default = _default;
|
|
24
|
+
var _default = exports.default = getCollectionPageActiveIndex;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _getCollectionPageActiveIndex = _interopRequireDefault(require("./getCollectionPageActiveIndex"));
|
|
4
|
-
function _interopRequireDefault(
|
|
4
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
5
5
|
// Local imports
|
|
6
6
|
|
|
7
|
-
describe('utils.CollectionPage.getCollectionPageActiveIndex',
|
|
8
|
-
it('should return the index of the active item in the collection, if one exists',
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
describe('utils.CollectionPage.getCollectionPageActiveIndex', () => {
|
|
8
|
+
it('should return the index of the active item in the collection, if one exists', () => {
|
|
9
|
+
const COLLECTION_NAME = 'test';
|
|
10
|
+
const ACTIVE_ID = '002';
|
|
11
|
+
const FORM_DATA = {
|
|
12
12
|
testActiveId: ACTIVE_ID,
|
|
13
13
|
test: [{
|
|
14
14
|
id: '001'
|
|
@@ -16,7 +16,7 @@ describe('utils.CollectionPage.getCollectionPageActiveIndex', function () {
|
|
|
16
16
|
id: '002'
|
|
17
17
|
}]
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
const PAGE = {
|
|
20
20
|
collection: {
|
|
21
21
|
name: COLLECTION_NAME
|
|
22
22
|
},
|
|
@@ -24,16 +24,16 @@ describe('utils.CollectionPage.getCollectionPageActiveIndex', function () {
|
|
|
24
24
|
};
|
|
25
25
|
expect((0, _getCollectionPageActiveIndex.default)(PAGE.collection.name, PAGE.formData)).toEqual(1);
|
|
26
26
|
});
|
|
27
|
-
it('should return null if no active item can be found in the collection',
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
it('should return null if no active item can be found in the collection', () => {
|
|
28
|
+
const COLLECTION_NAME = 'test';
|
|
29
|
+
const ACTIVE_ID = '002';
|
|
30
|
+
const FORM_DATA = {
|
|
31
31
|
testActiveId: ACTIVE_ID,
|
|
32
32
|
test: [{
|
|
33
33
|
id: '001'
|
|
34
34
|
}]
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
const PAGE = {
|
|
37
37
|
collection: {
|
|
38
38
|
name: COLLECTION_NAME
|
|
39
39
|
},
|
|
@@ -41,9 +41,9 @@ describe('utils.CollectionPage.getCollectionPageActiveIndex', function () {
|
|
|
41
41
|
};
|
|
42
42
|
expect((0, _getCollectionPageActiveIndex.default)(PAGE.collection.name, PAGE.formData)).toEqual(null);
|
|
43
43
|
});
|
|
44
|
-
it('should return null if formData is null',
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
it('should return null if formData is null', () => {
|
|
45
|
+
const COLLECTION_NAME = 'test';
|
|
46
|
+
const PAGE = {
|
|
47
47
|
collection: {
|
|
48
48
|
name: COLLECTION_NAME
|
|
49
49
|
}
|
|
@@ -7,13 +7,12 @@ exports.default = void 0;
|
|
|
7
7
|
var _duplicateCollectionPageActiveEntry = _interopRequireDefault(require("./duplicateCollectionPageActiveEntry"));
|
|
8
8
|
var _getCollectionPageActiveIndex = _interopRequireDefault(require("./getCollectionPageActiveIndex"));
|
|
9
9
|
var _mergeCollectionPages = _interopRequireDefault(require("./mergeCollectionPages"));
|
|
10
|
-
function _interopRequireDefault(
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
// Local imports
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const CollectionPage = {
|
|
14
14
|
duplicateActiveEntry: _duplicateCollectionPageActiveEntry.default,
|
|
15
15
|
getActiveIndex: _getCollectionPageActiveIndex.default,
|
|
16
16
|
mergePages: _mergeCollectionPages.default
|
|
17
17
|
};
|
|
18
|
-
var _default = CollectionPage;
|
|
19
|
-
exports.default = _default;
|
|
18
|
+
var _default = exports.default = CollectionPage;
|
|
@@ -4,28 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
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
7
|
/* eslint-disable no-param-reassign */
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
const createMasterPage = page => ({
|
|
10
|
+
id: page.id,
|
|
11
|
+
name: page.name,
|
|
12
|
+
collection: {
|
|
13
|
+
masterPage: true,
|
|
14
|
+
...page.collection
|
|
15
|
+
},
|
|
16
|
+
formData: {
|
|
17
|
+
...page.formData
|
|
18
|
+
},
|
|
19
|
+
collectionPages: [page]
|
|
20
|
+
});
|
|
21
|
+
const mergeIntoMasterPage = (page, masterPage) => {
|
|
22
|
+
masterPage.collection = {
|
|
23
|
+
...masterPage.collection,
|
|
24
|
+
...page.collection
|
|
25
|
+
};
|
|
26
|
+
masterPage.formData = {
|
|
27
|
+
...masterPage.formData,
|
|
28
|
+
...page.formData
|
|
24
29
|
};
|
|
25
|
-
};
|
|
26
|
-
var mergeIntoMasterPage = function mergeIntoMasterPage(page, masterPage) {
|
|
27
|
-
masterPage.collection = _objectSpread(_objectSpread({}, masterPage.collection), page.collection);
|
|
28
|
-
masterPage.formData = _objectSpread(_objectSpread({}, masterPage.formData), page.formData);
|
|
29
30
|
masterPage.collectionPages = [].concat(masterPage.collectionPages, [page]);
|
|
30
31
|
};
|
|
31
32
|
|
|
@@ -40,11 +41,10 @@ var mergeIntoMasterPage = function mergeIntoMasterPage(page, masterPage) {
|
|
|
40
41
|
* @param { array } pages Array of pages in the form.
|
|
41
42
|
* @returns An array of the same pages, with a master page for each collection.
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return pages.map(
|
|
46
|
-
|
|
47
|
-
if (page !== null && page !== void 0 && (_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name) {
|
|
44
|
+
const mergeCollectionPages = pages => {
|
|
45
|
+
const masterPages = {};
|
|
46
|
+
return pages.map(page => {
|
|
47
|
+
if (page?.collection?.name) {
|
|
48
48
|
if (!masterPages[page.collection.name]) {
|
|
49
49
|
// If no master page exists for this collection.name, then
|
|
50
50
|
// we kick one off using this page as a template.
|
|
@@ -58,9 +58,6 @@ var mergeCollectionPages = function mergeCollectionPages(pages) {
|
|
|
58
58
|
return null;
|
|
59
59
|
}
|
|
60
60
|
return page;
|
|
61
|
-
}).filter(
|
|
62
|
-
return !!page;
|
|
63
|
-
});
|
|
61
|
+
}).filter(page => !!page);
|
|
64
62
|
};
|
|
65
|
-
var _default = mergeCollectionPages;
|
|
66
|
-
exports.default = _default;
|
|
63
|
+
var _default = exports.default = mergeCollectionPages;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _mergeCollectionPages = _interopRequireDefault(require("./mergeCollectionPages"));
|
|
4
|
-
function _interopRequireDefault(
|
|
4
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
5
5
|
// Local imports
|
|
6
6
|
|
|
7
|
-
describe('utils.CollectionPage.mergeCollectionPages',
|
|
8
|
-
|
|
7
|
+
describe('utils.CollectionPage.mergeCollectionPages', () => {
|
|
8
|
+
const TEXT_COMP = {
|
|
9
9
|
id: 'testText',
|
|
10
10
|
fieldId: 'testText',
|
|
11
11
|
type: 'text'
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
const DATE_COMP = {
|
|
14
14
|
id: 'testDate',
|
|
15
15
|
fieldId: 'testDate',
|
|
16
16
|
type: 'date'
|
|
17
17
|
};
|
|
18
|
-
it('should return the same array if no pages belong to collections',
|
|
19
|
-
|
|
18
|
+
it('should return the same array if no pages belong to collections', () => {
|
|
19
|
+
const PAGES = [{
|
|
20
20
|
id: 'page1'
|
|
21
21
|
}, {
|
|
22
22
|
id: 'page2'
|
|
23
23
|
}];
|
|
24
24
|
expect((0, _mergeCollectionPages.default)(PAGES)).toEqual(PAGES);
|
|
25
25
|
});
|
|
26
|
-
it('should merge pages from the same collection into a single page',
|
|
27
|
-
|
|
26
|
+
it('should merge pages from the same collection into a single page', () => {
|
|
27
|
+
const PAGES = [{
|
|
28
28
|
id: 'page1',
|
|
29
29
|
collection: {
|
|
30
30
|
name: 'collection'
|
|
@@ -37,7 +37,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
37
37
|
},
|
|
38
38
|
components: [DATE_COMP]
|
|
39
39
|
}];
|
|
40
|
-
|
|
40
|
+
const RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
41
41
|
expect(RESULT.length).toEqual(1);
|
|
42
42
|
expect(RESULT[0]).toMatchObject({
|
|
43
43
|
id: 'page1',
|
|
@@ -49,8 +49,8 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
49
49
|
collectionPages: PAGES
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
|
-
it('should leave non-collection pages unaffected',
|
|
53
|
-
|
|
52
|
+
it('should leave non-collection pages unaffected', () => {
|
|
53
|
+
const PAGES = [{
|
|
54
54
|
id: 'page1',
|
|
55
55
|
collection: {
|
|
56
56
|
name: 'collection'
|
|
@@ -65,7 +65,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
65
65
|
}, {
|
|
66
66
|
id: 'page3'
|
|
67
67
|
}];
|
|
68
|
-
|
|
68
|
+
const RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
69
69
|
expect(RESULT.length).toEqual(2);
|
|
70
70
|
expect(RESULT[0]).toEqual({
|
|
71
71
|
id: 'page1',
|
|
@@ -80,8 +80,8 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
80
80
|
id: 'page3'
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
|
-
it('should handle multiple collections',
|
|
84
|
-
|
|
83
|
+
it('should handle multiple collections', () => {
|
|
84
|
+
const PAGES = [{
|
|
85
85
|
id: 'page1',
|
|
86
86
|
collection: {
|
|
87
87
|
name: 'collection1'
|
|
@@ -106,7 +106,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
106
106
|
},
|
|
107
107
|
components: []
|
|
108
108
|
}];
|
|
109
|
-
|
|
109
|
+
const RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
110
110
|
expect(RESULT.length).toEqual(2);
|
|
111
111
|
expect(RESULT[0]).toEqual({
|
|
112
112
|
id: 'page1',
|
|
@@ -4,12 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
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
7
|
/**
|
|
14
8
|
* Adds a show_when to a component.
|
|
15
9
|
* If the component has no show_when, then an array is created
|
|
@@ -21,14 +15,16 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
21
15
|
* @returns The component with the new show_when added.
|
|
22
16
|
* null if component or condition are invalid.
|
|
23
17
|
*/
|
|
24
|
-
|
|
18
|
+
const addShowWhen = (component, condition) => {
|
|
25
19
|
if (!component) {
|
|
26
20
|
return null;
|
|
27
21
|
}
|
|
28
22
|
if (!condition) {
|
|
29
23
|
return component;
|
|
30
24
|
}
|
|
31
|
-
|
|
25
|
+
const result = {
|
|
26
|
+
...component
|
|
27
|
+
};
|
|
32
28
|
if (result.show_when) {
|
|
33
29
|
if (Array.isArray(condition)) {
|
|
34
30
|
result.show_when = Array.isArray(result.show_when) ? [].concat(condition, result.show_when) : [].concat(condition, [result.show_when]);
|
|
@@ -40,5 +36,4 @@ var addShowWhen = function addShowWhen(component, condition) {
|
|
|
40
36
|
}
|
|
41
37
|
return result;
|
|
42
38
|
};
|
|
43
|
-
var _default = addShowWhen;
|
|
44
|
-
exports.default = _default;
|
|
39
|
+
var _default = exports.default = addShowWhen;
|
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _addShowWhen = _interopRequireDefault(require("./addShowWhen"));
|
|
4
|
-
function _interopRequireDefault(
|
|
4
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
5
5
|
// Local imports
|
|
6
6
|
|
|
7
|
-
describe('utils.Component.addShowWhen',
|
|
8
|
-
|
|
7
|
+
describe('utils.Component.addShowWhen', () => {
|
|
8
|
+
const NEW_SHOW_WHEN = {
|
|
9
9
|
field: 'field',
|
|
10
10
|
op: '=',
|
|
11
11
|
value: 'value'
|
|
12
12
|
};
|
|
13
|
-
it('should return null when component is undefined',
|
|
14
|
-
|
|
13
|
+
it('should return null when component is undefined', () => {
|
|
14
|
+
const result = (0, _addShowWhen.default)(undefined, {});
|
|
15
15
|
expect(result).toEqual(null);
|
|
16
16
|
});
|
|
17
|
-
it('should return null when component is null',
|
|
18
|
-
|
|
17
|
+
it('should return null when component is null', () => {
|
|
18
|
+
const result = (0, _addShowWhen.default)(null, {});
|
|
19
19
|
expect(result).toEqual(null);
|
|
20
20
|
});
|
|
21
|
-
it('should return component when condition is undefined',
|
|
22
|
-
|
|
21
|
+
it('should return component when condition is undefined', () => {
|
|
22
|
+
const COMPONENT = {
|
|
23
23
|
alpha: 'bravo'
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
const result = (0, _addShowWhen.default)(COMPONENT, undefined);
|
|
26
26
|
expect(result).toEqual({
|
|
27
27
|
alpha: 'bravo'
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
|
-
it('should return component when condition is null',
|
|
31
|
-
|
|
30
|
+
it('should return component when condition is null', () => {
|
|
31
|
+
const COMPONENT = {
|
|
32
32
|
alpha: 'bravo'
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
const result = (0, _addShowWhen.default)(COMPONENT, null);
|
|
35
35
|
expect(result).toEqual({
|
|
36
36
|
alpha: 'bravo'
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
-
it('should add the show_when to a component with no existing show_whens',
|
|
40
|
-
|
|
39
|
+
it('should add the show_when to a component with no existing show_whens', () => {
|
|
40
|
+
const COMPONENT = {
|
|
41
41
|
alpha: 'bravo'
|
|
42
42
|
};
|
|
43
|
-
|
|
43
|
+
const result = (0, _addShowWhen.default)(COMPONENT, NEW_SHOW_WHEN);
|
|
44
44
|
expect(result).toEqual({
|
|
45
45
|
alpha: 'bravo',
|
|
46
46
|
show_when: NEW_SHOW_WHEN
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
-
it('should add the array type show_when to a component with no existing show_whens',
|
|
50
|
-
|
|
49
|
+
it('should add the array type show_when to a component with no existing show_whens', () => {
|
|
50
|
+
const NEW_ARRAY_SHOW_WHEN = [{
|
|
51
51
|
field: 'abc',
|
|
52
52
|
op: '=',
|
|
53
53
|
value: 'bcd'
|
|
@@ -56,17 +56,17 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
56
56
|
op: '=',
|
|
57
57
|
value: 'efg'
|
|
58
58
|
}];
|
|
59
|
-
|
|
59
|
+
const COMPONENT = {
|
|
60
60
|
alpha: 'bravo'
|
|
61
61
|
};
|
|
62
|
-
|
|
62
|
+
const result = (0, _addShowWhen.default)(COMPONENT, NEW_ARRAY_SHOW_WHEN);
|
|
63
63
|
expect(result).toEqual({
|
|
64
64
|
alpha: 'bravo',
|
|
65
65
|
show_when: NEW_ARRAY_SHOW_WHEN
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
-
it('should add the show_when to a component with a single show_when',
|
|
69
|
-
|
|
68
|
+
it('should add the show_when to a component with a single show_when', () => {
|
|
69
|
+
const COMPONENT = {
|
|
70
70
|
alpha: 'bravo',
|
|
71
71
|
show_when: {
|
|
72
72
|
field: 'abc',
|
|
@@ -74,7 +74,7 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
74
74
|
value: 'bcd'
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
|
|
77
|
+
const result = (0, _addShowWhen.default)(COMPONENT, NEW_SHOW_WHEN);
|
|
78
78
|
expect(result).toEqual({
|
|
79
79
|
alpha: 'bravo',
|
|
80
80
|
show_when: [{
|
|
@@ -84,8 +84,8 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
84
84
|
}, NEW_SHOW_WHEN]
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
|
-
it('should add the show_when to a component with an array of show_whens',
|
|
88
|
-
|
|
87
|
+
it('should add the show_when to a component with an array of show_whens', () => {
|
|
88
|
+
const COMPONENT = {
|
|
89
89
|
alpha: 'bravo',
|
|
90
90
|
show_when: [{
|
|
91
91
|
field: 'abc',
|
|
@@ -97,7 +97,7 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
97
97
|
value: 'efg'
|
|
98
98
|
}]
|
|
99
99
|
};
|
|
100
|
-
|
|
100
|
+
const result = (0, _addShowWhen.default)(COMPONENT, NEW_SHOW_WHEN);
|
|
101
101
|
expect(result).toEqual({
|
|
102
102
|
alpha: 'bravo',
|
|
103
103
|
show_when: [{
|
|
@@ -111,11 +111,11 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
111
111
|
}, NEW_SHOW_WHEN]
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
|
-
it('should add the or type show_when to a component with no existing show_whens in an object not an array',
|
|
115
|
-
|
|
114
|
+
it('should add the or type show_when to a component with no existing show_whens in an object not an array', () => {
|
|
115
|
+
const COMPONENT = {
|
|
116
116
|
alpha: 'bravo'
|
|
117
117
|
};
|
|
118
|
-
|
|
118
|
+
const SHOW_WHEN_OR = {
|
|
119
119
|
type: 'or',
|
|
120
120
|
condition: [{
|
|
121
121
|
field: 'field1',
|
|
@@ -127,14 +127,14 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
127
127
|
value: 2
|
|
128
128
|
}]
|
|
129
129
|
};
|
|
130
|
-
|
|
130
|
+
const result = (0, _addShowWhen.default)(COMPONENT, SHOW_WHEN_OR);
|
|
131
131
|
expect(result).toEqual({
|
|
132
132
|
alpha: 'bravo',
|
|
133
133
|
show_when: SHOW_WHEN_OR
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
|
-
it('should add an array of show_whens to a component with an array of show_whens',
|
|
137
|
-
|
|
136
|
+
it('should add an array of show_whens to a component with an array of show_whens', () => {
|
|
137
|
+
const NEW_ARRAY_SHOW_WHEN = [{
|
|
138
138
|
field: 'hij',
|
|
139
139
|
op: '=',
|
|
140
140
|
value: 'klm'
|
|
@@ -143,7 +143,7 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
143
143
|
op: '=',
|
|
144
144
|
value: 'qrs'
|
|
145
145
|
}];
|
|
146
|
-
|
|
146
|
+
const COMPONENT = {
|
|
147
147
|
alpha: 'bravo',
|
|
148
148
|
show_when: [{
|
|
149
149
|
field: 'abc',
|
|
@@ -155,7 +155,7 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
155
155
|
value: 'efg'
|
|
156
156
|
}]
|
|
157
157
|
};
|
|
158
|
-
|
|
158
|
+
const result = (0, _addShowWhen.default)(COMPONENT, NEW_ARRAY_SHOW_WHEN);
|
|
159
159
|
expect(result).toEqual({
|
|
160
160
|
alpha: 'bravo',
|
|
161
161
|
show_when: [{
|
|
@@ -177,8 +177,8 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
177
177
|
}]
|
|
178
178
|
});
|
|
179
179
|
});
|
|
180
|
-
it('should add an array of show_whens to a component with a single show_when',
|
|
181
|
-
|
|
180
|
+
it('should add an array of show_whens to a component with a single show_when', () => {
|
|
181
|
+
const NEW_ARRAY_SHOW_WHEN = [{
|
|
182
182
|
field: 'hij',
|
|
183
183
|
op: '=',
|
|
184
184
|
value: 'klm'
|
|
@@ -187,7 +187,7 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
187
187
|
op: '=',
|
|
188
188
|
value: 'qrs'
|
|
189
189
|
}];
|
|
190
|
-
|
|
190
|
+
const COMPONENT = {
|
|
191
191
|
alpha: 'bravo',
|
|
192
192
|
show_when: {
|
|
193
193
|
field: 'abc',
|
|
@@ -195,7 +195,7 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
195
195
|
value: 'bcd'
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
|
-
|
|
198
|
+
const result = (0, _addShowWhen.default)(COMPONENT, NEW_ARRAY_SHOW_WHEN);
|
|
199
199
|
expect(result).toEqual({
|
|
200
200
|
alpha: 'bravo',
|
|
201
201
|
show_when: [{
|