@steroidsjs/core 2.2.11 → 2.2.14

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.
@@ -84,6 +84,11 @@ export interface IListConfig {
84
84
  * @example true
85
85
  */
86
86
  autoDestroy?: boolean;
87
+ /**
88
+ * Отправлять запрос на обновление данных при изменении данных формы. По-умолчанию - включено.
89
+ * @example false
90
+ */
91
+ autoFetchOnFormChanges?: boolean;
87
92
  /**
88
93
  * Обработчик, который вызывается при изменении значений формы, и нужен для подгрузки новых элементов коллекции
89
94
  * @param {IList} list
package/hooks/useList.js CHANGED
@@ -226,10 +226,12 @@ function useList(config) {
226
226
  // Sync with address bar
227
227
  updateQuery(formValues);
228
228
  // Send request
229
- dispatch(list_2.listLazyFetch(config.listId));
229
+ if (config.autoFetchOnFormChanges !== false) {
230
+ dispatch(list_2.listLazyFetch(config.listId));
231
+ }
230
232
  }
231
- }, [config.listId, dispatch, formId, formValues, paginationProps.attribute,
232
- paginationProps.defaultValue, prevFormValues, updateQuery]);
233
+ }, [config.autoFetchOnFormChanges, config.listId, dispatch, formId, formValues,
234
+ paginationProps.attribute, paginationProps.defaultValue, prevFormValues, updateQuery]);
233
235
  // Check change query
234
236
  var prevQuery = react_use_1.usePrevious(config.query);
235
237
  react_use_1.useUpdateEffect(function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "2.2.11",
3
+ "version": "2.2.14",
4
4
  "description": "",
5
5
  "author": "Vladimir Kozhin <hello@kozhindev.com>",
6
6
  "repository": {
package/reducers/form.js CHANGED
@@ -50,7 +50,7 @@ function reducerItem(state, action) {
50
50
  case form_1.FORM_SUBMIT:
51
51
  return dot_prop_immutable_1.set(state, 'submitCounter', (state.submitCounter || 0) + 1);
52
52
  case form_1.FORM_RESET:
53
- return dot_prop_immutable_1.set(state, 'values', cloneDeep_1["default"](state.initialValues || {}));
53
+ return __assign(__assign({}, state), { values: cloneDeep_1["default"](state.initialValues || {}) });
54
54
  case form_1.FORM_ARRAY_ADD:
55
55
  // eslint-disable-next-line no-case-declarations
56
56
  var newValue = [].concat(get_1["default"](state, 'values.' + action.name) || []);
@@ -69,8 +69,8 @@ var buildUrl = function (path, params) {
69
69
  var pathKeys = [];
70
70
  try {
71
71
  pathKeys = path_to_regexp_1.parse(path)
72
- .slice(1)
73
- .map(function (p) { return p.name; });
72
+ .map(function (p) { return typeof p === 'object' && p.name; })
73
+ .filter(Boolean);
74
74
  url = path_to_regexp_1.compile(path)(__assign({}, params));
75
75
  }
76
76
  catch (e) {
@@ -90,7 +90,7 @@ export interface IButtonProps {
90
90
  * автоматически будет переключаться в режим загрузки (`loading`) на время выполнения `Promise`.
91
91
  * @param e => fetch(...)
92
92
  */
93
- onClick?: (e: Event | React.MouseEvent) => Promise<any> | void;
93
+ onClick?: (e: Event | React.MouseEvent) => Promise<any> | any;
94
94
  /**
95
95
  * Переводит кнопку в состояние "не активна"
96
96
  * @example true
@@ -15,6 +15,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  };
16
16
  exports.__esModule = true;
17
17
  var react_1 = require("react");
18
+ var react_use_1 = require("react-use");
18
19
  var hooks_1 = require("../../../hooks");
19
20
  var fieldWrapper_1 = __importDefault(require("../../../ui/form/Field/fieldWrapper"));
20
21
  function CheckboxListField(props) {
@@ -42,6 +43,17 @@ function CheckboxListField(props) {
42
43
  react_1.useEffect(function () {
43
44
  props.input.onChange.call(null, selectedIds);
44
45
  }, [props.input.onChange, selectedIds]);
46
+ var onReset = react_1.useCallback(function () {
47
+ setSelectedIds([]);
48
+ }, [setSelectedIds]);
49
+ // Reset selected ids on form reset
50
+ var prevInputValue = react_use_1.usePrevious(props.input.value);
51
+ react_use_1.useUpdateEffect(function () {
52
+ // if form reset
53
+ if (prevInputValue && props.input.value === undefined && selectedIds.length > 0) {
54
+ onReset();
55
+ }
56
+ }, [onReset, prevInputValue, props.input.value, selectedIds.length]);
45
57
  return components.ui.renderView(props.view || 'form.CheckboxListFieldView', __assign(__assign({}, props), { items: items,
46
58
  inputProps: inputProps,
47
59
  onItemSelect: onItemSelect,
@@ -21,9 +21,9 @@ function NumberField(props) {
21
21
  var components = hooks_1.useComponents();
22
22
  props.inputProps = react_1.useMemo(function () {
23
23
  var _a;
24
- return (__assign({ name: props.input.name, value: (_a = props.input.value) !== null && _a !== void 0 ? _a : undefined, onChange: function (e) { var _a, _b; return props.input.onChange(((_a = e.target) === null || _a === void 0 ? void 0 : _a.value) || ((_b = e.nativeEvent) === null || _b === void 0 ? void 0 : _b.text)); }, type: 'number', min: props.min, max: props.max, step: props.step, placeholder: props.placeholder, disabled: props.disabled }, props.inputProps));
24
+ return (__assign({ name: props.input.name, value: (_a = props.input.value) !== null && _a !== void 0 ? _a : '', onChange: function (e) { var _a, _b; return props.input.onChange(((_a = e.target) === null || _a === void 0 ? void 0 : _a.value) || ((_b = e.nativeEvent) === null || _b === void 0 ? void 0 : _b.text)); }, type: 'number', min: props.min, max: props.max, step: props.step, placeholder: props.placeholder, disabled: props.disabled }, props.inputProps));
25
25
  }, [props.disabled, props.input, props.inputProps, props.placeholder, props.min, props.max, props.step]);
26
- return components.ui.renderView(props.view || 'form.NumberFieldView' || 'form.InputFieldView', props);
26
+ return components.ui.renderView(props.view || 'form.NumberFieldView', props);
27
27
  }
28
28
  NumberField.defaultProps = {
29
29
  disabled: false,
@@ -64,7 +64,8 @@ function Grid(props) {
64
64
  searchModel: props.searchModel,
65
65
  items: props.items,
66
66
  initialItems: props.initialItems,
67
- initialTotal: props.initialTotal
67
+ initialTotal: props.initialTotal,
68
+ autoFetchOnFormChanges: props.autoFetchOnFormChanges
68
69
  }), list = _a.list, model = _a.model, searchModel = _a.searchModel, paginationPosition = _a.paginationPosition, paginationSizePosition = _a.paginationSizePosition, layoutNamesPosition = _a.layoutNamesPosition, renderList = _a.renderList, renderEmpty = _a.renderEmpty, renderPagination = _a.renderPagination, renderPaginationSize = _a.renderPaginationSize, renderLayoutNames = _a.renderLayoutNames, renderSearchForm = _a.renderSearchForm, onFetch = _a.onFetch, onSort = _a.onSort;
69
70
  var renderLabel = react_1.useCallback(function (column) {
70
71
  if (column.headerView) {
@@ -59,7 +59,8 @@ function List(props) {
59
59
  searchModel: props.searchModel,
60
60
  items: props.items,
61
61
  initialItems: props.initialItems,
62
- initialTotal: props.initialTotal
62
+ initialTotal: props.initialTotal,
63
+ autoFetchOnFormChanges: props.autoFetchOnFormChanges
63
64
  }), list = _a.list, paginationPosition = _a.paginationPosition, paginationSizePosition = _a.paginationSizePosition, layoutNamesPosition = _a.layoutNamesPosition, renderList = _a.renderList, renderEmpty = _a.renderEmpty, renderPagination = _a.renderPagination, renderPaginationSize = _a.renderPaginationSize, renderLayoutNames = _a.renderLayoutNames, renderSearchForm = _a.renderSearchForm;
64
65
  var ItemView = props.itemView || components.ui.getView('list.ListItemView');
65
66
  var content = ((list === null || list === void 0 ? void 0 : list.items) || []).map(function (item, index) { return (React.createElement(ItemView, __assign({}, props.itemProps, { key: item[props.primaryKey] || index, primaryKey: props.primaryKey, item: item, index: index, layoutSelected: list.layoutName }))); });