@ukhomeoffice/cop-react-form-renderer 5.28.0 → 5.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CollectionSummary/BannerStrip.js +59 -0
- package/dist/components/CollectionSummary/BannerStrip.scss +47 -0
- package/dist/components/CollectionSummary/BannerStrip.test.js +111 -0
- package/dist/components/CollectionSummary/CollectionSummary.js +182 -0
- package/dist/components/CollectionSummary/CollectionSummary.scss +21 -0
- package/dist/components/CollectionSummary/CollectionSummary.test.js +121 -0
- package/dist/components/CollectionSummary/Confirmation.js +58 -0
- package/dist/components/CollectionSummary/Confirmation.scss +14 -0
- package/dist/components/CollectionSummary/Confirmation.test.js +102 -0
- package/dist/components/CollectionSummary/SummaryCard.js +274 -0
- package/dist/components/CollectionSummary/SummaryCard.scss +244 -0
- package/dist/components/CollectionSummary/SummaryCard.test.js +1164 -0
- package/dist/components/CollectionSummary/index.js +10 -0
- package/dist/components/FormComponent/FormComponent.js +19 -3
- package/dist/components/FormPage/FormPage.js +10 -3
- package/dist/components/FormRenderer/FormRenderer.js +1 -0
- package/dist/components/FormRenderer/onPageAction.js +5 -14
- package/dist/components/FormRenderer/onPageAction.test.js +3 -6
- package/dist/models/ComponentTypes.js +2 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +1 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +4 -21
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +32 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +68 -0
- package/dist/utils/CollectionPage/getQuickEditPage.js +74 -0
- package/dist/utils/CollectionPage/getQuickEditPage.test.js +109 -0
- package/dist/utils/CollectionPage/index.js +4 -0
- package/dist/utils/CollectionPage/removeCollectionPageEntry.js +36 -0
- package/dist/utils/CollectionPage/removeCollectionPageEntry.test.js +61 -0
- package/package.json +2 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.DEFAULT_CLASS = void 0;
|
|
7
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
11
|
+
require("./BannerStrip.scss");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
// Global imports.
|
|
14
|
+
|
|
15
|
+
// Local imports.
|
|
16
|
+
|
|
17
|
+
// Styles.
|
|
18
|
+
|
|
19
|
+
var DEFAULT_CLASS = 'hods-form-banner-strip';
|
|
20
|
+
exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
21
|
+
var BannerStrip = function BannerStrip(_ref) {
|
|
22
|
+
var id = _ref.id,
|
|
23
|
+
banners = _ref.banners,
|
|
24
|
+
formData = _ref.formData,
|
|
25
|
+
classModifiers = _ref.classModifiers;
|
|
26
|
+
var classes = _utils.default.classBuilder(DEFAULT_CLASS, classModifiers, '');
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
28
|
+
id: id,
|
|
29
|
+
className: classes()
|
|
30
|
+
}, banners.map(function (banner, index) {
|
|
31
|
+
var bannerId = "".concat(id, "-banner-").concat(index);
|
|
32
|
+
if (typeof banner === 'string') {
|
|
33
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
34
|
+
id: bannerId,
|
|
35
|
+
key: bannerId,
|
|
36
|
+
className: classes('banner')
|
|
37
|
+
}, _utils.default.interpolateString(banner, formData));
|
|
38
|
+
}
|
|
39
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Tag, {
|
|
40
|
+
key: bannerId,
|
|
41
|
+
classBlock: "".concat(DEFAULT_CLASS, "__tag"),
|
|
42
|
+
classModifiers: banner.classModifiers,
|
|
43
|
+
text: _utils.default.interpolateString(banner.text, formData)
|
|
44
|
+
});
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
BannerStrip.propTypes = {
|
|
48
|
+
id: _propTypes.default.string.isRequired,
|
|
49
|
+
banners: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})])),
|
|
50
|
+
formData: _propTypes.default.shape({}),
|
|
51
|
+
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)])
|
|
52
|
+
};
|
|
53
|
+
BannerStrip.defaultProps = {
|
|
54
|
+
banners: [],
|
|
55
|
+
formData: null,
|
|
56
|
+
classModifiers: null
|
|
57
|
+
};
|
|
58
|
+
var _default = BannerStrip;
|
|
59
|
+
exports.default = _default;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
@import "node_modules/govuk-frontend/govuk/_base";
|
|
2
|
+
@import "node_modules/govuk-frontend/govuk/components/tag/_index";
|
|
3
|
+
|
|
4
|
+
.hods-form-banner-strip {
|
|
5
|
+
display: block;
|
|
6
|
+
width: 100%;
|
|
7
|
+
padding: 0;
|
|
8
|
+
margin: 0 0 govuk-spacing(1) 0;
|
|
9
|
+
&__banner {
|
|
10
|
+
@include govuk-font($size: 19, $weight: bold);
|
|
11
|
+
display: inline-block;
|
|
12
|
+
margin-right: govuk-spacing(2);
|
|
13
|
+
}
|
|
14
|
+
&__tag {
|
|
15
|
+
@extend .govuk-tag;
|
|
16
|
+
text-transform: uppercase;
|
|
17
|
+
&--dark-grey{
|
|
18
|
+
background: #5C6367;
|
|
19
|
+
}
|
|
20
|
+
&--white{
|
|
21
|
+
background: #FFFFFF;
|
|
22
|
+
color: #000000;
|
|
23
|
+
border: 1px solid #BFC1C3
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
&--dark-blue{
|
|
27
|
+
background: #005EA5;
|
|
28
|
+
}
|
|
29
|
+
font-weight: bold;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@mixin banner-tag-colours($colour) {
|
|
34
|
+
.hods-form-banner-strip__tag--#{$colour} {
|
|
35
|
+
@extend .govuk-tag--#{$colour};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@include banner-tag-colours('grey');
|
|
40
|
+
@include banner-tag-colours('purple');
|
|
41
|
+
@include banner-tag-colours('turquoise');
|
|
42
|
+
@include banner-tag-colours('blue');
|
|
43
|
+
@include banner-tag-colours('yellow');
|
|
44
|
+
@include banner-tag-colours('orange');
|
|
45
|
+
@include banner-tag-colours('red');
|
|
46
|
+
@include banner-tag-colours('pink');
|
|
47
|
+
@include banner-tag-colours('green');
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
5
|
+
var _react = _interopRequireDefault(require("react"));
|
|
6
|
+
var _setupTests = require("../../setupTests");
|
|
7
|
+
var _BannerStrip = _interopRequireWildcard(require("./BannerStrip"));
|
|
8
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
// Global imports.
|
|
12
|
+
|
|
13
|
+
// Local imports.
|
|
14
|
+
|
|
15
|
+
describe('components.CollectionSummary.BannerStrip', function () {
|
|
16
|
+
var ID = 'testBanner';
|
|
17
|
+
var BANNERS = ['Banner 1', 'Banner 2'];
|
|
18
|
+
var FORM_DATA = {
|
|
19
|
+
textField: 'banner'
|
|
20
|
+
};
|
|
21
|
+
var classes = _copReactComponents.Utils.classBuilder(_BannerStrip.DEFAULT_CLASS, [], '');
|
|
22
|
+
var checkSetup = function checkSetup(container) {
|
|
23
|
+
var bannerStripDiv = container.children[0];
|
|
24
|
+
expect(bannerStripDiv.tagName).toEqual('DIV');
|
|
25
|
+
expect(bannerStripDiv.id).toEqual(ID);
|
|
26
|
+
return bannerStripDiv;
|
|
27
|
+
};
|
|
28
|
+
it('should correctly render a BannerStrip component with plain-text banners', function () {
|
|
29
|
+
var _renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_BannerStrip.default, {
|
|
30
|
+
id: ID,
|
|
31
|
+
banners: BANNERS,
|
|
32
|
+
formData: FORM_DATA
|
|
33
|
+
})),
|
|
34
|
+
container = _renderWithValidation.container;
|
|
35
|
+
var bannerStripDiv = checkSetup(container);
|
|
36
|
+
expect(bannerStripDiv.tagName).toEqual('DIV');
|
|
37
|
+
expect(bannerStripDiv.classList).toContain(_BannerStrip.DEFAULT_CLASS);
|
|
38
|
+
expect(bannerStripDiv.children.length).toEqual(2); // One for each banner provided.
|
|
39
|
+
|
|
40
|
+
var firstBanner = bannerStripDiv.children[0];
|
|
41
|
+
expect(firstBanner.tagName).toEqual('DIV');
|
|
42
|
+
expect(firstBanner.classList).toContain(classes('banner'));
|
|
43
|
+
expect(firstBanner.textContent).toEqual(BANNERS[0]);
|
|
44
|
+
var secondBanner = bannerStripDiv.children[1];
|
|
45
|
+
expect(secondBanner.tagName).toEqual('DIV');
|
|
46
|
+
expect(secondBanner.classList).toContain(classes('banner'));
|
|
47
|
+
expect(secondBanner.textContent).toEqual(BANNERS[1]);
|
|
48
|
+
});
|
|
49
|
+
it('should correctly render a BannerStrip component with tag banners', function () {
|
|
50
|
+
var TAG_BANNERS = [{
|
|
51
|
+
text: 'Banner 1'
|
|
52
|
+
}, {
|
|
53
|
+
text: 'Banner 2'
|
|
54
|
+
}];
|
|
55
|
+
var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_BannerStrip.default, {
|
|
56
|
+
id: ID,
|
|
57
|
+
banners: TAG_BANNERS,
|
|
58
|
+
formData: FORM_DATA
|
|
59
|
+
})),
|
|
60
|
+
container = _renderWithValidation2.container;
|
|
61
|
+
var bannerStripDiv = checkSetup(container);
|
|
62
|
+
expect(bannerStripDiv.tagName).toEqual('DIV');
|
|
63
|
+
expect(bannerStripDiv.classList).toContain(_BannerStrip.DEFAULT_CLASS);
|
|
64
|
+
expect(bannerStripDiv.children.length).toEqual(2); // One for each banner provided.
|
|
65
|
+
|
|
66
|
+
var firstBanner = bannerStripDiv.children[0];
|
|
67
|
+
expect(firstBanner.tagName).toEqual('STRONG');
|
|
68
|
+
expect(firstBanner.classList).toContain(classes('tag'));
|
|
69
|
+
expect(firstBanner.textContent).toEqual(BANNERS[0]);
|
|
70
|
+
var secondBanner = bannerStripDiv.children[1];
|
|
71
|
+
expect(secondBanner.tagName).toEqual('STRONG');
|
|
72
|
+
expect(secondBanner.classList).toContain(classes('tag'));
|
|
73
|
+
expect(secondBanner.textContent).toEqual(BANNERS[1]);
|
|
74
|
+
});
|
|
75
|
+
it('should correctly interpolate banners', function () {
|
|
76
|
+
var INTERPOLATED_BANNERS = [{
|
|
77
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
78
|
+
text: 'An interpolated ${textField}'
|
|
79
|
+
},
|
|
80
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
81
|
+
'Another interpolated ${textField}'];
|
|
82
|
+
var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_BannerStrip.default, {
|
|
83
|
+
id: ID,
|
|
84
|
+
banners: INTERPOLATED_BANNERS,
|
|
85
|
+
formData: FORM_DATA
|
|
86
|
+
})),
|
|
87
|
+
container = _renderWithValidation3.container;
|
|
88
|
+
var bannerStripDiv = checkSetup(container);
|
|
89
|
+
expect(bannerStripDiv.children.length).toEqual(2); // One for each banner provided.
|
|
90
|
+
|
|
91
|
+
var firstBanner = bannerStripDiv.children[0];
|
|
92
|
+
expect(firstBanner.tagName).toEqual('STRONG');
|
|
93
|
+
expect(firstBanner.classList).toContain(classes('tag'));
|
|
94
|
+
expect(firstBanner.textContent).toEqual("An interpolated ".concat(FORM_DATA.textField));
|
|
95
|
+
var secondBanner = bannerStripDiv.children[1];
|
|
96
|
+
expect(secondBanner.tagName).toEqual('DIV');
|
|
97
|
+
expect(secondBanner.classList).toContain(classes('banner'));
|
|
98
|
+
expect(secondBanner.textContent).toEqual("Another interpolated ".concat(FORM_DATA.textField));
|
|
99
|
+
});
|
|
100
|
+
it('should render no banners if none are provided', function () {
|
|
101
|
+
var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_BannerStrip.default, {
|
|
102
|
+
id: ID,
|
|
103
|
+
formData: FORM_DATA
|
|
104
|
+
})),
|
|
105
|
+
container = _renderWithValidation4.container;
|
|
106
|
+
var bannerStripDiv = checkSetup(container);
|
|
107
|
+
expect(bannerStripDiv.tagName).toEqual('DIV');
|
|
108
|
+
expect(bannerStripDiv.classList).toContain(_BannerStrip.DEFAULT_CLASS);
|
|
109
|
+
expect(bannerStripDiv.children.length).toEqual(0);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.DEFAULT_ADD_BUTTON_LABEL = void 0;
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _PageAction = require("../../models/PageAction");
|
|
11
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
12
|
+
var _ActionButton = _interopRequireDefault(require("../PageActions/ActionButton"));
|
|
13
|
+
var _Confirmation = _interopRequireDefault(require("./Confirmation"));
|
|
14
|
+
var _SummaryCard = _interopRequireDefault(require("./SummaryCard"));
|
|
15
|
+
require("./CollectionSummary.scss");
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
|
+
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; }
|
|
22
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
23
|
+
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); }
|
|
24
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
25
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
26
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
28
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
29
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // Global imports.
|
|
30
|
+
// Local imports.
|
|
31
|
+
// Styles.
|
|
32
|
+
var DEFAULT_ADD_BUTTON_LABEL = 'Add';
|
|
33
|
+
exports.DEFAULT_ADD_BUTTON_LABEL = DEFAULT_ADD_BUTTON_LABEL;
|
|
34
|
+
var CollectionSummary = function CollectionSummary(_ref) {
|
|
35
|
+
var _config$confirmation, _config$confirmation2;
|
|
36
|
+
var config = _ref.config,
|
|
37
|
+
formData = _ref.formData,
|
|
38
|
+
onAction = _ref.onAction,
|
|
39
|
+
onChange = _ref.onChange,
|
|
40
|
+
pages = _ref.pages;
|
|
41
|
+
var _useState = (0, _react.useState)(null),
|
|
42
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
43
|
+
entryToDelete = _useState2[0],
|
|
44
|
+
setEntryToDelete = _useState2[1];
|
|
45
|
+
var data = (0, _react.useMemo)(function () {
|
|
46
|
+
return _utils.default.CollectionPage.getData(config.collectionName, formData) || [];
|
|
47
|
+
}, [formData]);
|
|
48
|
+
var masterPage = (0, _react.useMemo)(function () {
|
|
49
|
+
var newMasterPages = _utils.default.CollectionPage.mergePages(pages || []) || [];
|
|
50
|
+
return newMasterPages.find(function (page) {
|
|
51
|
+
var _page$collection;
|
|
52
|
+
return ((_page$collection = page.collection) === null || _page$collection === void 0 ? void 0 : _page$collection.name) === config.collectionName;
|
|
53
|
+
});
|
|
54
|
+
}, [pages]);
|
|
55
|
+
var onSummaryCardChange = function onSummaryCardChange(page, entryId) {
|
|
56
|
+
if (typeof onAction !== 'function') {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
onAction({
|
|
60
|
+
type: _PageAction.PageActionTypes.SAVE_AND_NAVIGATE,
|
|
61
|
+
page: page,
|
|
62
|
+
addToFormData: {
|
|
63
|
+
field: "".concat(config.collectionName.split('.').pop(), "ActiveId"),
|
|
64
|
+
value: entryId
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
var onDuplicate = function onDuplicate(entry) {
|
|
69
|
+
_utils.default.CollectionPage.duplicateEntry(config.collectionName, formData, entry.id);
|
|
70
|
+
var parentCollection = config.collectionName.split('.').shift();
|
|
71
|
+
// Report the whole top-level collection as being changed. We have to do this
|
|
72
|
+
// because of how patch is applied to formData on a page submission.
|
|
73
|
+
if (typeof onChange === 'function') {
|
|
74
|
+
onChange({
|
|
75
|
+
target: {
|
|
76
|
+
name: parentCollection,
|
|
77
|
+
value: _utils.default.CollectionPage.getData(parentCollection, formData)
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var onDeleteConfirm = function onDeleteConfirm() {
|
|
83
|
+
if (!entryToDelete) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
_utils.default.CollectionPage.removeEntry(config.collectionName, formData, entryToDelete.id);
|
|
87
|
+
var parentCollection = config.collectionName.split('.').shift();
|
|
88
|
+
// Report the whole top-level collection as being changed. We have to do this
|
|
89
|
+
// because of how patch is applied to formData on a page submission.
|
|
90
|
+
if (typeof onChange === 'function') {
|
|
91
|
+
onChange({
|
|
92
|
+
target: {
|
|
93
|
+
name: parentCollection,
|
|
94
|
+
value: _utils.default.CollectionPage.getData(parentCollection, formData)
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
setEntryToDelete(null);
|
|
99
|
+
};
|
|
100
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
101
|
+
id: config.fieldId
|
|
102
|
+
}, entryToDelete && /*#__PURE__*/_react.default.createElement(_Confirmation.default, {
|
|
103
|
+
id: "".concat(config.fieldId, ".confirmation"),
|
|
104
|
+
message: _utils.default.interpolateString((_config$confirmation = config.confirmation) === null || _config$confirmation === void 0 ? void 0 : _config$confirmation.message, entryToDelete) || null,
|
|
105
|
+
confirmLabel: _utils.default.interpolateString((_config$confirmation2 = config.confirmation) === null || _config$confirmation2 === void 0 ? void 0 : _config$confirmation2.label, entryToDelete) || null,
|
|
106
|
+
onConfirm: onDeleteConfirm,
|
|
107
|
+
onCancel: function onCancel() {
|
|
108
|
+
return setEntryToDelete(null);
|
|
109
|
+
}
|
|
110
|
+
}, /*#__PURE__*/_react.default.createElement(_SummaryCard.default, {
|
|
111
|
+
id: "".concat(config.fieldId, ".confirmationChild"),
|
|
112
|
+
entryData: entryToDelete,
|
|
113
|
+
config: config.card ? _objectSpread(_objectSpread({}, config.card), {}, {
|
|
114
|
+
quickEdit: null
|
|
115
|
+
}) : {},
|
|
116
|
+
masterPage: masterPage,
|
|
117
|
+
classModifiers: "nested",
|
|
118
|
+
hideDetails: true
|
|
119
|
+
})), config.addButton && /*#__PURE__*/_react.default.createElement(_ActionButton.default, {
|
|
120
|
+
id: "".concat(config.fieldId, ".addButton"),
|
|
121
|
+
action: {
|
|
122
|
+
collection: config.collectionName,
|
|
123
|
+
label: config.addButton.label || DEFAULT_ADD_BUTTON_LABEL,
|
|
124
|
+
page: config.addButton.page,
|
|
125
|
+
type: _PageAction.PageActionTypes.COLLECTION_ADD,
|
|
126
|
+
classModifiers: ['secondary']
|
|
127
|
+
},
|
|
128
|
+
onAction: onAction
|
|
129
|
+
}), data.map(function (entry, index) {
|
|
130
|
+
var key = "".concat(config.fieldId, ".summaryCard").concat(entry.id);
|
|
131
|
+
return /*#__PURE__*/_react.default.createElement(_SummaryCard.default, {
|
|
132
|
+
id: key,
|
|
133
|
+
key: key,
|
|
134
|
+
entryData: _objectSpread(_objectSpread({}, entry), {}, {
|
|
135
|
+
index: index
|
|
136
|
+
}),
|
|
137
|
+
masterPage: masterPage,
|
|
138
|
+
config: config.card || {},
|
|
139
|
+
onChange: onSummaryCardChange,
|
|
140
|
+
onDuplicate: onDuplicate,
|
|
141
|
+
onDelete: function onDelete() {
|
|
142
|
+
return setEntryToDelete(entry);
|
|
143
|
+
},
|
|
144
|
+
pages: pages,
|
|
145
|
+
onQuickEdit: function onQuickEdit(target) {
|
|
146
|
+
return onChange(target);
|
|
147
|
+
},
|
|
148
|
+
parentCollectionName: config.collectionName.split('.').shift(),
|
|
149
|
+
formData: formData
|
|
150
|
+
});
|
|
151
|
+
}));
|
|
152
|
+
};
|
|
153
|
+
CollectionSummary.propTypes = {
|
|
154
|
+
config: _propTypes.default.shape({
|
|
155
|
+
fieldId: _propTypes.default.string.isRequired,
|
|
156
|
+
collectionName: _propTypes.default.string.isRequired,
|
|
157
|
+
addButton: _propTypes.default.shape({
|
|
158
|
+
label: _propTypes.default.string,
|
|
159
|
+
page: _propTypes.default.string.isRequired
|
|
160
|
+
}),
|
|
161
|
+
card: _propTypes.default.shape({
|
|
162
|
+
banners: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})])),
|
|
163
|
+
title: _propTypes.default.string,
|
|
164
|
+
details: _propTypes.default.string
|
|
165
|
+
}),
|
|
166
|
+
confirmation: _propTypes.default.shape({
|
|
167
|
+
message: _propTypes.default.string,
|
|
168
|
+
label: _propTypes.default.string
|
|
169
|
+
})
|
|
170
|
+
}).isRequired,
|
|
171
|
+
onAction: _propTypes.default.func,
|
|
172
|
+
onChange: _propTypes.default.func,
|
|
173
|
+
formData: _propTypes.default.shape({}).isRequired,
|
|
174
|
+
pages: _propTypes.default.arrayOf(_propTypes.default.shape({}))
|
|
175
|
+
};
|
|
176
|
+
CollectionSummary.defaultProps = {
|
|
177
|
+
onAction: null,
|
|
178
|
+
onChange: null,
|
|
179
|
+
pages: []
|
|
180
|
+
};
|
|
181
|
+
var _default = CollectionSummary;
|
|
182
|
+
exports.default = _default;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
@import "node_modules/govuk-frontend/govuk/_base";
|
|
2
|
+
|
|
3
|
+
.hods-form-summary-card.hods-form-summary-card--nested {
|
|
4
|
+
box-shadow: none;
|
|
5
|
+
border: none;
|
|
6
|
+
padding: 0;
|
|
7
|
+
margin-bottom: govuk-spacing(2);
|
|
8
|
+
|
|
9
|
+
.hods-form-summary-card {
|
|
10
|
+
&__header {
|
|
11
|
+
width: auto;
|
|
12
|
+
display: flex;
|
|
13
|
+
flex-direction: row;
|
|
14
|
+
@media (max-width: 640px) {
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
}
|
|
17
|
+
color: #0b0c0c;
|
|
18
|
+
padding: 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _setupTests = require("../../setupTests");
|
|
7
|
+
var _CollectionSummary = _interopRequireWildcard(require("./CollectionSummary"));
|
|
8
|
+
var _Confirmation = require("./Confirmation");
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
// Global imports.
|
|
13
|
+
|
|
14
|
+
// Local imports.
|
|
15
|
+
|
|
16
|
+
describe('components.CollectionSummary.CollectionSummary', function () {
|
|
17
|
+
var CONFIG = {
|
|
18
|
+
id: 'testSummary',
|
|
19
|
+
fieldId: 'testSummary',
|
|
20
|
+
collectionName: 'testCollection',
|
|
21
|
+
card: {
|
|
22
|
+
title: 'Title',
|
|
23
|
+
deleteAction: {
|
|
24
|
+
label: 'Delete'
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var FORM_DATA = {
|
|
29
|
+
testCollectionActiveId: '001',
|
|
30
|
+
testCollection: [{
|
|
31
|
+
id: '000'
|
|
32
|
+
}, {
|
|
33
|
+
id: '001'
|
|
34
|
+
}]
|
|
35
|
+
};
|
|
36
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
37
|
+
var checkSetup = function checkSetup(container) {
|
|
38
|
+
var summaryDiv = container.children[0];
|
|
39
|
+
expect(summaryDiv.tagName).toEqual('DIV');
|
|
40
|
+
return summaryDiv;
|
|
41
|
+
};
|
|
42
|
+
it('should correctly render a CollectionSummary component', function () {
|
|
43
|
+
var _renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
44
|
+
config: CONFIG,
|
|
45
|
+
formData: FORM_DATA,
|
|
46
|
+
onAction: ON_ACTION
|
|
47
|
+
})),
|
|
48
|
+
container = _renderWithValidation.container;
|
|
49
|
+
var summary = checkSetup(container);
|
|
50
|
+
expect(summary.children.length).toEqual(2);
|
|
51
|
+
expect(summary.children[0].id).toEqual("".concat(CONFIG.fieldId, ".summaryCard").concat(FORM_DATA.testCollection[0].id));
|
|
52
|
+
expect(summary.children[1].id).toEqual("".concat(CONFIG.fieldId, ".summaryCard").concat(FORM_DATA.testCollection[1].id));
|
|
53
|
+
});
|
|
54
|
+
it('should render a confirmation when a SummaryCard\'s delete button is pressed', function () {
|
|
55
|
+
var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
56
|
+
config: CONFIG,
|
|
57
|
+
formData: FORM_DATA,
|
|
58
|
+
onAction: ON_ACTION
|
|
59
|
+
})),
|
|
60
|
+
container = _renderWithValidation2.container;
|
|
61
|
+
var summary = checkSetup(container);
|
|
62
|
+
expect(summary.children.length).toEqual(2);
|
|
63
|
+
var card = summary.children[0];
|
|
64
|
+
var deleteButton = card.children[0].children[1].children[0];
|
|
65
|
+
_react2.fireEvent.click(deleteButton, {});
|
|
66
|
+
expect(summary.children.length).toEqual(3); // Now with a confirmation.
|
|
67
|
+
expect(summary.children[0].id).toEqual("".concat(CONFIG.fieldId, ".confirmation"));
|
|
68
|
+
expect(summary.children[0].classList).toContain(_Confirmation.DEFAULT_CLASS);
|
|
69
|
+
});
|
|
70
|
+
describe('Add Another button', function () {
|
|
71
|
+
it('should render with an Add button if one is configured', function () {
|
|
72
|
+
var CONFIG_WITH_BUTTON = {
|
|
73
|
+
id: 'testSummary',
|
|
74
|
+
fieldId: 'testSummary',
|
|
75
|
+
collectionName: 'testCollection',
|
|
76
|
+
addButton: {
|
|
77
|
+
label: 'Add another item',
|
|
78
|
+
page: 'nextPage'
|
|
79
|
+
},
|
|
80
|
+
card: {
|
|
81
|
+
title: 'Title'
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
85
|
+
config: CONFIG_WITH_BUTTON,
|
|
86
|
+
formData: FORM_DATA,
|
|
87
|
+
onAction: ON_ACTION
|
|
88
|
+
})),
|
|
89
|
+
container = _renderWithValidation3.container;
|
|
90
|
+
var summary = checkSetup(container);
|
|
91
|
+
expect(summary.children.length).toEqual(3); // The button and a card for each item.
|
|
92
|
+
expect(summary.children[0].id).toEqual("".concat(CONFIG_WITH_BUTTON.fieldId, ".addButton"));
|
|
93
|
+
expect(summary.children[0].textContent).toEqual(CONFIG_WITH_BUTTON.addButton.label);
|
|
94
|
+
expect(summary.children[0].tagName).toEqual('BUTTON');
|
|
95
|
+
});
|
|
96
|
+
it('should use the default button label if none is provided', function () {
|
|
97
|
+
var CONFIG_WITH_BUTTON = {
|
|
98
|
+
id: 'testSummary',
|
|
99
|
+
fieldId: 'testSummary',
|
|
100
|
+
collectionName: 'testCollection',
|
|
101
|
+
addButton: {
|
|
102
|
+
page: 'nextPage'
|
|
103
|
+
},
|
|
104
|
+
card: {
|
|
105
|
+
title: 'Title'
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
109
|
+
config: CONFIG_WITH_BUTTON,
|
|
110
|
+
formData: FORM_DATA,
|
|
111
|
+
onAction: ON_ACTION
|
|
112
|
+
})),
|
|
113
|
+
container = _renderWithValidation4.container;
|
|
114
|
+
var summary = checkSetup(container);
|
|
115
|
+
expect(summary.children.length).toEqual(3); // The button and a card for each item.
|
|
116
|
+
expect(summary.children[0].id).toEqual("".concat(CONFIG_WITH_BUTTON.fieldId, ".addButton"));
|
|
117
|
+
expect(summary.children[0].textContent).toEqual(_CollectionSummary.DEFAULT_ADD_BUTTON_LABEL);
|
|
118
|
+
expect(summary.children[0].tagName).toEqual('BUTTON');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.DEFAULT_MESSAGE = exports.DEFAULT_CONFIRM_LABEL = exports.DEFAULT_CLASS = void 0;
|
|
7
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
require("./Confirmation.scss");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
// Global imports.
|
|
13
|
+
|
|
14
|
+
// Styles.
|
|
15
|
+
|
|
16
|
+
var DEFAULT_CLASS = 'hods-form-confirmation';
|
|
17
|
+
exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
18
|
+
var DEFAULT_MESSAGE = 'Are you sure?';
|
|
19
|
+
exports.DEFAULT_MESSAGE = DEFAULT_MESSAGE;
|
|
20
|
+
var DEFAULT_CONFIRM_LABEL = 'Confirm';
|
|
21
|
+
exports.DEFAULT_CONFIRM_LABEL = DEFAULT_CONFIRM_LABEL;
|
|
22
|
+
var Confirmation = function Confirmation(_ref) {
|
|
23
|
+
var id = _ref.id,
|
|
24
|
+
message = _ref.message,
|
|
25
|
+
confirmLabel = _ref.confirmLabel,
|
|
26
|
+
children = _ref.children,
|
|
27
|
+
onConfirm = _ref.onConfirm,
|
|
28
|
+
onCancel = _ref.onCancel,
|
|
29
|
+
classModifiers = _ref.classModifiers;
|
|
30
|
+
var classes = _copReactComponents.Utils.classBuilder(DEFAULT_CLASS, classModifiers, '');
|
|
31
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
32
|
+
id: id,
|
|
33
|
+
className: classes()
|
|
34
|
+
}, /*#__PURE__*/_react.default.createElement("h2", null, message || DEFAULT_MESSAGE), children, /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
35
|
+
classModifiers: "warning",
|
|
36
|
+
onClick: onConfirm
|
|
37
|
+
}, confirmLabel || DEFAULT_CONFIRM_LABEL), /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
38
|
+
classModifiers: "secondary",
|
|
39
|
+
onClick: onCancel
|
|
40
|
+
}, "Cancel"));
|
|
41
|
+
};
|
|
42
|
+
Confirmation.propTypes = {
|
|
43
|
+
id: _propTypes.default.string.isRequired,
|
|
44
|
+
message: _propTypes.default.string,
|
|
45
|
+
confirmLabel: _propTypes.default.string,
|
|
46
|
+
children: _propTypes.default.node,
|
|
47
|
+
onConfirm: _propTypes.default.func.isRequired,
|
|
48
|
+
onCancel: _propTypes.default.func.isRequired,
|
|
49
|
+
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)])
|
|
50
|
+
};
|
|
51
|
+
Confirmation.defaultProps = {
|
|
52
|
+
message: null,
|
|
53
|
+
confirmLabel: null,
|
|
54
|
+
children: null,
|
|
55
|
+
classModifiers: []
|
|
56
|
+
};
|
|
57
|
+
var _default = Confirmation;
|
|
58
|
+
exports.default = _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
$govuk-font-family: 'Roboto', arial, sans-serif;
|
|
2
|
+
|
|
3
|
+
@import "node_modules/govuk-frontend/govuk/_base";
|
|
4
|
+
|
|
5
|
+
.hods-form-confirmation {
|
|
6
|
+
background-color: #E3E3E3;
|
|
7
|
+
padding: govuk-spacing(1) govuk-spacing(3) govuk-spacing(3);
|
|
8
|
+
margin-bottom: govuk-spacing(3);
|
|
9
|
+
|
|
10
|
+
.hods-button--warning {
|
|
11
|
+
@extend .hods-button--warning;
|
|
12
|
+
margin-right: govuk-spacing(2);
|
|
13
|
+
}
|
|
14
|
+
}
|