@steroidsjs/core 3.0.70 → 3.0.71
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/package.json
CHANGED
|
@@ -53,6 +53,9 @@ var range_1 = __importDefault(require("lodash-es/range"));
|
|
|
53
53
|
var isEmpty_1 = __importDefault(require("lodash-es/isEmpty"));
|
|
54
54
|
var concat_1 = __importDefault(require("lodash-es/concat"));
|
|
55
55
|
var get_1 = __importDefault(require("lodash-es/get"));
|
|
56
|
+
var omit_1 = __importDefault(require("lodash-es/omit"));
|
|
57
|
+
var values_1 = __importDefault(require("lodash-es/values"));
|
|
58
|
+
var zipObject_1 = __importDefault(require("lodash-es/zipObject"));
|
|
56
59
|
var react_use_1 = require("react-use");
|
|
57
60
|
var hooks_1 = require("../../../hooks");
|
|
58
61
|
var Form_1 = require("../../form/Form/Form");
|
|
@@ -66,7 +69,7 @@ function FieldList(props) {
|
|
|
66
69
|
var context = (0, react_1.useContext)(Form_1.FormContext);
|
|
67
70
|
// Resolve model
|
|
68
71
|
var modelAttributes = (_a = components.meta.getModel(props.model)) === null || _a === void 0 ? void 0 : _a.attributes;
|
|
69
|
-
var
|
|
72
|
+
var reduxFormValues = (0, hooks_1.useSelector)(function (state) { return (0, get_1["default"])(state, ['form', context.formId]) || null; });
|
|
70
73
|
var dispatch = context.provider.useDispatch();
|
|
71
74
|
// Mapper for preserving the correct sequence of rows on the UI
|
|
72
75
|
var _b = (0, react_1.useState)((0, range_1["default"])(props.input.value) || []), storeToRowIndexMap = _b[0], setStoreToRowIndexMap = _b[1];
|
|
@@ -86,9 +89,26 @@ function FieldList(props) {
|
|
|
86
89
|
dispatch((0, form_1.formArrayAdd)(context.formId, props.input.name, rowsCount, props.initialValues));
|
|
87
90
|
}, [addRowIndexes, context.formId, dispatch, props.initialValues, props.input.name]);
|
|
88
91
|
var onRemove = (0, react_1.useCallback)(function (rowIndex) {
|
|
92
|
+
var _a;
|
|
89
93
|
removeRowIndex(rowIndex);
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
var actions = [
|
|
95
|
+
(0, form_1.formArrayRemove)(context.formId, props.input.name, rowIndex),
|
|
96
|
+
];
|
|
97
|
+
var listErrors = (0, get_1["default"])(reduxFormValues === null || reduxFormValues === void 0 ? void 0 : reduxFormValues.errors, props.input.name);
|
|
98
|
+
if (!(0, isEmpty_1["default"])(listErrors)) {
|
|
99
|
+
/**
|
|
100
|
+
* После удаления строки, удаляет соответствующую этой строке ошибку
|
|
101
|
+
* и обновляет индексы для последующих элементов
|
|
102
|
+
*/
|
|
103
|
+
var errorsWithoutRemoved = (0, omit_1["default"])(listErrors, String(rowIndex));
|
|
104
|
+
var errorsArray = (0, values_1["default"])(errorsWithoutRemoved);
|
|
105
|
+
var errorsForList = (0, zipObject_1["default"])((0, range_1["default"])(errorsArray.length), errorsArray);
|
|
106
|
+
var newTotalErrors = __assign(__assign({}, reduxFormValues.errors), (_a = {}, _a[props.input.name] = errorsForList, _a));
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
actions.push((0, form_1.formSetErrors)(context.formId, newTotalErrors));
|
|
109
|
+
}
|
|
110
|
+
dispatch(actions);
|
|
111
|
+
}, [context.formId, dispatch, reduxFormValues === null || reduxFormValues === void 0 ? void 0 : reduxFormValues.errors, props.input.name, removeRowIndex]);
|
|
92
112
|
(0, react_use_1.useMount)(function () {
|
|
93
113
|
// Add initial rows
|
|
94
114
|
if (!props.input.value) {
|
|
@@ -140,7 +160,7 @@ function FieldList(props) {
|
|
|
140
160
|
var FieldListView = props.view || components.ui.getView('form.FieldListView');
|
|
141
161
|
var FieldListItemView = props.itemView || components.ui.getView('form.FieldListItemView');
|
|
142
162
|
return (react_1["default"].createElement(Form_1.FormContext.Provider, { value: contextValue },
|
|
143
|
-
react_1["default"].createElement(FieldListView, __assign({}, viewProps), !(0, isEmpty_1["default"])(storeToRowIndexMap) && (0, range_1["default"])(props.input.value || 0).map(function (index) { return (react_1["default"].createElement(FieldListItemView, __assign({}, itemViewProps, { key:
|
|
163
|
+
react_1["default"].createElement(FieldListView, __assign({}, viewProps), !(0, isEmpty_1["default"])(storeToRowIndexMap) && (0, range_1["default"])(props.input.value || 0).map(function (index) { return (react_1["default"].createElement(FieldListItemView, __assign({}, itemViewProps, { key: reduxFormValues ? storeToRowIndexMap[index] : index, prefix: props.input.name + '.' + index, rowIndex: index }))); }))));
|
|
144
164
|
}
|
|
145
165
|
FieldList.defaultProps = {
|
|
146
166
|
initialValues: null,
|