@steroidsjs/core 3.0.70 → 3.0.72

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.
@@ -34713,6 +34713,15 @@
34713
34713
  "type": "React.ReactNode | {}",
34714
34714
  "example": "MyCustomView",
34715
34715
  "defaultValue": null
34716
+ },
34717
+ {
34718
+ "name": "viewProps",
34719
+ "decorators": [],
34720
+ "description": "Пропсы для отображения элемента",
34721
+ "required": false,
34722
+ "type": "any",
34723
+ "example": null,
34724
+ "defaultValue": null
34716
34725
  }
34717
34726
  ],
34718
34727
  "methods": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "3.0.70",
3
+ "version": "3.0.72",
4
4
  "description": "",
5
5
  "author": "Vladimir Kozhin <hello@kozhindev.com>",
6
6
  "repository": {
@@ -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 isWithReduxForm = (0, hooks_1.useSelector)(function (state) { return (0, get_1["default"])(state, ['form', context.formId]) || null; });
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
- dispatch((0, form_1.formArrayRemove)(context.formId, props.input.name, rowIndex));
91
- }, [context.formId, dispatch, props.input.name, removeRowIndex]);
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: isWithReduxForm ? storeToRowIndexMap[index] : index, prefix: props.input.name + '.' + index, rowIndex: index }))); }))));
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,
@@ -138,6 +138,10 @@ export interface IGridProps extends IListConfig {
138
138
  * @example MyCustomView
139
139
  */
140
140
  view?: CustomView;
141
+ /**
142
+ * Пропсы для отображения элемента
143
+ */
144
+ viewProps?: CustomViewProps;
141
145
  /**
142
146
  * Коллекция с наименованиями и свойствами колонок в таблице
143
147
  * @example
@@ -119,36 +119,10 @@ function Grid(props) {
119
119
  .map(function (column) { return ((0, isString_1["default"])(column) ? { attribute: column } : column); })
120
120
  .filter(function (column) { return column.visible !== false; })
121
121
  .map(function (column) { return (__assign(__assign({}, column), { label: renderLabel(column) })); }); }, [props.columns, props.controls, props.itemsIndexing, renderLabel]);
122
- var viewProps = (0, react_1.useMemo)(function () { return ({
123
- list: list,
124
- paginationPosition: paginationPosition,
125
- paginationSizePosition: paginationSizePosition,
126
- layoutNamesPosition: layoutNamesPosition,
127
- renderList: renderList,
128
- renderLoading: renderLoading,
129
- renderEmpty: renderEmpty,
130
- renderPagination: renderPagination,
131
- renderPaginationSize: renderPaginationSize,
132
- renderLayoutNames: renderLayoutNames,
133
- renderSearchForm: renderSearchForm,
134
- renderInfiniteScroll: renderInfiniteScroll,
135
- renderValue: renderValue,
136
- columns: columns,
137
- onFetch: onFetch,
138
- onSort: onSort,
139
- sort: sort,
140
- items: (list === null || list === void 0 ? void 0 : list.items) || [],
141
- searchForm: props.searchForm,
142
- listId: props.listId,
143
- isLoading: props.isLoading,
144
- size: props.size,
145
- hasAlternatingColors: props.hasAlternatingColors,
146
- className: props.className,
147
- primaryKey: props.primaryKey
148
- }); }, [list, paginationPosition, paginationSizePosition, layoutNamesPosition, renderList, renderLoading, renderEmpty,
149
- renderPagination, renderPaginationSize, renderLayoutNames, renderSearchForm, renderInfiniteScroll, renderValue, columns,
150
- onFetch, onSort, sort, props.searchForm, props.listId, props.isLoading, props.size, props.hasAlternatingColors, props.className,
151
- props.primaryKey]);
122
+ var viewProps = (0, react_1.useMemo)(function () { return (__assign(__assign({}, props.viewProps), { list: list, paginationPosition: paginationPosition, paginationSizePosition: paginationSizePosition, layoutNamesPosition: layoutNamesPosition, renderList: renderList, renderLoading: renderLoading, renderEmpty: renderEmpty, renderPagination: renderPagination, renderPaginationSize: renderPaginationSize, renderLayoutNames: renderLayoutNames, renderSearchForm: renderSearchForm, renderInfiniteScroll: renderInfiniteScroll, renderValue: renderValue, columns: columns, onFetch: onFetch, onSort: onSort, sort: sort, items: (list === null || list === void 0 ? void 0 : list.items) || [], searchForm: props.searchForm, listId: props.listId, isLoading: props.isLoading, size: props.size, hasAlternatingColors: props.hasAlternatingColors, className: props.className, primaryKey: props.primaryKey })); }, [list, paginationPosition, paginationSizePosition, layoutNamesPosition, renderList, renderLoading, renderEmpty,
123
+ renderPagination, renderPaginationSize, renderLayoutNames, renderSearchForm, renderInfiniteScroll, renderValue,
124
+ columns, onFetch, onSort, sort, props.searchForm, props.listId, props.isLoading, props.size, props.hasAlternatingColors,
125
+ props.className, props.primaryKey, props.viewProps]);
152
126
  return components.ui.renderView(props.view || 'list.GridView', viewProps);
153
127
  }
154
128
  exports["default"] = Grid;