@k-int/stripes-kint-components 2.7.1 → 2.8.2
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/CHANGELOG.md +14 -1
- package/es/index.js +20 -0
- package/es/lib/ActionList/ActionList.js +7 -2
- package/es/lib/ActionList/ActionListFieldArray.js +11 -5
- package/es/lib/CustomProperties/Config/CustomPropertiesSettings.js +3 -1
- package/es/lib/CustomProperties/View/CustomPropertiesViewCtx.js +1 -1
- package/es/lib/CycleButton/CycleButton.js +2 -1
- package/es/lib/EditableRefdataCategoryList/EditableRefdataCategoryList.js +11 -2
- package/es/lib/EditableRefdataList/EditableRefdataList.js +11 -2
- package/es/lib/IconSelect/IconSelect.js +105 -110
- package/es/lib/RichSelect/RichSelect.js +252 -0
- package/es/lib/RichSelect/index.js +23 -0
- package/es/lib/RichSelect/useSelectedOption.js +39 -0
- package/es/lib/utils/index.js +8 -0
- package/es/lib/utils/parseErrorResponse.js +91 -0
- package/package.json +1 -1
- package/src/index.js +2 -0
- package/src/lib/ActionList/ActionList.js +8 -1
- package/src/lib/ActionList/ActionListFieldArray.js +13 -5
- package/src/lib/ActionList/README.md +1 -0
- package/src/lib/CustomProperties/Config/CustomPropertiesSettings.js +3 -1
- package/src/lib/CustomProperties/View/CustomPropertiesViewCtx.js +1 -1
- package/src/lib/CycleButton/CycleButton.js +3 -2
- package/src/lib/EditableRefdataCategoryList/EditableRefdataCategoryList.js +10 -2
- package/src/lib/EditableRefdataList/EditableRefdataList.js +10 -2
- package/src/lib/IconSelect/IconSelect.js +94 -113
- package/src/lib/IconSelect/README.md +6 -2
- package/src/lib/RichSelect/README.md +56 -0
- package/src/lib/RichSelect/RichSelect.js +230 -0
- package/src/lib/RichSelect/index.js +2 -0
- package/src/lib/RichSelect/useSelectedOption.js +14 -0
- package/src/lib/hooks/useMutateRefdataCategory.js +3 -3
- package/src/lib/utils/index.js +3 -0
- package/src/lib/utils/parseErrorResponse.js +18 -0
- package/styles/RichSelect.css +7 -0
- package/translations/stripes-kint-components/ar.json +2 -1
- package/translations/stripes-kint-components/cs_CZ.json +2 -1
- package/translations/stripes-kint-components/de.json +2 -1
- package/translations/stripes-kint-components/en.json +2 -1
- package/translations/stripes-kint-components/es.json +2 -1
- package/translations/stripes-kint-components/hi_IN.json +2 -1
- package/translations/stripes-kint-components/hu.json +2 -1
- package/translations/stripes-kint-components/it_IT.json +2 -1
- package/translations/stripes-kint-components/ja.json +2 -1
- package/translations/stripes-kint-components/ko.json +2 -1
- package/translations/stripes-kint-components/pt_PT.json +2 -1
- package/translations/stripes-kint-components/ru.json +2 -1
- package/translations/stripes-kint-components/sv.json +2 -1
- package/translations/stripes-kint-components/zh_CN.json +2 -1
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _reactIntl = require("react-intl");
|
|
13
|
+
|
|
14
|
+
var _components = require("@folio/stripes/components");
|
|
15
|
+
|
|
16
|
+
var _RichSelect = _interopRequireDefault(require("../../../styles/RichSelect.css"));
|
|
17
|
+
|
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
29
|
+
|
|
30
|
+
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."); }
|
|
31
|
+
|
|
32
|
+
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); }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
37
|
+
|
|
38
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
39
|
+
|
|
40
|
+
var RichSelect = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
41
|
+
var _ref2, _meta$initial, _findSelectedOptionBy, _meta$initial2;
|
|
42
|
+
|
|
43
|
+
var ariaLabel = _ref.ariaLabel,
|
|
44
|
+
_ref$disabled = _ref.disabled,
|
|
45
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
46
|
+
_ref$dropdownProps = _ref.dropdownProps,
|
|
47
|
+
dropdownProps = _ref$dropdownProps === void 0 ? {} : _ref$dropdownProps,
|
|
48
|
+
id = _ref.id,
|
|
49
|
+
_ref$input = _ref.input,
|
|
50
|
+
formInput = _ref$input === void 0 ? {} : _ref$input,
|
|
51
|
+
label = _ref.label,
|
|
52
|
+
meta = _ref.meta,
|
|
53
|
+
onChange = _ref.onChange,
|
|
54
|
+
_ref$options = _ref.options,
|
|
55
|
+
userOptions = _ref$options === void 0 ? [] : _ref$options,
|
|
56
|
+
placeholder = _ref.placeholder,
|
|
57
|
+
_renderMenu = _ref.renderMenu,
|
|
58
|
+
renderOption = _ref.renderOption,
|
|
59
|
+
_renderTrigger = _ref.renderTrigger,
|
|
60
|
+
_ref$required = _ref.required,
|
|
61
|
+
required = _ref$required === void 0 ? false : _ref$required,
|
|
62
|
+
value = _ref.value;
|
|
63
|
+
var hiddenInput = (0, _react.useRef)(null);
|
|
64
|
+
|
|
65
|
+
var _useState = (0, _react.useState)((_ref2 = (_meta$initial = meta === null || meta === void 0 ? void 0 : meta.initial) !== null && _meta$initial !== void 0 ? _meta$initial : value) !== null && _ref2 !== void 0 ? _ref2 : ''),
|
|
66
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
67
|
+
internalValue = _useState2[0],
|
|
68
|
+
setInternalValue = _useState2[1];
|
|
69
|
+
|
|
70
|
+
var findSelectedOptionByValue = (0, _react.useCallback)(function (val) {
|
|
71
|
+
return userOptions.find(function (opt) {
|
|
72
|
+
return opt.value === val;
|
|
73
|
+
});
|
|
74
|
+
}, [userOptions]);
|
|
75
|
+
|
|
76
|
+
var _useState3 = (0, _react.useState)((_findSelectedOptionBy = findSelectedOptionByValue((_meta$initial2 = meta === null || meta === void 0 ? void 0 : meta.initial) !== null && _meta$initial2 !== void 0 ? _meta$initial2 : '')) !== null && _findSelectedOptionBy !== void 0 ? _findSelectedOptionBy : {}),
|
|
77
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
78
|
+
selectedOption = _useState4[0],
|
|
79
|
+
setSelectedOption = _useState4[1];
|
|
80
|
+
|
|
81
|
+
(0, _react.useEffect)(function () {
|
|
82
|
+
// We treat non-undefined value/formInput values as valid values, whereas undefined is only relevant when prop has not been provided
|
|
83
|
+
if (value !== undefined && !(value === (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) && value === internalValue)) {
|
|
84
|
+
setSelectedOption(findSelectedOptionByValue(value));
|
|
85
|
+
setInternalValue(value);
|
|
86
|
+
} else if ((formInput === null || formInput === void 0 ? void 0 : formInput.value) !== undefined && !(value === (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) && value === internalValue)) {
|
|
87
|
+
setSelectedOption(findSelectedOptionByValue(formInput.value));
|
|
88
|
+
setInternalValue(formInput.value);
|
|
89
|
+
}
|
|
90
|
+
}, [formInput, value, internalValue, selectedOption, findSelectedOptionByValue]); // Way to grab internal selectedOption state, thereby avoiding having to reparse options for it
|
|
91
|
+
|
|
92
|
+
(0, _react.useImperativeHandle)(ref, function () {
|
|
93
|
+
return {
|
|
94
|
+
selectedOption: selectedOption
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
var defaultRenderTrigger = function defaultRenderTrigger(_ref3) {
|
|
99
|
+
var _ref4, _ref5, _ref6, _selectedOption$label;
|
|
100
|
+
|
|
101
|
+
var onToggle = _ref3.onToggle,
|
|
102
|
+
triggerRef = _ref3.triggerRef,
|
|
103
|
+
keyHandler = _ref3.keyHandler,
|
|
104
|
+
open = _ref3.open,
|
|
105
|
+
ariaProps = _ref3.ariaProps,
|
|
106
|
+
getTriggerProps = _ref3.getTriggerProps;
|
|
107
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, _objectSpread(_objectSpread(_objectSpread({
|
|
108
|
+
ref: triggerRef,
|
|
109
|
+
buttonClass: _RichSelect.default.iconButtonText,
|
|
110
|
+
buttonStyle: "none",
|
|
111
|
+
disabled: disabled,
|
|
112
|
+
marginBottom0: true,
|
|
113
|
+
onClick: onToggle,
|
|
114
|
+
onKeyDown: keyHandler,
|
|
115
|
+
paddingSide0: true,
|
|
116
|
+
type: "button"
|
|
117
|
+
}, getTriggerProps()), ariaProps), {}, {
|
|
118
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
|
|
119
|
+
icon: open ? 'caret-up' : 'caret-down',
|
|
120
|
+
iconPosition: "end",
|
|
121
|
+
children: (_ref4 = (_ref5 = (_ref6 = (_selectedOption$label = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) !== null && _selectedOption$label !== void 0 ? _selectedOption$label : selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) !== null && _ref6 !== void 0 ? _ref6 : internalValue || null) !== null && _ref5 !== void 0 ? _ref5 : placeholder) !== null && _ref4 !== void 0 ? _ref4 : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
122
|
+
id: "stripes-kint-components.richSelect.placeholder"
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
})) // Awaiting result of conversation about whether we want to allow labels on IconButtons
|
|
126
|
+
|
|
127
|
+
/* <IconButton
|
|
128
|
+
ref={triggerRef}
|
|
129
|
+
disabled={disabled}
|
|
130
|
+
icon={open ? 'caret-up' : 'caret-down'}
|
|
131
|
+
iconPosition="end"
|
|
132
|
+
marginBottom0
|
|
133
|
+
onClick={onToggle}
|
|
134
|
+
onKeyDown={keyHandler}
|
|
135
|
+
type="button"
|
|
136
|
+
{...getTriggerProps()}
|
|
137
|
+
{...ariaProps}
|
|
138
|
+
>
|
|
139
|
+
{
|
|
140
|
+
selectedOption?.label ??
|
|
141
|
+
selectedOption?.value ??
|
|
142
|
+
(internalValue ? internalValue : null) ??
|
|
143
|
+
placeholder ??
|
|
144
|
+
<FormattedMessage id="stripes-kint-components.richSelect.placeholder" />
|
|
145
|
+
}
|
|
146
|
+
</IconButton> */
|
|
147
|
+
;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var handleChange = function handleChange(e) {
|
|
151
|
+
// Actually set the value in the form (If formInput exists)
|
|
152
|
+
if (formInput !== null && formInput !== void 0 && formInput.onChange) {
|
|
153
|
+
formInput.onChange(e);
|
|
154
|
+
} // If the user has set up an onChange, this will ensure that that fires
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
if (onChange) {
|
|
158
|
+
onChange(e, e.target.value);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
var changeField = function changeField(val) {
|
|
163
|
+
(0, _components.nativeChangeFieldValue)(hiddenInput, false, val);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
var defaultRenderOption = function defaultRenderOption(opt) {
|
|
167
|
+
var _opt$label;
|
|
168
|
+
|
|
169
|
+
return (_opt$label = opt.label) !== null && _opt$label !== void 0 ? _opt$label : opt.value;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
var defaultRenderMenu = function defaultRenderMenu(_ref7) {
|
|
173
|
+
var onToggle = _ref7.onToggle;
|
|
174
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.DropdownMenu, {
|
|
175
|
+
children: userOptions.map(function (opt) {
|
|
176
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
177
|
+
autoFocus: (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) === opt.value,
|
|
178
|
+
buttonStyle: "dropdownItem",
|
|
179
|
+
id: "".concat(id, "-").concat(formInput.name, "-option-").concat(opt.value),
|
|
180
|
+
marginBottom0: true,
|
|
181
|
+
onClick: function onClick() {
|
|
182
|
+
// Trigger change event
|
|
183
|
+
changeField(opt.value); // Close the menu on select
|
|
184
|
+
|
|
185
|
+
onToggle();
|
|
186
|
+
},
|
|
187
|
+
children: renderOption ? renderOption(opt) : defaultRenderOption(opt)
|
|
188
|
+
});
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
194
|
+
children: [label || ariaLabel ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Label, {
|
|
195
|
+
className: ariaLabel && 'sr-only',
|
|
196
|
+
htmlFor: id,
|
|
197
|
+
id: "".concat(id, "-label"),
|
|
198
|
+
required: required,
|
|
199
|
+
children: ariaLabel || label
|
|
200
|
+
}) : '', /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Dropdown, _objectSpread({
|
|
201
|
+
hasPadding: true,
|
|
202
|
+
placement: "bottom-start",
|
|
203
|
+
renderMenu: function renderMenu(menuProps) {
|
|
204
|
+
if (_renderMenu) {
|
|
205
|
+
return _renderMenu(_objectSpread(_objectSpread({}, menuProps), {}, {
|
|
206
|
+
selectedOption: selectedOption,
|
|
207
|
+
changeField: changeField
|
|
208
|
+
}));
|
|
209
|
+
} else {
|
|
210
|
+
return defaultRenderMenu(menuProps);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
renderTrigger: function renderTrigger(triggerProps) {
|
|
214
|
+
if (_renderTrigger) {
|
|
215
|
+
return _renderTrigger(_objectSpread(_objectSpread({}, triggerProps), {}, {
|
|
216
|
+
selectedOption: selectedOption
|
|
217
|
+
}));
|
|
218
|
+
} else {
|
|
219
|
+
return defaultRenderTrigger(triggerProps);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}, dropdownProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({}, formInput), {}, {
|
|
223
|
+
ref: hiddenInput,
|
|
224
|
+
hidden: true,
|
|
225
|
+
onChange: handleChange,
|
|
226
|
+
type: "text",
|
|
227
|
+
value: internalValue
|
|
228
|
+
}))]
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
RichSelect.propTypes = {
|
|
232
|
+
ariaLabel: _propTypes.default.string,
|
|
233
|
+
disabled: _propTypes.default.bool,
|
|
234
|
+
dropdownProps: _propTypes.default.object,
|
|
235
|
+
id: _propTypes.default.string,
|
|
236
|
+
input: _propTypes.default.object,
|
|
237
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func, _propTypes.default.node]),
|
|
238
|
+
meta: _propTypes.default.object,
|
|
239
|
+
onChange: _propTypes.default.func,
|
|
240
|
+
options: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
241
|
+
value: _propTypes.default.string.isRequired,
|
|
242
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node])
|
|
243
|
+
})),
|
|
244
|
+
placeholder: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]),
|
|
245
|
+
renderMenu: _propTypes.default.func,
|
|
246
|
+
renderOption: _propTypes.default.func,
|
|
247
|
+
renderTrigger: _propTypes.default.func,
|
|
248
|
+
required: _propTypes.default.bool,
|
|
249
|
+
value: _propTypes.default.string
|
|
250
|
+
};
|
|
251
|
+
var _default = RichSelect;
|
|
252
|
+
exports.default = _default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _RichSelect.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "useSelectedOption", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _useSelectedOption.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _RichSelect = _interopRequireDefault(require("./RichSelect"));
|
|
20
|
+
|
|
21
|
+
var _useSelectedOption = _interopRequireDefault(require("./useSelectedOption"));
|
|
22
|
+
|
|
23
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
|
|
12
|
+
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."); }
|
|
13
|
+
|
|
14
|
+
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); }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
19
|
+
|
|
20
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
+
|
|
22
|
+
var useSelectedOption = function useSelectedOption() {
|
|
23
|
+
var _useState = (0, _react.useState)(),
|
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
25
|
+
selectedOption = _useState2[0],
|
|
26
|
+
setSelectedOption = _useState2[1];
|
|
27
|
+
|
|
28
|
+
var ref = (0, _react.useCallback)(function (node) {
|
|
29
|
+
var _node$selectedOption;
|
|
30
|
+
|
|
31
|
+
if (node !== null && (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) !== ((_node$selectedOption = node.selectedOption) === null || _node$selectedOption === void 0 ? void 0 : _node$selectedOption.value)) {
|
|
32
|
+
setSelectedOption(node.selectedOption);
|
|
33
|
+
}
|
|
34
|
+
}, [selectedOption]);
|
|
35
|
+
return [ref, selectedOption];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
var _default = useSelectedOption;
|
|
39
|
+
exports.default = _default;
|
package/es/lib/utils/index.js
CHANGED
|
@@ -45,6 +45,12 @@ Object.defineProperty(exports, "matchString", {
|
|
|
45
45
|
return _matchString.default;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
+
Object.defineProperty(exports, "parseErrorResponse", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function get() {
|
|
51
|
+
return _parseErrorResponse.default;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
48
54
|
Object.defineProperty(exports, "refdataOptions", {
|
|
49
55
|
enumerable: true,
|
|
50
56
|
get: function get() {
|
|
@@ -114,4 +120,6 @@ var _matchString = _interopRequireDefault(require("./matchString"));
|
|
|
114
120
|
|
|
115
121
|
var _highlightString = require("./highlightString");
|
|
116
122
|
|
|
123
|
+
var _parseErrorResponse = _interopRequireDefault(require("./parseErrorResponse"));
|
|
124
|
+
|
|
117
125
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
11
|
+
|
|
12
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
13
|
+
|
|
14
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
|
|
16
|
+
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); }
|
|
17
|
+
|
|
18
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
19
|
+
|
|
20
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
25
|
+
|
|
26
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
27
|
+
|
|
28
|
+
var parseErrorResponse = /*#__PURE__*/function () {
|
|
29
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(responseObj) {
|
|
30
|
+
var _ref2, _ref2$find;
|
|
31
|
+
|
|
32
|
+
var errorResp, contentType;
|
|
33
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
34
|
+
while (1) {
|
|
35
|
+
switch (_context.prev = _context.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
contentType = (_ref2 = _toConsumableArray(responseObj === null || responseObj === void 0 ? void 0 : responseObj.headers)) === null || _ref2 === void 0 ? void 0 : (_ref2$find = _ref2.find(function (header) {
|
|
38
|
+
return header[0] === 'content-type';
|
|
39
|
+
})) === null || _ref2$find === void 0 ? void 0 : _ref2$find[1];
|
|
40
|
+
|
|
41
|
+
if (!contentType.includes('json')) {
|
|
42
|
+
_context.next = 7;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_context.next = 4;
|
|
47
|
+
return responseObj.json();
|
|
48
|
+
|
|
49
|
+
case 4:
|
|
50
|
+
errorResp = _context.sent;
|
|
51
|
+
_context.next = 17;
|
|
52
|
+
break;
|
|
53
|
+
|
|
54
|
+
case 7:
|
|
55
|
+
_context.prev = 7;
|
|
56
|
+
_context.next = 10;
|
|
57
|
+
return responseObj.text();
|
|
58
|
+
|
|
59
|
+
case 10:
|
|
60
|
+
_context.t0 = _context.sent;
|
|
61
|
+
errorResp = {
|
|
62
|
+
message: _context.t0
|
|
63
|
+
};
|
|
64
|
+
_context.next = 17;
|
|
65
|
+
break;
|
|
66
|
+
|
|
67
|
+
case 14:
|
|
68
|
+
_context.prev = 14;
|
|
69
|
+
_context.t1 = _context["catch"](7);
|
|
70
|
+
errorResp = {
|
|
71
|
+
message: "something went wrong"
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
case 17:
|
|
75
|
+
return _context.abrupt("return", errorResp);
|
|
76
|
+
|
|
77
|
+
case 18:
|
|
78
|
+
case "end":
|
|
79
|
+
return _context.stop();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, _callee, null, [[7, 14]]);
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
return function parseErrorResponse(_x) {
|
|
86
|
+
return _ref.apply(this, arguments);
|
|
87
|
+
};
|
|
88
|
+
}();
|
|
89
|
+
|
|
90
|
+
var _default = parseErrorResponse;
|
|
91
|
+
exports.default = _default;
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export {
|
|
|
29
29
|
refdataQueryKey,
|
|
30
30
|
selectorSafe,
|
|
31
31
|
typedownQueryKey,
|
|
32
|
+
parseErrorResponse,
|
|
32
33
|
} from './lib/utils';
|
|
33
34
|
|
|
34
35
|
// Validators (Some/all copied from stripes-erm-components but this gives another way to acquire them)
|
|
@@ -125,3 +126,4 @@ export * as customPropertyContants from './lib/constants/customProperties';
|
|
|
125
126
|
|
|
126
127
|
export { default as CycleButton } from './lib/CycleButton';
|
|
127
128
|
export { default as IconSelect } from './lib/IconSelect';
|
|
129
|
+
export { default as RichSelect, useSelectedOption } from './lib/RichSelect';
|
|
@@ -14,10 +14,15 @@ const propTypes = {
|
|
|
14
14
|
contentData: PropTypes.arrayOf(PropTypes.object),
|
|
15
15
|
creatableFields: PropTypes.object,
|
|
16
16
|
createCallback: PropTypes.func,
|
|
17
|
+
defaultNewObject: PropTypes.object,
|
|
17
18
|
editableFields: PropTypes.object,
|
|
18
19
|
fieldComponents: PropTypes.object,
|
|
19
20
|
hideCreateButton: PropTypes.bool,
|
|
20
|
-
label: PropTypes.
|
|
21
|
+
label: PropTypes.oneOfType([
|
|
22
|
+
PropTypes.string,
|
|
23
|
+
PropTypes.node
|
|
24
|
+
]),
|
|
25
|
+
validateFields: PropTypes.object,
|
|
21
26
|
visibleFields: PropTypes.arrayOf(PropTypes.string)
|
|
22
27
|
};
|
|
23
28
|
|
|
@@ -28,6 +33,7 @@ const ActionList = forwardRef(({
|
|
|
28
33
|
contentData,
|
|
29
34
|
creatableFields = {},
|
|
30
35
|
createCallback,
|
|
36
|
+
defaultNewObject = {},
|
|
31
37
|
editableFields = {},
|
|
32
38
|
fieldComponents = {},
|
|
33
39
|
hideCreateButton,
|
|
@@ -58,6 +64,7 @@ const ActionList = forwardRef(({
|
|
|
58
64
|
component={ActionListFieldArrayWithRef}
|
|
59
65
|
creatableFields={creatableFields}
|
|
60
66
|
createCallback={createCallback}
|
|
67
|
+
defaultNewObject={defaultNewObject}
|
|
61
68
|
editableFields={editableFields}
|
|
62
69
|
fieldComponents={fieldComponents}
|
|
63
70
|
hideCreateButton={hideCreateButton}
|
|
@@ -2,6 +2,7 @@ import React, { forwardRef, useImperativeHandle, useState } from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { FormattedMessage } from 'react-intl';
|
|
4
4
|
import get from 'lodash/get';
|
|
5
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
5
6
|
|
|
6
7
|
import { Field, useForm, useFormState } from 'react-final-form';
|
|
7
8
|
import { Button, Headline, IconButton, MultiColumnList, TextField } from '@folio/stripes/components';
|
|
@@ -17,12 +18,18 @@ const propTypes = {
|
|
|
17
18
|
columnMapping: PropTypes.object,
|
|
18
19
|
creatableFields: PropTypes.object,
|
|
19
20
|
createCallback: PropTypes.func,
|
|
21
|
+
defaultNewObject: PropTypes.object,
|
|
20
22
|
editableFields: PropTypes.object,
|
|
21
23
|
fields: PropTypes.object,
|
|
22
24
|
fieldComponents: PropTypes.object,
|
|
23
25
|
formatter: PropTypes.object,
|
|
24
26
|
hideCreateButton: PropTypes.bool,
|
|
25
|
-
label: PropTypes.
|
|
27
|
+
label: PropTypes.oneOfType([
|
|
28
|
+
PropTypes.string,
|
|
29
|
+
PropTypes.node
|
|
30
|
+
]),
|
|
31
|
+
triggerFormSubmit: PropTypes.func.isRequired,
|
|
32
|
+
validateFields: PropTypes.object,
|
|
26
33
|
visibleFields: PropTypes.arrayOf(PropTypes.string)
|
|
27
34
|
};
|
|
28
35
|
|
|
@@ -32,6 +39,7 @@ const ActionListFieldArray = forwardRef(({
|
|
|
32
39
|
columnMapping,
|
|
33
40
|
creatableFields,
|
|
34
41
|
createCallback,
|
|
42
|
+
defaultNewObject,
|
|
35
43
|
editableFields,
|
|
36
44
|
fields,
|
|
37
45
|
fieldComponents,
|
|
@@ -95,7 +103,7 @@ const ActionListFieldArray = forwardRef(({
|
|
|
95
103
|
|
|
96
104
|
const handleClickCreate = () => {
|
|
97
105
|
toggleEditing('NEW_ROW');
|
|
98
|
-
fields.unshift(
|
|
106
|
+
fields.unshift(defaultNewObject);
|
|
99
107
|
};
|
|
100
108
|
|
|
101
109
|
// Way to go into create mode from external component, and way to tell internal editing state
|
|
@@ -135,7 +143,7 @@ const ActionListFieldArray = forwardRef(({
|
|
|
135
143
|
<Button
|
|
136
144
|
key={`save[${data.rowIndex}]`}
|
|
137
145
|
buttonStyle="primary"
|
|
138
|
-
disabled={submitting || pristine}
|
|
146
|
+
disabled={hasValidationErrors || submitting || pristine}
|
|
139
147
|
marginBottom0
|
|
140
148
|
onClick={() => {
|
|
141
149
|
triggerFormSubmit(); // This is set up as () => null in ActionList, so essentially only acts here to force validation
|
|
@@ -237,7 +245,7 @@ const ActionListFieldArray = forwardRef(({
|
|
|
237
245
|
return (
|
|
238
246
|
fields.map((fieldName, fieldIndex) => {
|
|
239
247
|
// Fetch the content from the field Values
|
|
240
|
-
const cd = get(values, fieldName);
|
|
248
|
+
const cd = cloneDeep(get(values, fieldName));
|
|
241
249
|
cd.actionListActions = actionAssigner(cd);
|
|
242
250
|
return { ...cd, fieldName, fieldIndex };
|
|
243
251
|
})
|
|
@@ -280,7 +288,7 @@ const ActionListFieldArray = forwardRef(({
|
|
|
280
288
|
(!!cd.id && editFunction(cd))
|
|
281
289
|
) {
|
|
282
290
|
const validateFunction = validateFields?.[key] ? validateFields?.[key](cd) : null;
|
|
283
|
-
|
|
291
|
+
|
|
284
292
|
returnValue =
|
|
285
293
|
fieldComponents[key] ?
|
|
286
294
|
fieldComponents[key]({
|
|
@@ -97,6 +97,7 @@ columnMapping | object | An object which will act on the rendered MultiColumnLis
|
|
|
97
97
|
contentData | array | An array of objects to render along with their actions | | ✓ |
|
|
98
98
|
creatableFields | object\<function> | An object with keys from the `visibleFields` array, and values of functions which take the entire row object and return a boolean indicating whether that field is fillable on create or not. | | ✕ |
|
|
99
99
|
createCallback | function | A callback to be used for the built in "create" action (ie "save" on a new row). Will be prioritised ahead of a `create` entry in the deprecated actionCalls prop. | {} | ✕ |
|
|
100
|
+
defaultNewObject | object | An object to use when pushing a new entry into the ActionList fields, acting as a way to bootstrap defaults into new items | {} | ✕ |
|
|
100
101
|
editableFields | object\<function> | An object with keys from the `visibleFields` array, and values of functions which take the entire row object and return a boolean indicating whether that field is editable or not. No key for a given field will be interpreted as () => true, so a field is editable by default. | | ✕ |
|
|
101
102
|
fieldComponents | object\<function> | An object with keys from the `visibleFields` array, and values of functions which take some `fieldProps` (currently only the name of the field `name`), and returns a Field component to be used in "edit mode" for the visible field specified. | | ✕ |
|
|
102
103
|
formatter | object\<function> | A "formatter" object that takes the same shape as an MCL formatter, and is used in the same way whilst a row is NOT being edited. While editing a given row, this formatter entry is ignored. | | ✕ |
|
|
@@ -15,6 +15,7 @@ import CustomPropertiesLookup from './CustomPropertiesLookup';
|
|
|
15
15
|
import CustomPropertyView from './CustomPropertyView';
|
|
16
16
|
import CustomPropertiesForm from './CustomPropertyForm';
|
|
17
17
|
import { useMutateCustomProperties, useRefdata } from '../../hooks';
|
|
18
|
+
import { parseErrorResponse } from '../../utils';
|
|
18
19
|
|
|
19
20
|
const EDITING = 'edit';
|
|
20
21
|
const CREATING = 'create';
|
|
@@ -99,7 +100,8 @@ const CustomPropertiesSettings = ({
|
|
|
99
100
|
// Default delete behaviour is to fire a callout, either with kint-components default message
|
|
100
101
|
// or one provided in labelOverrides, which is passed the error message and customProperty in question
|
|
101
102
|
delete: async (err) => {
|
|
102
|
-
const errorResp = await err.response
|
|
103
|
+
const errorResp = await parseErrorResponse(err.response);
|
|
104
|
+
|
|
103
105
|
callout.sendCallout({
|
|
104
106
|
message: labelOverrides?.deleteError ? labelOverrides.deleteError(errorResp?.message, customProperty) : (
|
|
105
107
|
<FormattedMessage
|
|
@@ -51,7 +51,7 @@ const CustomPropertiesViewCtx = ({
|
|
|
51
51
|
{ path: 'retired' }, // Place retired custprops at the end
|
|
52
52
|
{ path: 'primary', direction: 'desc' }, // Primary properties should display before optional
|
|
53
53
|
{ path: 'weight' }, // Within those groups, sort by weight
|
|
54
|
-
{ path: 'label' } //For those with the same weight, sort by label
|
|
54
|
+
{ path: 'label' } // For those with the same weight, sort by label
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
57
|
});
|
|
@@ -26,7 +26,7 @@ const CycleButton = ({
|
|
|
26
26
|
onClick(e);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
setIndex(index !== (buttons?.length -1) ? index + 1 : 0);
|
|
29
|
+
setIndex(index !== (buttons?.length - 1) ? index + 1 : 0);
|
|
30
30
|
}}
|
|
31
31
|
/>
|
|
32
32
|
);
|
|
@@ -37,7 +37,8 @@ CycleButton.propTypes = {
|
|
|
37
37
|
className: PropTypes.object,
|
|
38
38
|
icon: PropTypes.string.isRequired,
|
|
39
39
|
onClick: PropTypes.func.isRequired,
|
|
40
|
-
}))
|
|
40
|
+
})),
|
|
41
|
+
startIndex: PropTypes.number
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
export default CycleButton;
|