@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
|
@@ -8,11 +8,15 @@ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
|
8
8
|
var _models = require("../../models");
|
|
9
9
|
var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
|
|
10
10
|
var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
|
|
11
|
+
var _setupContainerComponentsPath = _interopRequireDefault(require("../Component/setupContainerComponentsPath"));
|
|
11
12
|
var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
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); }
|
|
13
15
|
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; }
|
|
14
16
|
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; }
|
|
15
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
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; }
|
|
18
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
19
|
+
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
20
|
var getEntryToCollectionRow = function getEntryToCollectionRow(page, onAction) {
|
|
17
21
|
var _page$components$0$la;
|
|
18
22
|
return [{
|
|
@@ -22,30 +26,30 @@ var getEntryToCollectionRow = function getEntryToCollectionRow(page, onAction) {
|
|
|
22
26
|
action: (0, _getCYAAction.default)(false, page, onAction)
|
|
23
27
|
}];
|
|
24
28
|
};
|
|
25
|
-
var getContainerForItem = function getContainerForItem(collection, item, labelCount,
|
|
29
|
+
var getContainerForItem = function getContainerForItem(collection, item, labelCount, fullPath) {
|
|
26
30
|
return {
|
|
27
31
|
id: item.id,
|
|
28
32
|
fieldId: item.id,
|
|
29
33
|
type: _models.ComponentTypes.CONTAINER,
|
|
30
34
|
required: collection.required,
|
|
31
|
-
full_path:
|
|
35
|
+
full_path: fullPath,
|
|
32
36
|
components: collection.item.map(function (component) {
|
|
33
37
|
return _objectSpread(_objectSpread({}, component), {}, {
|
|
34
38
|
label: _copReactComponents.Utils.interpolateString(component.label, _objectSpread(_objectSpread({}, item), {}, {
|
|
35
39
|
index: labelCount
|
|
36
40
|
})),
|
|
37
|
-
full_path: "".concat(
|
|
41
|
+
full_path: "".concat(fullPath, ".").concat(component.fieldId)
|
|
38
42
|
});
|
|
39
43
|
})
|
|
40
44
|
};
|
|
41
45
|
};
|
|
42
|
-
var getTitleRowForItem = function getTitleRowForItem(collection, item, pageId, labelCount,
|
|
46
|
+
var getTitleRowForItem = function getTitleRowForItem(collection, item, pageId, labelCount, fullPath) {
|
|
43
47
|
var labels = _objectSpread(_objectSpread({}, _models.CollectionLabels), collection.labels);
|
|
44
48
|
if (labels.item) {
|
|
45
49
|
return {
|
|
46
50
|
pageId: pageId,
|
|
47
51
|
fieldId: collection.fieldId,
|
|
48
|
-
full_path:
|
|
52
|
+
full_path: fullPath,
|
|
49
53
|
key: _copReactComponents.Utils.interpolateString(labels.item, _objectSpread(_objectSpread({}, item), {}, {
|
|
50
54
|
index: labelCount
|
|
51
55
|
})),
|
|
@@ -55,13 +59,14 @@ var getTitleRowForItem = function getTitleRowForItem(collection, item, pageId, l
|
|
|
55
59
|
}
|
|
56
60
|
return null;
|
|
57
61
|
};
|
|
58
|
-
var getCYARowsForCollection = function getCYARowsForCollection(page, collection, items, onAction) {
|
|
62
|
+
var getCYARowsForCollection = function getCYARowsForCollection(page, collection, items, onAction, fnOverride) {
|
|
59
63
|
if (Array.isArray(items) && items.length && (0, _showComponentCYA.default)(collection, page.formData)) {
|
|
60
64
|
return items.flatMap(function (item, index) {
|
|
61
65
|
var labelCount = (collection.countOffset || 0) + index + 1;
|
|
62
|
-
var
|
|
63
|
-
var container = getContainerForItem(collection, item, labelCount,
|
|
64
|
-
|
|
66
|
+
var fullPath = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
|
|
67
|
+
var container = getContainerForItem(collection, item, labelCount, fullPath);
|
|
68
|
+
container = (0, _setupContainerComponentsPath.default)(container);
|
|
69
|
+
return [getTitleRowForItem(collection, item, page.id, labelCount, fullPath)].concat((0, _getCYARowsForContainer.default)(page, container, item, onAction, fnOverride));
|
|
65
70
|
}).filter(function (r) {
|
|
66
71
|
return !!r;
|
|
67
72
|
});
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
var _setupTests = require("../../setupTests");
|
|
5
|
+
var _getCYARowsForCollection = _interopRequireDefault(require("./getCYARowsForCollection"));
|
|
6
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
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
|
+
describe('utils.CheckYourAnswers.getCYARowsForCollection', function () {
|
|
14
|
+
it('should get a single entry point row when there are no items', function () {
|
|
15
|
+
var FORM_DATA = undefined;
|
|
16
|
+
var PAGE = {
|
|
17
|
+
id: 'page',
|
|
18
|
+
components: [{
|
|
19
|
+
labels: {
|
|
20
|
+
add: 'Add'
|
|
21
|
+
}
|
|
22
|
+
}],
|
|
23
|
+
formData: FORM_DATA,
|
|
24
|
+
cya_link: {}
|
|
25
|
+
};
|
|
26
|
+
var COMPONENT = {
|
|
27
|
+
type: 'text',
|
|
28
|
+
readonly: true,
|
|
29
|
+
id: 'a',
|
|
30
|
+
fieldId: 'a',
|
|
31
|
+
label: 'Alpha'
|
|
32
|
+
};
|
|
33
|
+
var COLLECTION = {
|
|
34
|
+
id: 'collection',
|
|
35
|
+
fieldId: 'collection',
|
|
36
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
37
|
+
item: [COMPONENT]
|
|
38
|
+
};
|
|
39
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
40
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, undefined, ON_ACTION);
|
|
41
|
+
expect(ROWS.length).toEqual(1);
|
|
42
|
+
});
|
|
43
|
+
it('should get an appropriate row for a collection with a single readonly text component', function () {
|
|
44
|
+
var FORM_DATA = {
|
|
45
|
+
collection: [{
|
|
46
|
+
a: 'Bravo'
|
|
47
|
+
}]
|
|
48
|
+
};
|
|
49
|
+
var PAGE = {
|
|
50
|
+
id: 'page',
|
|
51
|
+
formData: FORM_DATA,
|
|
52
|
+
cya_link: {}
|
|
53
|
+
};
|
|
54
|
+
var COMPONENT = {
|
|
55
|
+
type: 'text',
|
|
56
|
+
readonly: true,
|
|
57
|
+
id: 'a',
|
|
58
|
+
fieldId: 'a',
|
|
59
|
+
label: 'Alpha'
|
|
60
|
+
};
|
|
61
|
+
var COLLECTION = {
|
|
62
|
+
id: 'collection',
|
|
63
|
+
fieldId: 'collection',
|
|
64
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
65
|
+
countOffset: 22,
|
|
66
|
+
item: [COMPONENT],
|
|
67
|
+
value: FORM_DATA.collection,
|
|
68
|
+
formData: FORM_DATA
|
|
69
|
+
};
|
|
70
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
71
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
|
|
72
|
+
expect(ROWS.length).toEqual(2); // Item title row + component row
|
|
73
|
+
(0, _setupTests.expectObjectLike)(ROWS[0], {
|
|
74
|
+
pageId: PAGE.id,
|
|
75
|
+
fieldId: COLLECTION.fieldId,
|
|
76
|
+
full_path: "".concat(COLLECTION.fieldId, "[0]"),
|
|
77
|
+
key: 'Item 23',
|
|
78
|
+
// includes countOffset
|
|
79
|
+
type: 'title',
|
|
80
|
+
action: null
|
|
81
|
+
});
|
|
82
|
+
(0, _setupTests.expectObjectLike)(ROWS[1], {
|
|
83
|
+
pageId: PAGE.id,
|
|
84
|
+
fieldId: COMPONENT.fieldId,
|
|
85
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
|
|
86
|
+
key: COMPONENT.label,
|
|
87
|
+
action: null,
|
|
88
|
+
component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
|
|
89
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId)
|
|
90
|
+
}),
|
|
91
|
+
value: 'Bravo'
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
it('should get an appropriate row for a collection with a single readonly text component where the item label is an empty string', function () {
|
|
95
|
+
var FORM_DATA = {
|
|
96
|
+
collection: [{
|
|
97
|
+
a: 'Bravo'
|
|
98
|
+
}]
|
|
99
|
+
};
|
|
100
|
+
var PAGE = {
|
|
101
|
+
id: 'page',
|
|
102
|
+
formData: FORM_DATA,
|
|
103
|
+
cya_link: {}
|
|
104
|
+
};
|
|
105
|
+
var COMPONENT = {
|
|
106
|
+
type: 'text',
|
|
107
|
+
readonly: true,
|
|
108
|
+
id: 'a',
|
|
109
|
+
fieldId: 'a',
|
|
110
|
+
label: 'Alpha'
|
|
111
|
+
};
|
|
112
|
+
var COLLECTION = {
|
|
113
|
+
id: 'collection',
|
|
114
|
+
fieldId: 'collection',
|
|
115
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
116
|
+
labels: {
|
|
117
|
+
item: ''
|
|
118
|
+
},
|
|
119
|
+
countOffset: 22,
|
|
120
|
+
item: [COMPONENT],
|
|
121
|
+
value: FORM_DATA.collection,
|
|
122
|
+
formData: FORM_DATA
|
|
123
|
+
};
|
|
124
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
125
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
|
|
126
|
+
expect(ROWS.length).toEqual(1); // Just the component row, no title row
|
|
127
|
+
(0, _setupTests.expectObjectLike)(ROWS[0], {
|
|
128
|
+
pageId: PAGE.id,
|
|
129
|
+
fieldId: COMPONENT.fieldId,
|
|
130
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
|
|
131
|
+
key: COMPONENT.label,
|
|
132
|
+
action: null,
|
|
133
|
+
component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
|
|
134
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId)
|
|
135
|
+
}),
|
|
136
|
+
value: 'Bravo'
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
it('should interpolate a field label appropriately', function () {
|
|
140
|
+
var FORM_DATA = {
|
|
141
|
+
collection: [{
|
|
142
|
+
a: 'Bravo'
|
|
143
|
+
}]
|
|
144
|
+
};
|
|
145
|
+
var PAGE = {
|
|
146
|
+
id: 'page',
|
|
147
|
+
formData: FORM_DATA,
|
|
148
|
+
cya_link: {}
|
|
149
|
+
};
|
|
150
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
151
|
+
var COMPONENT = {
|
|
152
|
+
type: 'text',
|
|
153
|
+
readonly: true,
|
|
154
|
+
id: 'a',
|
|
155
|
+
fieldId: 'a',
|
|
156
|
+
label: 'Alpha ${index}'
|
|
157
|
+
};
|
|
158
|
+
var COLLECTION = {
|
|
159
|
+
id: 'collection',
|
|
160
|
+
fieldId: 'collection',
|
|
161
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
162
|
+
item: [COMPONENT],
|
|
163
|
+
value: FORM_DATA.collection,
|
|
164
|
+
formData: FORM_DATA
|
|
165
|
+
};
|
|
166
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
167
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
|
|
168
|
+
expect(ROWS.length).toEqual(2); // Title and item row.
|
|
169
|
+
(0, _setupTests.expectObjectLike)(ROWS[1], {
|
|
170
|
+
pageId: PAGE.id,
|
|
171
|
+
fieldId: COMPONENT.fieldId,
|
|
172
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
|
|
173
|
+
key: 'Alpha 1',
|
|
174
|
+
// no countOffset
|
|
175
|
+
action: null,
|
|
176
|
+
component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
|
|
177
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
|
|
178
|
+
label: 'Alpha 1' // no countOffset
|
|
179
|
+
}),
|
|
180
|
+
|
|
181
|
+
value: 'Bravo'
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
it('should ignore the result of the override function if it returns nullish', function () {
|
|
185
|
+
var FORM_DATA = {
|
|
186
|
+
collection: [{
|
|
187
|
+
a: 'Bravo'
|
|
188
|
+
}]
|
|
189
|
+
};
|
|
190
|
+
var PAGE = {
|
|
191
|
+
id: 'page',
|
|
192
|
+
formData: FORM_DATA,
|
|
193
|
+
cya_link: {}
|
|
194
|
+
};
|
|
195
|
+
var COMPONENT = {
|
|
196
|
+
type: 'text',
|
|
197
|
+
readonly: true,
|
|
198
|
+
id: 'a',
|
|
199
|
+
fieldId: 'a',
|
|
200
|
+
label: 'Alpha'
|
|
201
|
+
};
|
|
202
|
+
var COLLECTION = {
|
|
203
|
+
id: 'collection',
|
|
204
|
+
fieldId: 'collection',
|
|
205
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
206
|
+
countOffset: 22,
|
|
207
|
+
item: [COMPONENT],
|
|
208
|
+
value: FORM_DATA.collection,
|
|
209
|
+
formData: FORM_DATA
|
|
210
|
+
};
|
|
211
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
212
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION, function () {
|
|
213
|
+
return null;
|
|
214
|
+
});
|
|
215
|
+
expect(ROWS.length).toEqual(2); // Item title row + component row
|
|
216
|
+
(0, _setupTests.expectObjectLike)(ROWS[0], {
|
|
217
|
+
pageId: PAGE.id,
|
|
218
|
+
fieldId: COLLECTION.fieldId,
|
|
219
|
+
full_path: "".concat(COLLECTION.fieldId, "[0]"),
|
|
220
|
+
key: 'Item 23',
|
|
221
|
+
// includes countOffset
|
|
222
|
+
type: 'title',
|
|
223
|
+
action: null
|
|
224
|
+
});
|
|
225
|
+
(0, _setupTests.expectObjectLike)(ROWS[1], {
|
|
226
|
+
pageId: PAGE.id,
|
|
227
|
+
fieldId: COMPONENT.fieldId,
|
|
228
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
|
|
229
|
+
key: COMPONENT.label,
|
|
230
|
+
action: null,
|
|
231
|
+
component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
|
|
232
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId)
|
|
233
|
+
}),
|
|
234
|
+
value: 'Bravo'
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
it('should use rows produced by the override function if provided', function () {
|
|
238
|
+
var FORM_DATA = {
|
|
239
|
+
collection: [{
|
|
240
|
+
a: 'Bravo'
|
|
241
|
+
}]
|
|
242
|
+
};
|
|
243
|
+
var PAGE = {
|
|
244
|
+
id: 'page',
|
|
245
|
+
formData: FORM_DATA,
|
|
246
|
+
cya_link: {}
|
|
247
|
+
};
|
|
248
|
+
var COMPONENT = {
|
|
249
|
+
type: 'text',
|
|
250
|
+
readonly: true,
|
|
251
|
+
id: 'a',
|
|
252
|
+
fieldId: 'a',
|
|
253
|
+
label: 'Alpha'
|
|
254
|
+
};
|
|
255
|
+
var COLLECTION = {
|
|
256
|
+
id: 'collection',
|
|
257
|
+
fieldId: 'collection',
|
|
258
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
259
|
+
countOffset: 22,
|
|
260
|
+
item: [COMPONENT],
|
|
261
|
+
value: FORM_DATA.collection,
|
|
262
|
+
formData: FORM_DATA
|
|
263
|
+
};
|
|
264
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
265
|
+
// eslint-disable-next-line arrow-body-style
|
|
266
|
+
var OVERRIDE = function OVERRIDE(page, comp) {
|
|
267
|
+
// This will be called for each component in the collection,
|
|
268
|
+
// returning a custom row object.
|
|
269
|
+
return {
|
|
270
|
+
key: "CustomRowFor".concat(comp.label)
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION, OVERRIDE);
|
|
274
|
+
expect(ROWS.length).toEqual(2); // Item title row + component row
|
|
275
|
+
(0, _setupTests.expectObjectLike)(ROWS[0], {
|
|
276
|
+
pageId: PAGE.id,
|
|
277
|
+
fieldId: COLLECTION.fieldId,
|
|
278
|
+
full_path: "".concat(COLLECTION.fieldId, "[0]"),
|
|
279
|
+
key: 'Item 23',
|
|
280
|
+
// includes countOffset
|
|
281
|
+
type: 'title',
|
|
282
|
+
action: null
|
|
283
|
+
});
|
|
284
|
+
(0, _setupTests.expectObjectLike)(ROWS[1], {
|
|
285
|
+
key: "CustomRowFor".concat(COMPONENT.label)
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
@@ -5,79 +5,137 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
|
-
var _elevateNestedComponents = _interopRequireDefault(require("../Component/elevateNestedComponents"));
|
|
9
8
|
var _models = require("../../models");
|
|
10
|
-
var
|
|
9
|
+
var _addShowWhen = _interopRequireDefault(require("../Component/addShowWhen"));
|
|
10
|
+
var _showFormPageCYA = _interopRequireDefault(require("../FormPage/showFormPageCYA"));
|
|
11
11
|
var _getCYACollectionDeleteAction = _interopRequireDefault(require("./getCYACollectionDeleteAction"));
|
|
12
12
|
var _getCYACollectionChangeAction = _interopRequireDefault(require("./getCYACollectionChangeAction"));
|
|
13
|
-
var
|
|
13
|
+
var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
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); }
|
|
15
16
|
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; }
|
|
16
17
|
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; }
|
|
17
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
-
var
|
|
19
|
-
|
|
18
|
+
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; }
|
|
19
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
20
|
+
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); }
|
|
21
|
+
var getContainerForPage = function getContainerForPage(page, item, labelCount, fullPath) {
|
|
20
22
|
return {
|
|
21
23
|
id: item.id,
|
|
22
24
|
fieldId: item.id,
|
|
23
25
|
type: _models.ComponentTypes.CONTAINER,
|
|
24
26
|
required: true,
|
|
25
|
-
full_path:
|
|
26
|
-
components:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return undefined;
|
|
36
|
-
}).filter(function (c) {
|
|
37
|
-
return c;
|
|
27
|
+
full_path: fullPath,
|
|
28
|
+
components: page.components.map(function (component) {
|
|
29
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
30
|
+
label: _copReactComponents.Utils.interpolateString(component.label, _objectSpread(_objectSpread({}, item), {}, {
|
|
31
|
+
index: labelCount
|
|
32
|
+
})),
|
|
33
|
+
full_path: "".concat(fullPath, ".").concat(component.fieldId)
|
|
34
|
+
});
|
|
38
35
|
})
|
|
39
36
|
};
|
|
40
37
|
};
|
|
41
|
-
var getTitleRowForItem = function getTitleRowForItem(page, item, pageId, labelCount,
|
|
38
|
+
var getTitleRowForItem = function getTitleRowForItem(page, item, pageId, labelCount, fullPath) {
|
|
42
39
|
var labels = _objectSpread(_objectSpread({}, _models.CollectionLabels), page.collection.labels);
|
|
43
40
|
return {
|
|
44
41
|
pageId: pageId,
|
|
45
42
|
fieldId: 'Title',
|
|
46
|
-
full_path: "".concat(
|
|
43
|
+
full_path: "".concat(fullPath, ".Title"),
|
|
47
44
|
key: _copReactComponents.Utils.interpolateString(labels.item, _objectSpread(_objectSpread({}, item), {}, {
|
|
48
45
|
index: labelCount
|
|
49
46
|
})),
|
|
50
|
-
type: '
|
|
47
|
+
type: 'heading',
|
|
48
|
+
size: page.collection.titleSize || 's'
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
var getHeadingRow = function getHeadingRow(config, pageId, labelCount) {
|
|
52
|
+
if (config.text === '') {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
pageId: pageId,
|
|
57
|
+
fieldId: "heading".concat(labelCount),
|
|
58
|
+
full_path: "heading".concat(labelCount),
|
|
59
|
+
key: config.text,
|
|
60
|
+
type: 'heading',
|
|
61
|
+
size: config.size || 's'
|
|
51
62
|
};
|
|
52
63
|
};
|
|
53
64
|
var getActionRows = function getActionRows(page, item, onAction, labelCount) {
|
|
54
65
|
var _page$collection, _page$collection$acti;
|
|
55
|
-
|
|
66
|
+
return (_page$collection = page.collection) === null || _page$collection === void 0 ? void 0 : (_page$collection$acti = _page$collection.actions) === null || _page$collection$acti === void 0 ? void 0 : _page$collection$acti.map(function (action) {
|
|
56
67
|
if (action.type === 'remove') {
|
|
57
68
|
return (0, _getCYACollectionDeleteAction.default)(page, item, onAction, labelCount, action);
|
|
58
|
-
}
|
|
69
|
+
}
|
|
70
|
+
if (action.type === 'change') {
|
|
59
71
|
return (0, _getCYACollectionChangeAction.default)(page, item, onAction, labelCount, action);
|
|
60
|
-
} else {
|
|
61
|
-
return null;
|
|
62
72
|
}
|
|
73
|
+
return null;
|
|
63
74
|
}).filter(function (action) {
|
|
64
75
|
return !!action;
|
|
65
76
|
});
|
|
66
|
-
return actions;
|
|
67
77
|
};
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
|
|
79
|
+
// eslint-disable-next-line arrow-body-style
|
|
80
|
+
var getChangeActionForPage = function getChangeActionForPage(page, item, onAction) {
|
|
81
|
+
return function () {
|
|
82
|
+
var changeCallback = function changeCallback(changeData) {
|
|
83
|
+
var data = changeData;
|
|
84
|
+
data["".concat(page.collection.name, "ActiveId")] = item.id;
|
|
85
|
+
return data;
|
|
86
|
+
};
|
|
87
|
+
onAction({
|
|
88
|
+
pageId: page.id
|
|
89
|
+
}, changeCallback);
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onAction, fnOverride) {
|
|
93
|
+
var _page$formData, _page$formData$page$c, _page$formData2, _page$formData2$page$;
|
|
94
|
+
if (!((_page$formData = page.formData) !== null && _page$formData !== void 0 && (_page$formData$page$c = _page$formData[page.collection.name]) !== null && _page$formData$page$c !== void 0 && _page$formData$page$c.length)) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
70
97
|
var rows = [];
|
|
71
|
-
|
|
98
|
+
if (!page.collection.hideNameFromCYA) {
|
|
99
|
+
rows.push({
|
|
100
|
+
pageId: page.id,
|
|
101
|
+
fieldId: "".concat(page.collection.name, "Title"),
|
|
102
|
+
full_path: "".concat(page.collection.name, "Title"),
|
|
103
|
+
key: page.collection.name.charAt(0).toUpperCase() + page.collection.name.slice(1),
|
|
104
|
+
type: 'heading',
|
|
105
|
+
size: 'm'
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
(_page$formData2 = page.formData) === null || _page$formData2 === void 0 ? void 0 : (_page$formData2$page$ = _page$formData2[page.collection.name]) === null || _page$formData2$page$ === void 0 ? void 0 : _page$formData2$page$.forEach(function (item, index) {
|
|
109
|
+
var _page$collection2;
|
|
72
110
|
var labelCount = index + 1;
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
var
|
|
76
|
-
var titleRow = getTitleRowForItem(page, item, page.id, labelCount, full_path);
|
|
111
|
+
var actionPosition = ((_page$collection2 = page.collection) === null || _page$collection2 === void 0 ? void 0 : _page$collection2.actionPosition) || 'top';
|
|
112
|
+
var fullPath = "".concat(page.collection.name, "[").concat(index, "]");
|
|
113
|
+
var titleRow = getTitleRowForItem(page, item, page.id, labelCount, fullPath);
|
|
77
114
|
var actionRows = getActionRows(page, item, onAction, labelCount);
|
|
78
115
|
rows = rows.concat(titleRow);
|
|
79
|
-
|
|
80
|
-
|
|
116
|
+
if (actionPosition === 'top') {
|
|
117
|
+
rows = rows.concat(actionRows);
|
|
118
|
+
}
|
|
119
|
+
page.collectionPages.forEach(function (p) {
|
|
120
|
+
var collectionPage = p;
|
|
121
|
+
if (collectionPage.collection.route) {
|
|
122
|
+
var pageWithRoute = (0, _addShowWhen.default)(collectionPage, p.collection.route);
|
|
123
|
+
collectionPage = pageWithRoute || collectionPage;
|
|
124
|
+
}
|
|
125
|
+
if ((0, _showFormPageCYA.default)(collectionPage, _objectSpread(_objectSpread({}, collectionPage.formData), item))) {
|
|
126
|
+
if (collectionPage.collection.heading) {
|
|
127
|
+
var headingRow = getHeadingRow(collectionPage.collection.heading, collectionPage.id, labelCount);
|
|
128
|
+
rows = rows.concat(headingRow);
|
|
129
|
+
}
|
|
130
|
+
var container = getContainerForPage(collectionPage, item, labelCount, fullPath);
|
|
131
|
+
var rowChangeAction = getChangeActionForPage(collectionPage, item, onAction);
|
|
132
|
+
var containerRows = (0, _getCYARowsForContainer.default)(collectionPage, container, item, rowChangeAction, fnOverride);
|
|
133
|
+
rows = rows.concat(containerRows);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
if (actionPosition === 'bottom') {
|
|
137
|
+
rows = rows.concat(actionRows);
|
|
138
|
+
}
|
|
81
139
|
});
|
|
82
140
|
return rows.filter(function (row) {
|
|
83
141
|
return !!row;
|