@steroidsjs/core 2.2.69 → 2.2.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.
@@ -117,21 +117,22 @@ function useDataProvider(config) {
117
117
  react_1.useEffect(function () {
118
118
  var fetchRemote = function (isAuto) { return __awaiter(_this, void 0, void 0, function () {
119
119
  var searchHandler, result, newItems;
120
- return __generator(this, function (_a) {
121
- switch (_a.label) {
120
+ var _a;
121
+ return __generator(this, function (_b) {
122
+ switch (_b.label) {
122
123
  case 0:
123
124
  searchHandler = dataProvider.onSearch || (typeof dataProvider.action === 'function'
124
125
  ? function (method, params) { return method(components.api, params).then(function (response) { return response.data; }); }
125
126
  : function (method, params) { return components.http.send(dataProvider.actionMethod, method, params)
126
127
  .then(function (response) { return response.data; }); });
127
- result = searchHandler(dataProvider.action, __assign(__assign({ query: config.query }, (isAuto ? { ids: config.initialSelectedIds } : null)), config.dataProvider.params));
128
+ result = searchHandler(dataProvider.action, __assign(__assign(__assign({ query: config.query }, (isAuto ? { ids: config.initialSelectedIds } : null)), (((_a = config.initialSelectedIds) === null || _a === void 0 ? void 0 : _a.length) > 0 ? { withIds: config.initialSelectedIds } : null)), config.dataProvider.params));
128
129
  if (!(result && isFunction_1["default"](result.then))) return [3 /*break*/, 2];
129
130
  setIsLoading(true);
130
131
  return [4 /*yield*/, result];
131
132
  case 1:
132
- newItems = _a.sent();
133
+ newItems = _b.sent();
133
134
  setIsLoading(false);
134
- _a.label = 2;
135
+ _b.label = 2;
135
136
  case 2:
136
137
  // Update items
137
138
  newItems = data_1.normalizeItems(newItems);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "2.2.69",
3
+ "version": "2.2.72",
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
  }); }