@steroidsjs/core 2.2.70 → 2.2.73

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "2.2.70",
3
+ "version": "2.2.73",
4
4
  "description": "",
5
5
  "author": "Vladimir Kozhin <hello@kozhindev.com>",
6
6
  "repository": {
@@ -96,7 +96,9 @@ exports.buildUrl = buildUrl;
96
96
  var checkIsActive = function (state, item) {
97
97
  // Check is active
98
98
  var pathname = !process.env.IS_SSR && window.location.protocol === 'file:'
99
- ? window.location.hash.replace(/^#/, '')
99
+ ? window.location.hash
100
+ .replace(/^#/, '')
101
+ .replace(/\?.*$/, '')
100
102
  : get_1["default"](state, 'location.pathname');
101
103
  var checkActive = function (subPathname, subItem) {
102
104
  var match = react_router_1.matchPath(subPathname, pick_1["default"](subItem, ['exact', 'strict', 'path']));
@@ -34,6 +34,7 @@ export interface ICrudClickProps {
34
34
  record?: Record<string, unknown>;
35
35
  components: IComponents;
36
36
  goToAction: (nextAction: string) => any;
37
+ errorHandler?: (error: any, dispatch: any) => void;
37
38
  }
38
39
  export interface ICrudProps {
39
40
  crudId?: string;
@@ -56,6 +57,7 @@ export interface ICrudProps {
56
57
  form?: IFormProps | React.ReactNode;
57
58
  detail?: any;
58
59
  crudView?: CustomView;
60
+ errorHandler?: (error: any, dispatch: any) => void;
59
61
  [key: string]: any;
60
62
  }
61
63
  export interface ICrudChildrenProps extends ICrudProps, IConnectHocOutput, IComponentsHocOutput {
@@ -112,7 +112,8 @@ function Crud(props) {
112
112
  recordId: recordId,
113
113
  record: record,
114
114
  components: components,
115
- goToAction: goToAction
115
+ goToAction: goToAction,
116
+ errorHandler: props.errorHandler
116
117
  }); }, [components, goToAction, props.crudId, props.mode, props.primaryKey, props.queryKey,
117
118
  props.restApi, props.restUrl, record, recordId, routeAction, routeId, routeParams]);
118
119
  // Handler for convert control item to props for button
@@ -101,16 +101,23 @@ var normalizeItems = function (sourceItems, fromProps) {
101
101
  return [4 /*yield*/, props.restApi["delete"](props.components.api, (_a = {}, _a[props.primaryKey] = props.recordId, _a))];
102
102
  case 1:
103
103
  _b.sent();
104
- return [3 /*break*/, 4];
104
+ props.goToAction(exports.CRUD_ACTION_INDEX);
105
+ return [2 /*return*/];
105
106
  case 2:
106
107
  if (!props.restUrl) return [3 /*break*/, 4];
107
- return [4 /*yield*/, props.components.http["delete"](props.restUrl + "/" + props.recordId)];
108
+ return [4 /*yield*/, props.components.http["delete"](props.restUrl + "/" + props.recordId)
109
+ .then(function () { return props.goToAction(exports.CRUD_ACTION_INDEX); })["catch"](function (error) {
110
+ if (props.errorHandler) {
111
+ props.errorHandler(error, props.components.store.dispatch);
112
+ }
113
+ else {
114
+ throw error;
115
+ }
116
+ })];
108
117
  case 3:
109
118
  _b.sent();
110
- _b.label = 4;
111
- case 4:
112
- props.goToAction(exports.CRUD_ACTION_INDEX);
113
119
  return [2 /*return*/];
120
+ case 4: throw new Error('Either restApi or restUrl must be set');
114
121
  }
115
122
  });
116
123
  }); }
@@ -17,15 +17,18 @@ exports.__esModule = true;
17
17
  var react_1 = require("react");
18
18
  var hooks_1 = require("../../../hooks");
19
19
  var fieldWrapper_1 = __importDefault(require("../../form/Field/fieldWrapper"));
20
+ var react_use_1 = require("react-use");
21
+ var isEqual_1 = __importDefault(require("lodash-es/isEqual"));
20
22
  function RadioListField(props) {
21
23
  var components = hooks_1.useComponents();
24
+ var inputSelectedIds = react_1.useMemo(function () { return props.selectedIds || [].concat(props.input.value || []); }, [props.input.value, props.selectedIds]);
22
25
  // Data provider
23
26
  var items = hooks_1.useDataProvider({
24
27
  items: props.items
25
28
  }).items;
26
29
  // Data select
27
30
  var _a = hooks_1.useDataSelect({
28
- selectedIds: props.selectedIds,
31
+ selectedIds: inputSelectedIds,
29
32
  selectFirst: props.selectFirst,
30
33
  primaryKey: props.primaryKey,
31
34
  items: items,
@@ -36,10 +39,14 @@ function RadioListField(props) {
36
39
  }, [setSelectedIds]);
37
40
  var inputProps = react_1.useMemo(function () { return (__assign(__assign({}, props.inputProps), { type: 'radio', name: props.input.name, disabled: props.disabled, onChange: function (value) { return props.input.onChange(value); } })); }, [props.disabled, props.input, props.inputProps]);
38
41
  // Sync with form
42
+ var prevSelectedIds = react_use_1.usePrevious(selectedIds);
39
43
  react_1.useEffect(function () {
40
- var _a;
41
- props.input.onChange.call(null, selectedIds[0]);
42
- (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(null, selectedIds[0]);
44
+ if (!isEqual_1["default"](prevSelectedIds || [], selectedIds)) {
45
+ props.input.onChange.call(null, selectedIds[0]);
46
+ if (props.onChange) {
47
+ props.onChange.call(null, selectedIds[0]);
48
+ }
49
+ }
43
50
  }, [props.input.onChange, selectedIds]);
44
51
  return components.ui.renderView(props.view || 'form.RadioListFieldView', __assign(__assign({}, props), { items: items,
45
52
  inputProps: inputProps,