react-hook-core 0.4.14 → 0.4.15
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/common.js +3 -3
- package/lib/useEdit.js +18 -14
- package/package.json +1 -1
- package/src/common.ts +4 -4
- package/src/useEdit.ts +14 -14
- package/src/useSearch.ts +2 -2
package/lib/common.js
CHANGED
|
@@ -13,7 +13,7 @@ function error(err, resource, ae) {
|
|
|
13
13
|
var title = resource.error
|
|
14
14
|
var msg = resource.error_internal
|
|
15
15
|
if (!err) {
|
|
16
|
-
ae(msg, title)
|
|
16
|
+
ae(msg, undefined, title)
|
|
17
17
|
return
|
|
18
18
|
}
|
|
19
19
|
var data = err && err.response ? err.response : err
|
|
@@ -22,9 +22,9 @@ function error(err, resource, ae) {
|
|
|
22
22
|
if (status_1 && !isNaN(status_1)) {
|
|
23
23
|
msg = messageByHttpStatus(status_1, resource)
|
|
24
24
|
}
|
|
25
|
-
ae(msg, title)
|
|
25
|
+
ae(msg, undefined, title)
|
|
26
26
|
} else {
|
|
27
|
-
ae(msg, title)
|
|
27
|
+
ae(msg, undefined, title)
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.error = error
|
package/lib/useEdit.js
CHANGED
|
@@ -229,9 +229,13 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
229
229
|
formutil_1.setReadOnly(form)
|
|
230
230
|
}
|
|
231
231
|
var resource = p1.resource.resource()
|
|
232
|
-
p1.showError(
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
p1.showError(
|
|
233
|
+
resource.error_404,
|
|
234
|
+
function () {
|
|
235
|
+
return window.history.back
|
|
236
|
+
},
|
|
237
|
+
resource.error,
|
|
238
|
+
)
|
|
235
239
|
}
|
|
236
240
|
var handleNotFound = p && p.handleNotFound ? p.handleNotFound : _handleNotFound
|
|
237
241
|
var _getModel = function () {
|
|
@@ -295,9 +299,9 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
295
299
|
var resource = p1.resource.resource()
|
|
296
300
|
if (p && p.readOnly) {
|
|
297
301
|
if (flag.newMode === true) {
|
|
298
|
-
p1.showError(resource.error_permission_add, resource.error_permission)
|
|
302
|
+
p1.showError(resource.error_permission_add, undefined, resource.error_permission)
|
|
299
303
|
} else {
|
|
300
|
-
p1.showError(resource.error_permission_edit, resource.error_permission)
|
|
304
|
+
p1.showError(resource.error_permission_edit, undefined, resource.error_permission)
|
|
301
305
|
}
|
|
302
306
|
} else {
|
|
303
307
|
if (running === true) {
|
|
@@ -390,17 +394,17 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
390
394
|
var t = resource.error
|
|
391
395
|
if (p1.ui && p1.ui.buildErrorMessage) {
|
|
392
396
|
var msg = p1.ui.buildErrorMessage(unmappedErrors)
|
|
393
|
-
p1.showError(msg, t)
|
|
397
|
+
p1.showError(msg, undefined, t)
|
|
394
398
|
} else {
|
|
395
|
-
p1.showError(unmappedErrors[0].field + " " + unmappedErrors[0].code + " " + unmappedErrors[0].message, t)
|
|
399
|
+
p1.showError(unmappedErrors[0].field + " " + unmappedErrors[0].code + " " + unmappedErrors[0].message, undefined, t)
|
|
396
400
|
}
|
|
397
401
|
}
|
|
398
402
|
} else {
|
|
399
403
|
var t = resource.error
|
|
400
404
|
if (result.length > 0) {
|
|
401
|
-
p1.showError(result[0].field + " " + result[0].code + " " + result[0].message, t)
|
|
405
|
+
p1.showError(result[0].field + " " + result[0].code + " " + result[0].message, undefined, t)
|
|
402
406
|
} else {
|
|
403
|
-
p1.showError(t, t)
|
|
407
|
+
p1.showError(t, undefined, t)
|
|
404
408
|
}
|
|
405
409
|
}
|
|
406
410
|
}
|
|
@@ -415,9 +419,9 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
415
419
|
var data = err && err.response ? err.response : err
|
|
416
420
|
if (data.status === 400) {
|
|
417
421
|
var errMsg_1 = resource.error_400
|
|
418
|
-
p1.showError(errMsg_1, errHeader)
|
|
422
|
+
p1.showError(errMsg_1, undefined, errHeader)
|
|
419
423
|
} else {
|
|
420
|
-
p1.showError(errMsg, errHeader)
|
|
424
|
+
p1.showError(errMsg, undefined, errHeader)
|
|
421
425
|
}
|
|
422
426
|
}
|
|
423
427
|
}
|
|
@@ -442,7 +446,7 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
442
446
|
} else {
|
|
443
447
|
var title = resource.error
|
|
444
448
|
var err = resource.error_version
|
|
445
|
-
p1.showError(err, title)
|
|
449
|
+
p1.showError(err, undefined, title)
|
|
446
450
|
}
|
|
447
451
|
}
|
|
448
452
|
} else {
|
|
@@ -464,7 +468,7 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
464
468
|
var postSave = p && p.postSave ? p.postSave : _postSave
|
|
465
469
|
var _handleDuplicateKey = function (result) {
|
|
466
470
|
var resource = p1.resource.resource()
|
|
467
|
-
p1.showError(resource.error_duplicate_key, resource.error)
|
|
471
|
+
p1.showError(resource.error_duplicate_key, undefined, resource.error)
|
|
468
472
|
}
|
|
469
473
|
var handleDuplicateKey = p && p.handleDuplicateKey ? p.handleDuplicateKey : _handleDuplicateKey
|
|
470
474
|
var _doSave = function (obj, body, version, isBack) {
|
|
@@ -541,7 +545,7 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
541
545
|
if (data && (data.status === 401 || data.status === 403)) {
|
|
542
546
|
formutil_1.setReadOnly(refForm.current)
|
|
543
547
|
}
|
|
544
|
-
p1.showError(msg, title)
|
|
548
|
+
p1.showError(msg, undefined, title)
|
|
545
549
|
}
|
|
546
550
|
}
|
|
547
551
|
setRunning(false)
|
package/package.json
CHANGED
package/src/common.ts
CHANGED
|
@@ -8,11 +8,11 @@ export function messageByHttpStatus(status: number, resource: StringMap): string
|
|
|
8
8
|
}
|
|
9
9
|
return msg
|
|
10
10
|
}
|
|
11
|
-
export function error(err: any, resource: StringMap, ae: (msg: string,
|
|
11
|
+
export function error(err: any, resource: StringMap, ae: (msg: string, callback?: () => void, header?: string) => void) {
|
|
12
12
|
const title = resource.error
|
|
13
13
|
let msg = resource.error_internal
|
|
14
14
|
if (!err) {
|
|
15
|
-
ae(msg, title)
|
|
15
|
+
ae(msg, undefined, title)
|
|
16
16
|
return
|
|
17
17
|
}
|
|
18
18
|
const data = err && err.response ? err.response : err
|
|
@@ -21,8 +21,8 @@ export function error(err: any, resource: StringMap, ae: (msg: string, header?:
|
|
|
21
21
|
if (status && !isNaN(status)) {
|
|
22
22
|
msg = messageByHttpStatus(status, resource)
|
|
23
23
|
}
|
|
24
|
-
ae(msg, title)
|
|
24
|
+
ae(msg, undefined, title)
|
|
25
25
|
} else {
|
|
26
|
-
ae(msg, title)
|
|
26
|
+
ae(msg, undefined, title)
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/useEdit.ts
CHANGED
|
@@ -52,7 +52,7 @@ export function buildId<ID>(p: Readonly<Params<string>>, keys?: string[]): ID |
|
|
|
52
52
|
export interface EditParameter {
|
|
53
53
|
resource: ResourceService
|
|
54
54
|
showMessage: (msg: string, option?: string) => void
|
|
55
|
-
showError: (m: string,
|
|
55
|
+
showError: (m: string, callback?: () => void, header?: string) => void
|
|
56
56
|
confirm: (m2: string, yesCallback?: () => void, header?: string, btnLeftText?: string, btnRightText?: string, noCallback?: () => void) => void
|
|
57
57
|
ui?: UIService
|
|
58
58
|
getLocale?: (profile?: string) => Locale
|
|
@@ -164,7 +164,7 @@ export interface HookBaseEditParameter<T, ID, S> extends BaseEditComponentParam<
|
|
|
164
164
|
service: GenericService<T, ID, number | T | ErrorMessage[]>
|
|
165
165
|
resource: ResourceService
|
|
166
166
|
showMessage: (msg: string) => void
|
|
167
|
-
showError: (m: string,
|
|
167
|
+
showError: (m: string, callback?: () => void, header?: string) => void
|
|
168
168
|
getLocale?: () => Locale
|
|
169
169
|
confirm: (m2: string, yesCallback?: () => void, header?: string, btnLeftText?: string, btnRightText?: string, noCallback?: () => void) => void
|
|
170
170
|
ui?: UIService
|
|
@@ -340,7 +340,7 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
340
340
|
setReadOnly(form)
|
|
341
341
|
}
|
|
342
342
|
const resource = p1.resource.resource()
|
|
343
|
-
p1.showError(resource.error_404,
|
|
343
|
+
p1.showError(resource.error_404, () => window.history.back, resource.error)
|
|
344
344
|
}
|
|
345
345
|
const handleNotFound = p && p.handleNotFound ? p.handleNotFound : _handleNotFound
|
|
346
346
|
|
|
@@ -408,9 +408,9 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
408
408
|
const resource = p1.resource.resource()
|
|
409
409
|
if (p && p.readOnly) {
|
|
410
410
|
if (flag.newMode === true) {
|
|
411
|
-
p1.showError(resource.error_permission_add, resource.error_permission)
|
|
411
|
+
p1.showError(resource.error_permission_add, undefined, resource.error_permission)
|
|
412
412
|
} else {
|
|
413
|
-
p1.showError(resource.error_permission_edit, resource.error_permission)
|
|
413
|
+
p1.showError(resource.error_permission_edit, undefined, resource.error_permission)
|
|
414
414
|
}
|
|
415
415
|
} else {
|
|
416
416
|
if (running === true) {
|
|
@@ -507,17 +507,17 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
507
507
|
const t = resource.error
|
|
508
508
|
if (p1.ui && p1.ui.buildErrorMessage) {
|
|
509
509
|
const msg = p1.ui.buildErrorMessage(unmappedErrors)
|
|
510
|
-
p1.showError(msg, t)
|
|
510
|
+
p1.showError(msg, undefined, t)
|
|
511
511
|
} else {
|
|
512
|
-
p1.showError(unmappedErrors[0].field + " " + unmappedErrors[0].code + " " + unmappedErrors[0].message, t)
|
|
512
|
+
p1.showError(unmappedErrors[0].field + " " + unmappedErrors[0].code + " " + unmappedErrors[0].message, undefined, t)
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
515
|
} else {
|
|
516
516
|
const t = resource.error
|
|
517
517
|
if (result.length > 0) {
|
|
518
|
-
p1.showError(result[0].field + " " + result[0].code + " " + result[0].message, t)
|
|
518
|
+
p1.showError(result[0].field + " " + result[0].code + " " + result[0].message, undefined, t)
|
|
519
519
|
} else {
|
|
520
|
-
p1.showError(t, t)
|
|
520
|
+
p1.showError(t, undefined, t)
|
|
521
521
|
}
|
|
522
522
|
}
|
|
523
523
|
}
|
|
@@ -533,9 +533,9 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
533
533
|
const data = err && err.response ? err.response : err
|
|
534
534
|
if (data.status === 400) {
|
|
535
535
|
const errMsg = resource.error_400
|
|
536
|
-
p1.showError(errMsg, errHeader)
|
|
536
|
+
p1.showError(errMsg, undefined, errHeader)
|
|
537
537
|
} else {
|
|
538
|
-
p1.showError(errMsg, errHeader)
|
|
538
|
+
p1.showError(errMsg, undefined, errHeader)
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
}
|
|
@@ -562,7 +562,7 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
562
562
|
} else {
|
|
563
563
|
const title = resource.error
|
|
564
564
|
const err = resource.error_version
|
|
565
|
-
p1.showError(err, title)
|
|
565
|
+
p1.showError(err, undefined, title)
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
568
|
} else {
|
|
@@ -584,7 +584,7 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
584
584
|
|
|
585
585
|
const _handleDuplicateKey = (result?: T) => {
|
|
586
586
|
const resource = p1.resource.resource()
|
|
587
|
-
p1.showError(resource.error_duplicate_key, resource.error)
|
|
587
|
+
p1.showError(resource.error_duplicate_key, undefined, resource.error)
|
|
588
588
|
}
|
|
589
589
|
const handleDuplicateKey = p && p.handleDuplicateKey ? p.handleDuplicateKey : _handleDuplicateKey
|
|
590
590
|
|
|
@@ -659,7 +659,7 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
659
659
|
if (data && (data.status === 401 || data.status === 403)) {
|
|
660
660
|
setReadOnly(refForm.current)
|
|
661
661
|
}
|
|
662
|
-
p1.showError(msg, title)
|
|
662
|
+
p1.showError(msg, undefined, title)
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
665
|
setRunning(false)
|
package/src/useSearch.ts
CHANGED
|
@@ -38,7 +38,7 @@ interface Searchable extends Pagination, Sortable {
|
|
|
38
38
|
export interface SearchParameter {
|
|
39
39
|
resource: ResourceService
|
|
40
40
|
showMessage: (msg: string, option?: string) => void
|
|
41
|
-
showError: (m: string,
|
|
41
|
+
showError: (m: string, callback?: () => void, h?: string) => void
|
|
42
42
|
ui?: UIService
|
|
43
43
|
getLocale?: (profile?: string) => Locale
|
|
44
44
|
loading?: LoadingService
|
|
@@ -327,7 +327,7 @@ export interface HookBaseSearchParameter<T, S extends Filter, ST extends SearchC
|
|
|
327
327
|
service: ((s: S, limit?: number, offset?: number | string, fields?: string[]) => Promise<SearchResult<T>>) | SearchService<T, S>
|
|
328
328
|
resource: ResourceService
|
|
329
329
|
showMessage: (msg: string) => void
|
|
330
|
-
showError: (m: string,
|
|
330
|
+
showError: (m: string, callback?: () => void, header?: string) => void
|
|
331
331
|
getLocale?: () => Locale
|
|
332
332
|
autoSearch?: boolean
|
|
333
333
|
}
|