@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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
var _cyaAction = _interopRequireDefault(require("./cyaAction"));
|
|
8
8
|
var _navigate = _interopRequireDefault(require("./navigate"));
|
|
9
9
|
var _submissionError = _interopRequireDefault(require("./submissionError"));
|
|
@@ -13,6 +13,5 @@ var handlers = {
|
|
|
13
13
|
navigate: _navigate.default,
|
|
14
14
|
submissionError: _submissionError.default
|
|
15
15
|
};
|
|
16
|
-
exports.handlers = handlers;
|
|
17
16
|
var _default = handlers;
|
|
18
17
|
exports.default = _default;
|
|
@@ -12,11 +12,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
12
12
|
* @param {object} action The invoked action.
|
|
13
13
|
* @param {string} currentPageId The current pageId.
|
|
14
14
|
* @param {Function} onNavigate The handler to call if the pageId is different to the currentPageId.
|
|
15
|
+
* @param {object|undefined} state State to pass to the handler on change
|
|
15
16
|
*/
|
|
16
17
|
var navigate = function navigate(action, currentPageId, onNavigate) {
|
|
18
|
+
var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
|
|
17
19
|
var pageId = (0, _getPageId.default)(action, currentPageId);
|
|
18
20
|
if (pageId !== currentPageId) {
|
|
19
|
-
onNavigate(pageId);
|
|
21
|
+
onNavigate(pageId, state);
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
var _default = navigate;
|
|
@@ -4,24 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
return patch;
|
|
19
|
-
};
|
|
7
|
+
var _optionIsSelected = _interopRequireDefault(require("../../../utils/Component/optionIsSelected"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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); }
|
|
15
|
+
var parentComponents = ['radios', 'checkboxes'];
|
|
20
16
|
function getIdsToDelete(component, selectedValue) {
|
|
21
17
|
var _component$data, _component$data$optio;
|
|
22
18
|
var idsToDelete = [];
|
|
23
19
|
component === null || component === void 0 ? void 0 : (_component$data = component.data) === null || _component$data === void 0 ? void 0 : (_component$data$optio = _component$data.options) === null || _component$data$optio === void 0 ? void 0 : _component$data$optio.forEach(function (option) {
|
|
24
|
-
if (
|
|
20
|
+
if (!(0, _optionIsSelected.default)(selectedValue, option) && option.nested) {
|
|
25
21
|
option.nested.forEach(function (nested) {
|
|
26
22
|
idsToDelete.push(nested.id);
|
|
27
23
|
});
|
|
@@ -29,5 +25,30 @@ function getIdsToDelete(component, selectedValue) {
|
|
|
29
25
|
});
|
|
30
26
|
return idsToDelete;
|
|
31
27
|
}
|
|
28
|
+
;
|
|
29
|
+
var cleanHiddenNestedData = function cleanHiddenNestedData(patch, page) {
|
|
30
|
+
page.components.forEach(function (component) {
|
|
31
|
+
if (!parentComponents.includes(component.type)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
var _patch = patch;
|
|
35
|
+
var idsToDelete = getIdsToDelete(component, _patch[component.id]);
|
|
36
|
+
idsToDelete.forEach(function (id) {
|
|
37
|
+
delete _patch[id];
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
if (page.collection && patch[page.collection.name]) {
|
|
41
|
+
var _page$formData;
|
|
42
|
+
var activeId = patch["".concat(page.collection.name, "ActiveId")] || ((_page$formData = page.formData) === null || _page$formData === void 0 ? void 0 : _page$formData["".concat(page.collection.name, "ActiveId")]);
|
|
43
|
+
var _patch = patch;
|
|
44
|
+
_patch[page.collection.name] = _patch[page.collection.name].map(function (entry) {
|
|
45
|
+
return entry.id === activeId ? cleanHiddenNestedData(entry, _objectSpread(_objectSpread({}, page), {}, {
|
|
46
|
+
collection: undefined
|
|
47
|
+
})) : entry;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
;
|
|
51
|
+
return patch;
|
|
52
|
+
};
|
|
32
53
|
var _default = cleanHiddenNestedData;
|
|
33
54
|
exports.default = _default;
|
|
@@ -8,13 +8,13 @@ describe('components', function () {
|
|
|
8
8
|
describe('FormRenderer', function () {
|
|
9
9
|
describe('helpers', function () {
|
|
10
10
|
describe('cleanHiddenNestedData', function () {
|
|
11
|
-
it('remove data corresponding to hidden nested components', function () {
|
|
12
|
-
var
|
|
11
|
+
it('should remove data corresponding to hidden nested components in radios', function () {
|
|
12
|
+
var patchRadios = {
|
|
13
13
|
parent: 'option2',
|
|
14
14
|
nested1: 'should not be included',
|
|
15
15
|
nested2: 'should be included'
|
|
16
16
|
};
|
|
17
|
-
var
|
|
17
|
+
var pageRadios = {
|
|
18
18
|
id: 'page',
|
|
19
19
|
name: 'page',
|
|
20
20
|
title: 'Page',
|
|
@@ -39,9 +39,92 @@ describe('components', function () {
|
|
|
39
39
|
}
|
|
40
40
|
}]
|
|
41
41
|
};
|
|
42
|
+
var updatedPatchRadios = (0, _cleanHiddenNestedData.default)(patchRadios, pageRadios);
|
|
43
|
+
expect(updatedPatchRadios.nested1).toBeFalsy();
|
|
44
|
+
expect(updatedPatchRadios.nested2).toBeTruthy();
|
|
45
|
+
});
|
|
46
|
+
it('should remove data corresponding to hidden nested components in checkboxes', function () {
|
|
47
|
+
var patchCheckboxes = {
|
|
48
|
+
parent: ['option2'],
|
|
49
|
+
nested1: 'should not be included',
|
|
50
|
+
nested2: 'should be included'
|
|
51
|
+
};
|
|
52
|
+
var pageCheckboxes = {
|
|
53
|
+
id: 'page',
|
|
54
|
+
name: 'page',
|
|
55
|
+
title: 'Page',
|
|
56
|
+
components: [{
|
|
57
|
+
id: 'parent',
|
|
58
|
+
fieldId: 'parent',
|
|
59
|
+
type: 'checkboxes',
|
|
60
|
+
data: {
|
|
61
|
+
options: [{
|
|
62
|
+
value: 'option1',
|
|
63
|
+
nested: [{
|
|
64
|
+
id: 'nested1',
|
|
65
|
+
fieldId: 'nested1'
|
|
66
|
+
}]
|
|
67
|
+
}, {
|
|
68
|
+
value: 'option2',
|
|
69
|
+
nested: [{
|
|
70
|
+
id: 'nested2',
|
|
71
|
+
fieldId: 'nested2'
|
|
72
|
+
}]
|
|
73
|
+
}]
|
|
74
|
+
}
|
|
75
|
+
}]
|
|
76
|
+
};
|
|
77
|
+
var updatedPatchCheckboxes = (0, _cleanHiddenNestedData.default)(patchCheckboxes, pageCheckboxes);
|
|
78
|
+
expect(updatedPatchCheckboxes.nested1).toBeFalsy();
|
|
79
|
+
expect(updatedPatchCheckboxes.nested2).toBeTruthy();
|
|
80
|
+
});
|
|
81
|
+
it('remove data corresponding to hidden nested components within the active collection entry', function () {
|
|
82
|
+
var patch = {
|
|
83
|
+
collectionNameActiveId: '456',
|
|
84
|
+
collectionName: [{
|
|
85
|
+
id: '123',
|
|
86
|
+
parent: 'option1',
|
|
87
|
+
nested1: 'should be included',
|
|
88
|
+
nested2: 'should be included'
|
|
89
|
+
}, {
|
|
90
|
+
id: '456',
|
|
91
|
+
parent: 'option2',
|
|
92
|
+
nested1: 'should not be included',
|
|
93
|
+
nested2: 'should be included'
|
|
94
|
+
}]
|
|
95
|
+
};
|
|
96
|
+
var page = {
|
|
97
|
+
id: 'page',
|
|
98
|
+
name: 'page',
|
|
99
|
+
title: 'Page',
|
|
100
|
+
collection: {
|
|
101
|
+
name: 'collectionName'
|
|
102
|
+
},
|
|
103
|
+
components: [{
|
|
104
|
+
id: 'parent',
|
|
105
|
+
type: 'radios',
|
|
106
|
+
data: {
|
|
107
|
+
options: [{
|
|
108
|
+
value: 'option1',
|
|
109
|
+
nested: [{
|
|
110
|
+
id: 'nested1',
|
|
111
|
+
fieldId: 'nested1'
|
|
112
|
+
}]
|
|
113
|
+
}, {
|
|
114
|
+
value: 'option2',
|
|
115
|
+
nested: [{
|
|
116
|
+
id: 'nested2',
|
|
117
|
+
fieldId: 'nested2'
|
|
118
|
+
}]
|
|
119
|
+
}]
|
|
120
|
+
}
|
|
121
|
+
}]
|
|
122
|
+
};
|
|
42
123
|
var updatedPatch = (0, _cleanHiddenNestedData.default)(patch, page);
|
|
43
|
-
expect(updatedPatch[
|
|
44
|
-
expect(updatedPatch[
|
|
124
|
+
expect(updatedPatch.collectionName[0].nested1).toBeTruthy();
|
|
125
|
+
expect(updatedPatch.collectionName[0].nested2).toBeTruthy();
|
|
126
|
+
expect(updatedPatch.collectionName[1].nested1).toBeFalsy();
|
|
127
|
+
expect(updatedPatch.collectionName[1].nested2).toBeTruthy();
|
|
45
128
|
});
|
|
46
129
|
});
|
|
47
130
|
});
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _models = require("../../../models");
|
|
8
|
+
var _utils = _interopRequireDefault(require("../../../utils"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
10
|
// Local imports
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -18,17 +20,24 @@ var getCYA = function getCYA(pageId, pages, hub) {
|
|
|
18
20
|
return {
|
|
19
21
|
title: ''
|
|
20
22
|
};
|
|
21
|
-
}
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
if (pageId === _models.FormPages.CYA) {
|
|
22
26
|
return {};
|
|
23
27
|
}
|
|
28
|
+
;
|
|
24
29
|
var currentPage = pages === null || pages === void 0 ? void 0 : pages.find(function (p) {
|
|
25
30
|
return p.id === pageId;
|
|
26
31
|
});
|
|
27
32
|
if ((currentPage === null || currentPage === void 0 ? void 0 : currentPage.type) === _models.FormPages.PARTIAL_CYA) {
|
|
33
|
+
var pageWithConditionals = _utils.default.FormPage.applyConditionalProperties(currentPage);
|
|
28
34
|
return {
|
|
29
|
-
title:
|
|
35
|
+
title: pageWithConditionals.title,
|
|
36
|
+
hideChangeActions: pageWithConditionals.hideChangeActions,
|
|
37
|
+
hideGroupActions: pageWithConditionals.hideGroupActions
|
|
30
38
|
};
|
|
31
39
|
}
|
|
40
|
+
;
|
|
32
41
|
return undefined;
|
|
33
42
|
};
|
|
34
43
|
var _default = getCYA;
|
|
@@ -18,11 +18,14 @@ var getNextHubPageId = function getNextHubPageId(action, currentPageId, pages, f
|
|
|
18
18
|
if ((currentPage === null || currentPage === void 0 ? void 0 : currentPage.type) === 'pre-task-list') {
|
|
19
19
|
return currentPage.id;
|
|
20
20
|
}
|
|
21
|
+
;
|
|
21
22
|
return _models.FormPages.HUB;
|
|
22
23
|
}
|
|
24
|
+
;
|
|
23
25
|
return pages.length > 0 ? pages[0].id : undefined;
|
|
24
26
|
}
|
|
25
|
-
|
|
27
|
+
;
|
|
28
|
+
var nextPage;
|
|
26
29
|
action === null || action === void 0 ? void 0 : (_action$pages = action.pages) === null || _action$pages === void 0 ? void 0 : _action$pages.forEach(function (page) {
|
|
27
30
|
if (_FormPage.default.show({
|
|
28
31
|
show_when: page.show_when
|
|
@@ -33,9 +36,6 @@ var getNextHubPageId = function getNextHubPageId(action, currentPageId, pages, f
|
|
|
33
36
|
});
|
|
34
37
|
return nextPage || (action === null || action === void 0 ? void 0 : action.page) || _models.FormPages.HUB;
|
|
35
38
|
};
|
|
36
|
-
var getNextCYAPageId = function getNextCYAPageId(pages, currentPageId, formData) {
|
|
37
|
-
return getNextWizardPageId(pages, currentPageId, formData) || _models.FormPages.CYA;
|
|
38
|
-
};
|
|
39
39
|
var getNextWizardPageId = function getNextWizardPageId(pages, currentPageId, formData) {
|
|
40
40
|
var _page;
|
|
41
41
|
var nextIndex = pages.findIndex(function (p) {
|
|
@@ -43,14 +43,20 @@ var getNextWizardPageId = function getNextWizardPageId(pages, currentPageId, for
|
|
|
43
43
|
}) + 1;
|
|
44
44
|
var page = pages[nextIndex];
|
|
45
45
|
while (page && !_FormPage.default.show(page, formData)) {
|
|
46
|
-
nextIndex
|
|
46
|
+
nextIndex += 1;
|
|
47
47
|
page = pages[nextIndex];
|
|
48
48
|
}
|
|
49
|
+
;
|
|
49
50
|
return ((_page = page) === null || _page === void 0 ? void 0 : _page.id) || undefined;
|
|
50
51
|
};
|
|
52
|
+
var getNextCYAPageId = function getNextCYAPageId(pages, currentPageId, formData) {
|
|
53
|
+
return getNextWizardPageId(pages, currentPageId, formData) || _models.FormPages.CYA;
|
|
54
|
+
};
|
|
51
55
|
var getNextFormPageId = function getNextFormPageId(pages) {
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
return (
|
|
57
|
+
// A form has a single page... so always return that id.
|
|
58
|
+
pages.length > 0 ? pages[0].id : undefined
|
|
59
|
+
);
|
|
54
60
|
};
|
|
55
61
|
var getNextPageId = function getNextPageId(formType, pages, currentPageId, action, formData) {
|
|
56
62
|
if (action) {
|
|
@@ -7,7 +7,10 @@ exports.default = void 0;
|
|
|
7
7
|
var _models = require("../../../models");
|
|
8
8
|
var slicePages = function slicePages(pages, currentPageId) {
|
|
9
9
|
return pages.slice(0, pages.findIndex(function (p) {
|
|
10
|
-
|
|
10
|
+
if ((p === null || p === void 0 ? void 0 : p.id) === currentPageId) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
11
14
|
}));
|
|
12
15
|
};
|
|
13
16
|
var getRelevantPages = function getRelevantPages(formState, pages, currentTaskPages) {
|
|
@@ -15,7 +18,12 @@ var getRelevantPages = function getRelevantPages(formState, pages, currentTaskPa
|
|
|
15
18
|
if (((_formState$page = formState.page) === null || _formState$page === void 0 ? void 0 : _formState$page.type) === _models.FormPages.PARTIAL_CYA) {
|
|
16
19
|
return currentTaskPages ? slicePages(currentTaskPages, formState.pageId) : slicePages(pages, formState.pageId);
|
|
17
20
|
}
|
|
18
|
-
|
|
21
|
+
;
|
|
22
|
+
if (currentTaskPages) {
|
|
23
|
+
return currentTaskPages;
|
|
24
|
+
}
|
|
25
|
+
;
|
|
26
|
+
return pages;
|
|
19
27
|
};
|
|
20
28
|
var _default = getRelevantPages;
|
|
21
29
|
exports.default = _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _models = require("../../../models");
|
|
4
|
-
var _getRelevantPages = _interopRequireDefault(require("
|
|
4
|
+
var _getRelevantPages = _interopRequireDefault(require("./getRelevantPages"));
|
|
5
5
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
6
|
// Local imports
|
|
7
7
|
|
|
@@ -23,12 +23,12 @@ var getSubmissionStatus = function getSubmissionStatus(formType, pages, currentP
|
|
|
23
23
|
sections.forEach(function (section) {
|
|
24
24
|
section.tasks.forEach(function (task) {
|
|
25
25
|
var lastPage = task.pages[task.pages.length - 1];
|
|
26
|
-
if ((lastPage === currentPageId || lastPage.id === currentPageId) && isCompleted) {
|
|
26
|
+
if ((lastPage === currentPageId || lastPage.id === currentPageId) && isCompleted && (task === null || task === void 0 ? void 0 : task.type) === 'pre-task-list') {
|
|
27
27
|
formStatus.tasks[task.name] = {
|
|
28
28
|
complete: isCompleted,
|
|
29
29
|
currentPage: currentPageId
|
|
30
30
|
};
|
|
31
|
-
} else if (task.pages.includes(currentPageId)) {
|
|
31
|
+
} else if (task.pages.includes(currentPageId) && (task === null || task === void 0 ? void 0 : task.type) === 'pre-task-list') {
|
|
32
32
|
formStatus.tasks[task.name] = {
|
|
33
33
|
complete: false,
|
|
34
34
|
currentPage: currentPageId
|
|
@@ -4,7 +4,10 @@ var _models = require("../../../models");
|
|
|
4
4
|
var _PageAction = require("../../../models/PageAction");
|
|
5
5
|
var _getSubmissionStatus = _interopRequireDefault(require("./getSubmissionStatus"));
|
|
6
6
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
-
function
|
|
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 _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); }
|
|
8
11
|
describe('components', function () {
|
|
9
12
|
describe('FormRenderer', function () {
|
|
10
13
|
describe('helpers', function () {
|
|
@@ -249,7 +252,7 @@ describe('components', function () {
|
|
|
249
252
|
})
|
|
250
253
|
});
|
|
251
254
|
});
|
|
252
|
-
it("should mark the current task as complete if the current task is
|
|
255
|
+
it("should mark the current task as complete if the current task is a pre-task-list task", function () {
|
|
253
256
|
var CURRENT_PAGE_ID = PAGES[PAGES.length - 1].id;
|
|
254
257
|
var TASK_NAME = undefined;
|
|
255
258
|
var CURRENT_TASK = {
|
|
@@ -259,6 +262,7 @@ describe('components', function () {
|
|
|
259
262
|
complete: true
|
|
260
263
|
};
|
|
261
264
|
var TASKS = [{
|
|
265
|
+
type: 'pre-task-list',
|
|
262
266
|
pages: PAGES
|
|
263
267
|
}];
|
|
264
268
|
var SECTIONS = [{
|
|
@@ -5,9 +5,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _models = require("../../../models");
|
|
8
|
-
var
|
|
8
|
+
var _utils = _interopRequireDefault(require("../../../utils"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
|
+
/**
|
|
17
|
+
* @param {boolean} complete - true if task complete
|
|
18
|
+
* @param {boolean} currentPage - true if current page
|
|
19
|
+
* @param {TaskStates.TYPES|string} defaultState - default state to set task
|
|
20
|
+
* @returns {TaskStates.TYPES|string} current task state
|
|
21
|
+
*/
|
|
22
|
+
var getCurrentTaskState = function getCurrentTaskState(_ref) {
|
|
9
23
|
var complete = _ref.complete,
|
|
10
24
|
currentPage = _ref.currentPage;
|
|
25
|
+
var defaultState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _models.TaskStates.TYPES.NOT_STARTED;
|
|
11
26
|
if (complete) {
|
|
12
27
|
return _models.TaskStates.TYPES.COMPLETE;
|
|
13
28
|
}
|
|
@@ -16,67 +31,172 @@ var getCurrentTaskState = function getCurrentTaskState(_ref, defaultState) {
|
|
|
16
31
|
}
|
|
17
32
|
return defaultState;
|
|
18
33
|
};
|
|
19
|
-
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* check if dependent tasks have been completed
|
|
37
|
+
* @param {object} taskStates - list of tasks
|
|
38
|
+
* @param {array} mustBeComplete - tasks which are depended on
|
|
39
|
+
* @param {boolean} ignoreSkipped - skipped tasks don't need to have been completed
|
|
40
|
+
* @returns {boolean} true if dependent tasks complete
|
|
41
|
+
*/
|
|
42
|
+
var allDependentTasksComplete = function allDependentTasksComplete(taskStates, mustBeComplete) {
|
|
43
|
+
var ignoreSkipped = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
20
44
|
return mustBeComplete.reduce(function (allComplete, taskName) {
|
|
21
|
-
var
|
|
22
|
-
|
|
45
|
+
var task = taskStates[taskName];
|
|
46
|
+
if (ignoreSkipped && (task === null || task === void 0 ? void 0 : task.state) === _models.TaskStates.TYPES.SKIPPED) {
|
|
47
|
+
return allComplete;
|
|
48
|
+
}
|
|
49
|
+
return allComplete && (task === null || task === void 0 ? void 0 : task.complete);
|
|
23
50
|
}, true);
|
|
24
51
|
};
|
|
52
|
+
var isPreviousTaskComplete = function isPreviousTaskComplete(tasks, taskIndex) {
|
|
53
|
+
var lastTaskState = tasks[taskIndex - 1].state;
|
|
54
|
+
if (lastTaskState === _models.TaskStates.TYPES.COMPLETE) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (lastTaskState === _models.TaskStates.TYPES.SKIPPED) {
|
|
58
|
+
return taskIndex - 1 === 0 ? true : isPreviousTaskComplete(tasks, taskIndex - 1);
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
25
62
|
|
|
26
63
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @param {object}
|
|
29
|
-
* @param {
|
|
30
|
-
* {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
* @returns An JSON representation of the task list sections with up to date states
|
|
64
|
+
* return updated task state
|
|
65
|
+
* @param {object} task - current task object
|
|
66
|
+
* @param {number} taskIndex - order number of task in list
|
|
67
|
+
* @param {object[]} taskList - list of tasks (associated with section)
|
|
68
|
+
* @param {object} taskStates - map of task state
|
|
69
|
+
* @param {boolean} nonSequential - set if tasks can be performed out of order
|
|
70
|
+
* @param {boolean} allowFirst true if first task in list can be accepted
|
|
71
|
+
* @returns {TYPES|string} new state
|
|
37
72
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
73
|
+
|
|
74
|
+
var updateTaskState = function updateTaskState(task, taskIndex, taskList, taskStates) {
|
|
75
|
+
var nonSequential = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
76
|
+
var allowFirst = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
|
|
77
|
+
if (taskStates[task.name]) {
|
|
78
|
+
return getCurrentTaskState(taskStates[task.name], task.state);
|
|
79
|
+
}
|
|
80
|
+
if (nonSequential) {
|
|
81
|
+
if (task.depends_on && !allDependentTasksComplete(taskStates, task.depends_on, task.ignoreSkipped)) {
|
|
82
|
+
return _models.TaskStates.TYPES.CANNOT_START_YET;
|
|
83
|
+
}
|
|
84
|
+
return _models.TaskStates.TYPES.NOT_STARTED;
|
|
85
|
+
}
|
|
86
|
+
var notStarted = allowFirst;
|
|
87
|
+
if (taskIndex) {
|
|
88
|
+
notStarted = isPreviousTaskComplete(taskList, taskIndex);
|
|
89
|
+
}
|
|
90
|
+
if (notStarted) {
|
|
91
|
+
return _models.TaskStates.TYPES.NOT_STARTED;
|
|
92
|
+
}
|
|
93
|
+
return _models.TaskStates.TYPES.CANNOT_START_YET;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* update all tasks in section with new state.
|
|
98
|
+
* note use of clone and forEach as some tasks depend on previous update
|
|
99
|
+
* @param {object} section - section to be processed
|
|
100
|
+
* @param {object} taskStates - task updates
|
|
101
|
+
* @param {boolean} nonSequential - true if non-sequential task performance allowed
|
|
102
|
+
* @param {boolean} allowFirst - true if first task can be started
|
|
103
|
+
* @returns {object} - updated section
|
|
104
|
+
*/
|
|
105
|
+
var updateTasks = function updateTasks(section, taskStates, nonSequential, allowFirst) {
|
|
106
|
+
var clone = section.tasks.map(function (a) {
|
|
107
|
+
return _objectSpread({}, a);
|
|
108
|
+
});
|
|
109
|
+
clone.filter(function (t) {
|
|
110
|
+
return t.state !== _models.TaskStates.TYPES.SKIPPED;
|
|
111
|
+
}).forEach(function (t, index) {
|
|
112
|
+
var task = t;
|
|
113
|
+
task.state = updateTaskState(task, index, clone, taskStates, nonSequential, allowFirst);
|
|
58
114
|
});
|
|
115
|
+
return clone;
|
|
59
116
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Checks if the previous section has been completed. If the last section
|
|
120
|
+
* was skipped then this function will check the section before that until
|
|
121
|
+
* the state of a non-skipped section can be found.
|
|
122
|
+
* @param {array} sections - array of sections
|
|
123
|
+
* @param {number} currentIndex - index of the current section
|
|
124
|
+
* @returns {boolean} true if the last non-skipped section is complete, false
|
|
125
|
+
* if not.
|
|
126
|
+
*/
|
|
127
|
+
var isPreviousSectionComplete = function isPreviousSectionComplete(sections, currentIndex) {
|
|
128
|
+
var _sections, _sections$tasks$slice;
|
|
129
|
+
var lastTaskState = (_sections = sections[currentIndex - 1]) === null || _sections === void 0 ? void 0 : (_sections$tasks$slice = _sections.tasks.slice(-1)[0]) === null || _sections$tasks$slice === void 0 ? void 0 : _sections$tasks$slice.state;
|
|
130
|
+
if (lastTaskState === _models.TaskStates.TYPES.COMPLETE) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
if (lastTaskState === _models.TaskStates.TYPES.SKIPPED) {
|
|
134
|
+
return currentIndex - 1 === 0 ? true : isPreviousSectionComplete(sections, currentIndex - 1);
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* update task states in sections
|
|
141
|
+
* @param {object[]} sections - array of sections
|
|
142
|
+
* @param {object} taskStates - update task states
|
|
143
|
+
* @param {boolean} nonSequential - true if tasks can be performed non-sequentially
|
|
144
|
+
* @param {object} data - current form data
|
|
145
|
+
* @returns {object[]} - updated sections - note this is a clone
|
|
146
|
+
*/
|
|
147
|
+
var getUpdatedSectionStates = function getUpdatedSectionStates(sections, taskStates) {
|
|
148
|
+
var nonSequential = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
149
|
+
var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
150
|
+
// Make a clone and handle any hidden sections.
|
|
151
|
+
var clone = sections.map(function (section) {
|
|
152
|
+
var showWhen = section.show_when ? [section.show_when].flat() : [];
|
|
153
|
+
if (data && !_utils.default.Condition.meetsAll(showWhen, data)) {
|
|
154
|
+
return _objectSpread(_objectSpread({}, section), {}, {
|
|
155
|
+
skipped: true,
|
|
156
|
+
tasks: section.tasks.map(function (task) {
|
|
157
|
+
return _objectSpread(_objectSpread({}, task), {}, {
|
|
158
|
+
state: _models.TaskStates.TYPES.SKIPPED
|
|
159
|
+
});
|
|
160
|
+
})
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
;
|
|
164
|
+
return _objectSpread({}, section);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Now iterate through the clone and handle any hidden tasks.
|
|
168
|
+
clone.forEach(function (s) {
|
|
169
|
+
var section = s;
|
|
170
|
+
section.tasks = section.tasks.map(function (task) {
|
|
171
|
+
var showWhen = task.show_when ? [task.show_when].flat() : [];
|
|
172
|
+
if (data && !_utils.default.Condition.meetsAll(showWhen, data)) {
|
|
173
|
+
return _objectSpread(_objectSpread({}, task), {}, {
|
|
174
|
+
state: _models.TaskStates.TYPES.SKIPPED
|
|
175
|
+
});
|
|
69
176
|
}
|
|
70
|
-
return task;
|
|
177
|
+
return _objectSpread({}, task);
|
|
71
178
|
});
|
|
72
179
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
180
|
+
|
|
181
|
+
// Update the taskStates to account for skipped tasks.
|
|
182
|
+
var states = _objectSpread({}, taskStates);
|
|
183
|
+
clone.forEach(function (section) {
|
|
184
|
+
section.tasks.filter(function (t) {
|
|
185
|
+
return t.state === _models.TaskStates.TYPES.SKIPPED;
|
|
186
|
+
}).forEach(function (task) {
|
|
187
|
+
states[task.name] = _objectSpread(_objectSpread({}, states[task.name]), {}, {
|
|
188
|
+
state: _models.TaskStates.TYPES.SKIPPED
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Now figure out all the task states.
|
|
194
|
+
clone.forEach(function (s, index) {
|
|
195
|
+
var section = s;
|
|
196
|
+
var allowFirst = index === 0 || isPreviousSectionComplete(clone, index);
|
|
197
|
+
section.tasks = updateTasks(section, states, nonSequential, allowFirst);
|
|
198
|
+
});
|
|
199
|
+
return clone;
|
|
80
200
|
};
|
|
81
201
|
var _default = getUpdatedSectionStates;
|
|
82
202
|
exports.default = _default;
|