react-hook-core 0.2.7 → 0.2.8
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/lib/core.js +3 -3
- package/lib/useEdit.js +19 -18
- package/lib/useSearch.js +3 -5
- package/package.json +1 -1
- package/src/core.ts +5 -5
- package/src/edit.ts +2 -2
- package/src/useEdit.ts +21 -20
- package/src/useSearch.ts +1 -1
package/lib/core.js
CHANGED
|
@@ -136,7 +136,7 @@ function error(err, gv, ae) {
|
|
|
136
136
|
var title = gv('error');
|
|
137
137
|
var msg = gv('error_internal');
|
|
138
138
|
if (!err) {
|
|
139
|
-
ae(msg, title);
|
|
139
|
+
ae(msg, undefined, title);
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
142
|
var data = err && err.response ? err.response : err;
|
|
@@ -145,10 +145,10 @@ function error(err, gv, ae) {
|
|
|
145
145
|
if (status_1 && !isNaN(status_1)) {
|
|
146
146
|
msg = messageByHttpStatus(status_1, gv);
|
|
147
147
|
}
|
|
148
|
-
ae(msg, title);
|
|
148
|
+
ae(msg, undefined, title);
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
151
|
-
ae(msg, title);
|
|
151
|
+
ae(msg, undefined, title);
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
exports.error = error;
|
package/lib/useEdit.js
CHANGED
|
@@ -134,7 +134,7 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
134
134
|
if (form) {
|
|
135
135
|
formutil_1.setReadOnly(form);
|
|
136
136
|
}
|
|
137
|
-
p1.showError(msg.message,
|
|
137
|
+
p1.showError(msg.message, function () { return window.history.back; }, msg.title);
|
|
138
138
|
};
|
|
139
139
|
var handleNotFound = (p && p.handleNotFound ? p.handleNotFound : _handleNotFound);
|
|
140
140
|
var _getModel = function () {
|
|
@@ -163,9 +163,9 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
163
163
|
}
|
|
164
164
|
else {
|
|
165
165
|
var msg = core_1.message(p1.resource.value, 'msg_confirm_back', 'confirm', 'yes', 'no');
|
|
166
|
-
p1.confirm(msg.message,
|
|
166
|
+
p1.confirm(msg.message, function () {
|
|
167
167
|
navigate(-1);
|
|
168
|
-
}, msg.no, msg.yes);
|
|
168
|
+
}, msg.title, msg.no, msg.yes);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
};
|
|
@@ -196,11 +196,11 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
196
196
|
if (p && p.readOnly) {
|
|
197
197
|
if (flag.newMode === true) {
|
|
198
198
|
var m = core_1.message(p1.resource.value, 'error_permission_add', 'error_permission');
|
|
199
|
-
p1.showError(m.message, m.title);
|
|
199
|
+
p1.showError(m.message, undefined, m.title);
|
|
200
200
|
}
|
|
201
201
|
else {
|
|
202
202
|
var msg = core_1.message(p1.resource.value, 'error_permission_edit', 'error_permission');
|
|
203
|
-
p1.showError(msg.message, msg.title);
|
|
203
|
+
p1.showError(msg.message, undefined, msg.title);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
else {
|
|
@@ -219,9 +219,9 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
219
219
|
if (flag.newMode) {
|
|
220
220
|
validate(obj_1, function () {
|
|
221
221
|
var msg = core_1.message(p1.resource.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
222
|
-
p1.confirm(msg.message,
|
|
222
|
+
p1.confirm(msg.message, function () {
|
|
223
223
|
doSave(obj_1, undefined, version_1, isBack);
|
|
224
|
-
}, msg.no, msg.yes);
|
|
224
|
+
}, msg.title, msg.no, msg.yes);
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
227
|
else {
|
|
@@ -233,9 +233,9 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
233
233
|
else {
|
|
234
234
|
validate(obj_1, function () {
|
|
235
235
|
var msg = core_1.message(p1.resource.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
236
|
-
p1.confirm(msg.message,
|
|
236
|
+
p1.confirm(msg.message, function () {
|
|
237
237
|
doSave(obj_1, diffObj_1, version_1, isBack);
|
|
238
|
-
}, msg.no, msg.yes);
|
|
238
|
+
}, msg.title, msg.no, msg.yes);
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
241
|
}
|
|
@@ -288,20 +288,20 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
288
288
|
var t = p1.resource.value('error');
|
|
289
289
|
if (p1.ui && p1.ui.buildErrorMessage) {
|
|
290
290
|
var msg = p1.ui.buildErrorMessage(unmappedErrors);
|
|
291
|
-
p1.showError(msg, t);
|
|
291
|
+
p1.showError(msg, undefined, t);
|
|
292
292
|
}
|
|
293
293
|
else {
|
|
294
|
-
p1.showError(unmappedErrors[0].field + ' ' + unmappedErrors[0].code + ' ' + unmappedErrors[0].message, t);
|
|
294
|
+
p1.showError(unmappedErrors[0].field + ' ' + unmappedErrors[0].code + ' ' + unmappedErrors[0].message, undefined, t);
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
else {
|
|
299
299
|
var t = p1.resource.value('error');
|
|
300
300
|
if (result.length > 0) {
|
|
301
|
-
p1.showError(result[0].field + ' ' + result[0].code + ' ' + result[0].message, t);
|
|
301
|
+
p1.showError(result[0].field + ' ' + result[0].code + ' ' + result[0].message, undefined, t);
|
|
302
302
|
}
|
|
303
303
|
else {
|
|
304
|
-
p1.showError(t, t);
|
|
304
|
+
p1.showError(t, undefined, t);
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
};
|
|
@@ -310,14 +310,15 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
310
310
|
if (err) {
|
|
311
311
|
setRunning(false);
|
|
312
312
|
core_1.hideLoading(p1.loading);
|
|
313
|
+
var errHeader = p1.resource.value('error');
|
|
313
314
|
var errMsg = p1.resource.value('error_internal');
|
|
314
315
|
var data = (err && err.response) ? err.response : err;
|
|
315
316
|
if (data.status === 400) {
|
|
316
317
|
var errMsg_1 = p1.resource.value('error_400');
|
|
317
|
-
p1.showError(errMsg_1,
|
|
318
|
+
p1.showError(errMsg_1, undefined, errHeader);
|
|
318
319
|
}
|
|
319
320
|
else {
|
|
320
|
-
p1.showError(errMsg,
|
|
321
|
+
p1.showError(errMsg, undefined, errHeader);
|
|
321
322
|
}
|
|
322
323
|
}
|
|
323
324
|
};
|
|
@@ -345,7 +346,7 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
345
346
|
else {
|
|
346
347
|
var title = p1.resource.value('error');
|
|
347
348
|
var err = p1.resource.value('error_version');
|
|
348
|
-
p1.showError(err, title);
|
|
349
|
+
p1.showError(err, undefined, title);
|
|
349
350
|
}
|
|
350
351
|
}
|
|
351
352
|
}
|
|
@@ -369,7 +370,7 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
369
370
|
var postSave = (p && p.postSave ? p.postSave : _postSave);
|
|
370
371
|
var _handleDuplicateKey = function (result) {
|
|
371
372
|
var msg = core_1.message(p1.resource.value, 'error_duplicate_key', 'error');
|
|
372
|
-
p1.showError(msg.message, msg.title);
|
|
373
|
+
p1.showError(msg.message, undefined, msg.title);
|
|
373
374
|
};
|
|
374
375
|
var handleDuplicateKey = (p && p.handleDuplicateKey ? p.handleDuplicateKey : _handleDuplicateKey);
|
|
375
376
|
var _doSave = function (obj, body, version, isBack) {
|
|
@@ -436,7 +437,7 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
436
437
|
if (data && (data.status === 401 || data.status === 403)) {
|
|
437
438
|
formutil_1.setReadOnly(refForm.current);
|
|
438
439
|
}
|
|
439
|
-
p1.showError(msg, title);
|
|
440
|
+
p1.showError(msg, undefined, title);
|
|
440
441
|
}
|
|
441
442
|
}
|
|
442
443
|
setRunning(false);
|
package/lib/useSearch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
4
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
5
|
s = arguments[i];
|
|
6
6
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
@@ -361,8 +361,7 @@ exports.useCoreSearch = function (refForm, initialState, service, p1, p2) {
|
|
|
361
361
|
component.append = false;
|
|
362
362
|
doSearch(component);
|
|
363
363
|
};
|
|
364
|
-
return __assign(__assign({}, baseProps), {
|
|
365
|
-
running: running,
|
|
364
|
+
return __assign(__assign({}, baseProps), { running: running,
|
|
366
365
|
setRunning: setRunning,
|
|
367
366
|
getCurrencyCode: getCurrencyCode, resource: p1.resource.resource(), setComponent: setComponent,
|
|
368
367
|
component: component, showMessage: p1.showMessage, load: load,
|
|
@@ -377,6 +376,5 @@ exports.useCoreSearch = function (refForm, initialState, service, p1, p2) {
|
|
|
377
376
|
clearQ: clearQ,
|
|
378
377
|
showResults: showResults,
|
|
379
378
|
getFields: getFields,
|
|
380
|
-
getModelName: getModelName, format: p ? p.format : undefined, searchError: searchError
|
|
381
|
-
});
|
|
379
|
+
getModelName: getModelName, format: p ? p.format : undefined, searchError: searchError });
|
|
382
380
|
};
|
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface SearchPermission {
|
|
|
29
29
|
export interface SearchParameter {
|
|
30
30
|
resource: ResourceService;
|
|
31
31
|
showMessage: (msg: string, option?: string) => void;
|
|
32
|
-
showError: (m: string,
|
|
32
|
+
showError: (m: string, callback?: () => void, h?: string) => void;
|
|
33
33
|
ui?: UIService;
|
|
34
34
|
getLocale?: (profile?: string) => Locale;
|
|
35
35
|
loading?: LoadingService;
|
|
@@ -395,11 +395,11 @@ export function initForm(form?: HTMLFormElement, initMat?: (f: HTMLFormElement)
|
|
|
395
395
|
}
|
|
396
396
|
return form;
|
|
397
397
|
}
|
|
398
|
-
export function error(err: any, gv: (key: string) => string, ae: (msg: string,
|
|
398
|
+
export function error(err: any, gv: (key: string) => string, ae: (msg: string, callback?: () => void, header?: string) => void) {
|
|
399
399
|
const title = gv('error');
|
|
400
400
|
let msg = gv('error_internal');
|
|
401
401
|
if (!err) {
|
|
402
|
-
ae(msg, title);
|
|
402
|
+
ae(msg, undefined, title);
|
|
403
403
|
return;
|
|
404
404
|
}
|
|
405
405
|
const data = err && err.response ? err.response : err;
|
|
@@ -408,9 +408,9 @@ export function error(err: any, gv: (key: string) => string, ae: (msg: string, h
|
|
|
408
408
|
if (status && !isNaN(status)) {
|
|
409
409
|
msg = messageByHttpStatus(status, gv);
|
|
410
410
|
}
|
|
411
|
-
ae(msg, title);
|
|
411
|
+
ae(msg, undefined, title);
|
|
412
412
|
} else {
|
|
413
|
-
ae(msg, title);
|
|
413
|
+
ae(msg, undefined, title);
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
export function getName(d: string, n?: string): string {
|
package/src/edit.ts
CHANGED
|
@@ -9,8 +9,8 @@ export interface ResultInfo<T> {
|
|
|
9
9
|
export interface EditParameter {
|
|
10
10
|
resource: ResourceService;
|
|
11
11
|
showMessage: (msg: string, option?: string) => void;
|
|
12
|
-
showError: (m: string,
|
|
13
|
-
confirm: (m2: string,
|
|
12
|
+
showError: (m: string, callback?: () => void, header?: string) => void;
|
|
13
|
+
confirm: (m2: string, yesCallback?: () => void, header?: string, btnLeftText?: string, btnRightText?: string, noCallback?: () => void) => void;
|
|
14
14
|
ui?: UIService;
|
|
15
15
|
getLocale?: (profile?: string) => Locale;
|
|
16
16
|
loading?: LoadingService;
|
package/src/useEdit.ts
CHANGED
|
@@ -47,9 +47,9 @@ export interface HookBaseEditParameter<T, ID, S> extends BaseEditComponentParam<
|
|
|
47
47
|
service: GenericService<T, ID, number|T|ErrorMessage[]>;
|
|
48
48
|
resource: ResourceService;
|
|
49
49
|
showMessage: (msg: string) => void;
|
|
50
|
-
showError: (m: string,
|
|
50
|
+
showError: (m: string, callback?: () => void, header?: string) => void;
|
|
51
51
|
getLocale?: () => Locale;
|
|
52
|
-
confirm: (m2: string,
|
|
52
|
+
confirm: (m2: string, yesCallback?: () => void, header?: string, btnLeftText?: string, btnRightText?: string, noCallback?: () => void) => void;
|
|
53
53
|
ui?: UIService;
|
|
54
54
|
loading?: LoadingService;
|
|
55
55
|
}
|
|
@@ -213,7 +213,7 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
213
213
|
if (form) {
|
|
214
214
|
setReadOnly(form);
|
|
215
215
|
}
|
|
216
|
-
p1.showError(msg.message,
|
|
216
|
+
p1.showError(msg.message, () => window.history.back, msg.title);
|
|
217
217
|
};
|
|
218
218
|
const handleNotFound = (p && p.handleNotFound ? p.handleNotFound : _handleNotFound);
|
|
219
219
|
|
|
@@ -241,9 +241,9 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
241
241
|
navigate(-1);
|
|
242
242
|
} else {
|
|
243
243
|
const msg = message(p1.resource.value, 'msg_confirm_back', 'confirm', 'yes', 'no');
|
|
244
|
-
p1.confirm(msg.message,
|
|
244
|
+
p1.confirm(msg.message, () => {
|
|
245
245
|
navigate(-1);
|
|
246
|
-
}, msg.no, msg.yes);
|
|
246
|
+
}, msg.title, msg.no, msg.yes);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
};
|
|
@@ -275,10 +275,10 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
275
275
|
if (p && p.readOnly) {
|
|
276
276
|
if (flag.newMode === true) {
|
|
277
277
|
const m = message(p1.resource.value, 'error_permission_add', 'error_permission');
|
|
278
|
-
p1.showError(m.message, m.title);
|
|
278
|
+
p1.showError(m.message, undefined, m.title);
|
|
279
279
|
} else {
|
|
280
280
|
const msg = message(p1.resource.value, 'error_permission_edit', 'error_permission');
|
|
281
|
-
p1.showError(msg.message, msg.title);
|
|
281
|
+
p1.showError(msg.message, undefined, msg.title);
|
|
282
282
|
}
|
|
283
283
|
} else {
|
|
284
284
|
if (running === true) {
|
|
@@ -296,9 +296,9 @@ if (running === true) {
|
|
|
296
296
|
if (flag.newMode) {
|
|
297
297
|
validate(obj, () => {
|
|
298
298
|
const msg = message(p1.resource.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
299
|
-
p1.confirm(msg.message,
|
|
299
|
+
p1.confirm(msg.message, () => {
|
|
300
300
|
doSave(obj, undefined, version, isBack);
|
|
301
|
-
}, msg.no, msg.yes);
|
|
301
|
+
}, msg.title, msg.no, msg.yes);
|
|
302
302
|
});
|
|
303
303
|
} else {
|
|
304
304
|
const diffObj = makeDiff(flag.originalModel, obj, keys, version);
|
|
@@ -308,9 +308,9 @@ if (running === true) {
|
|
|
308
308
|
} else {
|
|
309
309
|
validate(obj, () => {
|
|
310
310
|
const msg = message(p1.resource.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
311
|
-
p1.confirm(msg.message,
|
|
311
|
+
p1.confirm(msg.message, () => {
|
|
312
312
|
doSave(obj, diffObj as any, version, isBack);
|
|
313
|
-
}, msg.no, msg.yes);
|
|
313
|
+
}, msg.title, msg.no, msg.yes);
|
|
314
314
|
});
|
|
315
315
|
}
|
|
316
316
|
}
|
|
@@ -364,17 +364,17 @@ if (running === true) {
|
|
|
364
364
|
const t = p1.resource.value('error');
|
|
365
365
|
if (p1.ui && p1.ui.buildErrorMessage) {
|
|
366
366
|
const msg = p1.ui.buildErrorMessage(unmappedErrors);
|
|
367
|
-
p1.showError(msg, t);
|
|
367
|
+
p1.showError(msg, undefined, t);
|
|
368
368
|
} else {
|
|
369
|
-
p1.showError(unmappedErrors[0].field + ' ' + unmappedErrors[0].code + ' ' + unmappedErrors[0].message, t);
|
|
369
|
+
p1.showError(unmappedErrors[0].field + ' ' + unmappedErrors[0].code + ' ' + unmappedErrors[0].message, undefined, t);
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
} else {
|
|
373
373
|
const t = p1.resource.value('error');
|
|
374
374
|
if (result.length > 0) {
|
|
375
|
-
p1.showError(result[0].field + ' ' + result[0].code + ' ' + result[0].message, t);
|
|
375
|
+
p1.showError(result[0].field + ' ' + result[0].code + ' ' + result[0].message, undefined, t);
|
|
376
376
|
} else {
|
|
377
|
-
p1.showError(t, t);
|
|
377
|
+
p1.showError(t, undefined, t);
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
};
|
|
@@ -384,13 +384,14 @@ if (running === true) {
|
|
|
384
384
|
if (err) {
|
|
385
385
|
setRunning(false);
|
|
386
386
|
hideLoading(p1.loading);
|
|
387
|
+
const errHeader = p1.resource.value('error');
|
|
387
388
|
const errMsg = p1.resource.value('error_internal');
|
|
388
389
|
const data = (err && err.response) ? err.response : err;
|
|
389
390
|
if (data.status === 400) {
|
|
390
391
|
const errMsg = p1.resource.value('error_400');
|
|
391
|
-
p1.showError(errMsg,
|
|
392
|
+
p1.showError(errMsg, undefined, errHeader);
|
|
392
393
|
} else{
|
|
393
|
-
p1.showError(errMsg,
|
|
394
|
+
p1.showError(errMsg, undefined, errHeader);
|
|
394
395
|
}
|
|
395
396
|
}
|
|
396
397
|
};
|
|
@@ -416,7 +417,7 @@ if (running === true) {
|
|
|
416
417
|
} else {
|
|
417
418
|
const title = p1.resource.value('error');
|
|
418
419
|
const err = p1.resource.value('error_version');
|
|
419
|
-
p1.showError(err, title);
|
|
420
|
+
p1.showError(err, undefined, title);
|
|
420
421
|
}
|
|
421
422
|
}
|
|
422
423
|
} else {
|
|
@@ -438,7 +439,7 @@ if (running === true) {
|
|
|
438
439
|
|
|
439
440
|
const _handleDuplicateKey = (result?: T) => {
|
|
440
441
|
const msg = message(p1.resource.value, 'error_duplicate_key', 'error');
|
|
441
|
-
p1.showError(msg.message, msg.title);
|
|
442
|
+
p1.showError(msg.message, undefined, msg.title);
|
|
442
443
|
};
|
|
443
444
|
const handleDuplicateKey = (p && p.handleDuplicateKey ? p.handleDuplicateKey : _handleDuplicateKey);
|
|
444
445
|
|
|
@@ -501,7 +502,7 @@ if (running === true) {
|
|
|
501
502
|
if (data && (data.status === 401 || data.status === 403)) {
|
|
502
503
|
setReadOnly(refForm.current);
|
|
503
504
|
}
|
|
504
|
-
p1.showError(msg, title);
|
|
505
|
+
p1.showError(msg, undefined, title);
|
|
505
506
|
}
|
|
506
507
|
}
|
|
507
508
|
setRunning(false);
|
package/src/useSearch.ts
CHANGED
|
@@ -107,7 +107,7 @@ export interface HookBaseSearchParameter<T, S extends Filter, ST extends SearchC
|
|
|
107
107
|
service: ((s: S, limit?: number, offset?: number|string, fields?: string[]) => Promise<SearchResult<T>>) | SearchService<T, S>;
|
|
108
108
|
resource: ResourceService;
|
|
109
109
|
showMessage: (msg: string) => void;
|
|
110
|
-
showError: (m: string,
|
|
110
|
+
showError: (m: string, callback?: () => void, header?: string) => void;
|
|
111
111
|
getLocale?: () => Locale;
|
|
112
112
|
autoSearch?: boolean;
|
|
113
113
|
}
|