@applica-software-guru/react-admin 1.0.46 → 1.0.51
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/bitbucket-pipelines.yml +2 -1
- package/dist/AdminContext.d.ts +5 -10
- package/dist/AdminContext.d.ts.map +1 -1
- package/dist/ApplicaAdmin.d.ts +51 -17
- package/dist/ApplicaAdmin.d.ts.map +1 -1
- package/dist/components/@extended/Breadcrumbs.d.ts +1 -0
- package/dist/components/@extended/Breadcrumbs.d.ts.map +1 -1
- package/dist/components/Layout/Drawer/DrawerHeader/DrawerHeaderStyled.d.ts +1 -1
- package/dist/components/MainCard.d.ts +70 -1
- package/dist/components/MainCard.d.ts.map +1 -1
- package/dist/components/Notification.d.ts +2 -2
- package/dist/components/ra-forms/TabbedForm.d.ts +2 -2
- package/dist/components/ra-lists/Datagrid.d.ts +25 -12
- package/dist/components/ra-lists/Datagrid.d.ts.map +1 -1
- package/dist/components/ra-lists/Empty.d.ts +42 -17
- package/dist/components/ra-lists/Empty.d.ts.map +1 -1
- package/dist/components/ra-lists/List.d.ts +8 -6
- package/dist/components/ra-lists/List.d.ts.map +1 -1
- package/dist/components/ra-lists/index.d.ts +1 -1
- package/dist/components/ra-lists/index.d.ts.map +1 -1
- package/dist/contexts/MenuConfigContext.d.ts +34 -12
- package/dist/contexts/MenuConfigContext.d.ts.map +1 -1
- package/dist/contexts/MenuPropTypes.d.ts +1 -0
- package/dist/contexts/MenuPropTypes.d.ts.map +1 -1
- package/dist/dev/index.d.ts +1 -2
- package/dist/dev/index.d.ts.map +1 -1
- package/dist/dev/useCliErrorCatcher.d.ts +57 -29
- package/dist/dev/useCliErrorCatcher.d.ts.map +1 -1
- package/dist/i18n/useI18nCatcher.d.ts +26 -13
- package/dist/i18n/useI18nCatcher.d.ts.map +1 -1
- package/dist/react-admin.cjs.js +44 -44
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +3893 -3886
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +44 -44
- package/dist/react-admin.umd.js.map +1 -1
- package/dist/types.d.ts +54 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/AdminContext.tsx +19 -0
- package/src/{ApplicaAdmin.jsx → ApplicaAdmin.tsx} +115 -50
- package/src/components/{MainCard.jsx → MainCard.tsx} +74 -3
- package/src/components/ra-lists/{Datagrid.jsx → Datagrid.tsx} +14 -3
- package/src/components/ra-lists/{Empty.jsx → Empty.tsx} +31 -2
- package/src/components/ra-lists/{List.jsx → List.tsx} +3 -2
- package/src/contexts/MenuConfigContext.tsx +117 -0
- package/src/contexts/MenuPropTypes.jsx +2 -1
- package/src/dev/useCliErrorCatcher.ts +142 -0
- package/src/i18n/{useI18nCatcher.jsx → useI18nCatcher.ts} +49 -11
- package/src/types.ts +55 -0
- package/src/AdminContext.jsx +0 -24
- package/src/contexts/MenuConfigContext.jsx +0 -93
- package/src/dev/useCliErrorCatcher.jsx +0 -86
- /package/src/components/ra-lists/{index.jsx → index.ts} +0 -0
- /package/src/dev/{index.jsx → index.ts} +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/* eslint-disable prefer-rest-params */
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
export type CatchResultProps = {
|
|
6
|
+
catch: boolean;
|
|
7
|
+
display: boolean;
|
|
8
|
+
log: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
class CatchResult {
|
|
13
|
+
catch: boolean;
|
|
14
|
+
display: boolean;
|
|
15
|
+
log: boolean;
|
|
16
|
+
error?: string;
|
|
17
|
+
|
|
18
|
+
constructor({ catch: catchErr, display: displayErr, log: logErr, error }: CatchResultProps) {
|
|
19
|
+
this.catch = catchErr;
|
|
20
|
+
this.display = displayErr;
|
|
21
|
+
this.log = logErr;
|
|
22
|
+
this.error = error;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
isCatched() {
|
|
26
|
+
return this.catch;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
logError() {
|
|
30
|
+
return this.log;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
displayError() {
|
|
34
|
+
return this.display;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type CliErrorCatcherBodyBuilderProps = (error: string | any) => any;
|
|
39
|
+
|
|
40
|
+
type CliErrorCatcherPutProps = {
|
|
41
|
+
apiUrl: string;
|
|
42
|
+
endpoint?: string;
|
|
43
|
+
message: string;
|
|
44
|
+
bodyBuilder: CliErrorCatcherBodyBuilderProps;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const putError = ({ apiUrl, endpoint, message, bodyBuilder }: CliErrorCatcherPutProps) =>
|
|
48
|
+
fetch(`${apiUrl}${endpoint}`, {
|
|
49
|
+
method: 'PUT',
|
|
50
|
+
headers: new Headers({
|
|
51
|
+
Accept: 'application/json',
|
|
52
|
+
'Content-Type': 'application/json'
|
|
53
|
+
}),
|
|
54
|
+
body: JSON.stringify(bodyBuilder(message))
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export type UseCliErrorCatcherProps = {
|
|
58
|
+
/**
|
|
59
|
+
* Definisce l'URL del server API.
|
|
60
|
+
*/
|
|
61
|
+
apiUrl: string;
|
|
62
|
+
/**
|
|
63
|
+
* Definisce se il catcher è abilitato.
|
|
64
|
+
*/
|
|
65
|
+
enabled?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Definisce l'endpoint del server API su cui inviare l'errore.
|
|
68
|
+
* Questo parametro viene aggiunto all'URL del server API (apiUrl) attraverso una semplice concatenazione.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* // Serve più per ricordarti come funziona quando lo utilizzerai attivamente dopo tanto tempo (ti conosco bene Roberto, dimenticherai tutto!).
|
|
72
|
+
* let apiUrl = 'http://localhost:3000';
|
|
73
|
+
* let endpoint = '/ui-errors/put';
|
|
74
|
+
* let url = apiUrl + endpoint;
|
|
75
|
+
* // url = 'http://localhost:3000/ui-errors/put'
|
|
76
|
+
*/
|
|
77
|
+
endpoint?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Definisce se l'applicazione chiamante è in caricamento.
|
|
80
|
+
* In tal caso il catcher non viene attivato.
|
|
81
|
+
*/
|
|
82
|
+
loading?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Definisce la funzione che determina se l'errore deve essere catturato.
|
|
85
|
+
*
|
|
86
|
+
* @param error
|
|
87
|
+
* @returns {CatchResult} Restituisce un oggetto di tipo CatchResult.
|
|
88
|
+
*/
|
|
89
|
+
catcherFn?: (error: string | any) => CatchResult;
|
|
90
|
+
/**
|
|
91
|
+
* Definisce la funzione che costruisce il body da inviare al server API.
|
|
92
|
+
*/
|
|
93
|
+
bodyBuilder?: CliErrorCatcherBodyBuilderProps;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const useCliErrorCatcher = ({
|
|
97
|
+
enabled = true,
|
|
98
|
+
apiUrl,
|
|
99
|
+
endpoint = '/ui-errors/put',
|
|
100
|
+
loading,
|
|
101
|
+
catcherFn = (error) => new CatchResult({ catch: error != undefined, display: false, log: false }),
|
|
102
|
+
bodyBuilder = (error) => ({ message: error })
|
|
103
|
+
}: UseCliErrorCatcherProps) => {
|
|
104
|
+
React.useMemo(() => {
|
|
105
|
+
if (loading) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!enabled) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const consoleError = console.error;
|
|
113
|
+
|
|
114
|
+
console.error = function (error, ...args) {
|
|
115
|
+
if (!error || typeof error !== 'string') {
|
|
116
|
+
consoleError.apply(console, arguments as any);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const message = error.replace(/%s/g, () => args.shift());
|
|
120
|
+
const catchResult = catcherFn(message);
|
|
121
|
+
if (!catchResult.isCatched()) {
|
|
122
|
+
consoleError.apply(console, arguments as any);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (catchResult.logError()) {
|
|
127
|
+
putError({ apiUrl, endpoint, message, bodyBuilder });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (catchResult.displayError()) {
|
|
131
|
+
consoleError.apply(console, arguments as any);
|
|
132
|
+
} else {
|
|
133
|
+
// eslint-disable-next-line prefer-spread
|
|
134
|
+
console.debug.apply(console, arguments as any);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}, [apiUrl, loading, bodyBuilder, endpoint, catcherFn, enabled]);
|
|
138
|
+
return true;
|
|
139
|
+
};
|
|
140
|
+
export { CatchResult };
|
|
141
|
+
|
|
142
|
+
export default useCliErrorCatcher;
|
|
@@ -3,9 +3,33 @@ import * as React from 'react';
|
|
|
3
3
|
|
|
4
4
|
import { useLocaleState } from 'react-admin';
|
|
5
5
|
|
|
6
|
-
const queued = [];
|
|
6
|
+
const queued: string[] = [];
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
export type I18nCatcherBodyBuilderResultProps =
|
|
9
|
+
| {
|
|
10
|
+
lang: string;
|
|
11
|
+
code: string;
|
|
12
|
+
text: string;
|
|
13
|
+
}
|
|
14
|
+
| {
|
|
15
|
+
message: {
|
|
16
|
+
lang: string;
|
|
17
|
+
code: string;
|
|
18
|
+
text: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type I18nCatcherBodyBuilderProps = (lang: string, message: string) => I18nCatcherBodyBuilderResultProps;
|
|
23
|
+
|
|
24
|
+
type PutMessageProps = {
|
|
25
|
+
apiUrl: string;
|
|
26
|
+
endpoint?: string;
|
|
27
|
+
locale: string;
|
|
28
|
+
message: string;
|
|
29
|
+
bodyBuilder: I18nCatcherBodyBuilderProps;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const putMessage = ({ apiUrl, endpoint, locale, message, bodyBuilder }: PutMessageProps): any =>
|
|
9
33
|
message != null &&
|
|
10
34
|
message !== 'undefined' &&
|
|
11
35
|
message.indexOf('[') === -1 &&
|
|
@@ -18,22 +42,34 @@ const putMessage = ({ apiUrl, endpoint, locale, message, bodyBuilder }) =>
|
|
|
18
42
|
Accept: 'application/json',
|
|
19
43
|
'Content-Type': 'application/json'
|
|
20
44
|
}),
|
|
21
|
-
body: JSON.stringify(bodyBuilder(locale, message))
|
|
45
|
+
body: JSON.stringify(bodyBuilder(locale, message) || {})
|
|
22
46
|
});
|
|
23
47
|
|
|
48
|
+
export type UseI18nCatcherProps = {
|
|
49
|
+
apiUrl: string;
|
|
50
|
+
enabled?: boolean;
|
|
51
|
+
endpoint?: string;
|
|
52
|
+
loading?: boolean;
|
|
53
|
+
bodyBuilder: I18nCatcherBodyBuilderProps;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Hook che consente di catturare ed inoltrare al server API le stringhe non tradotte.
|
|
58
|
+
*
|
|
59
|
+
* @param {UseI18nCatcherProps}
|
|
60
|
+
* @returns {boolean}
|
|
61
|
+
*/
|
|
24
62
|
const useI18nCatcher = ({
|
|
25
63
|
apiUrl,
|
|
26
64
|
enabled = true,
|
|
27
65
|
endpoint = '/languages/put-message',
|
|
28
66
|
loading,
|
|
29
|
-
bodyBuilder = (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
text: message
|
|
34
|
-
}
|
|
67
|
+
bodyBuilder = (lang, message) => ({
|
|
68
|
+
lang,
|
|
69
|
+
code: message,
|
|
70
|
+
text: message
|
|
35
71
|
})
|
|
36
|
-
}) => {
|
|
72
|
+
}: UseI18nCatcherProps) => {
|
|
37
73
|
const [locale] = useLocaleState();
|
|
38
74
|
React.useMemo(() => {
|
|
39
75
|
if (loading) {
|
|
@@ -62,7 +98,9 @@ const useI18nCatcher = ({
|
|
|
62
98
|
return;
|
|
63
99
|
}
|
|
64
100
|
|
|
65
|
-
|
|
101
|
+
// eslint-disable-next-line prefer-rest-params
|
|
102
|
+
// eslint-disable-next-line prefer-rest-params
|
|
103
|
+
consoleError.apply(console, arguments as any);
|
|
66
104
|
};
|
|
67
105
|
}, [apiUrl, locale, loading, bodyBuilder, endpoint, enabled]);
|
|
68
106
|
return true;
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Definisce le proprietà di un elemento del menu.
|
|
5
|
+
*/
|
|
6
|
+
export type MenuItemProps = {
|
|
7
|
+
id: string;
|
|
8
|
+
/**
|
|
9
|
+
* Titolo da attribure all'elemento del menu.
|
|
10
|
+
* Il titolo deve essere una stringa localizzata: es. ra.menu.item.foo
|
|
11
|
+
*/
|
|
12
|
+
title: string;
|
|
13
|
+
/**
|
|
14
|
+
* Icona da attribuire all'elemento del menu.
|
|
15
|
+
*/
|
|
16
|
+
icon: React.ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Tipo di elemento del menu.
|
|
19
|
+
* - item: elemento di menu normale
|
|
20
|
+
* - group: gruppo di elementi di menu
|
|
21
|
+
* - collapse: gruppo di elementi di menu con collapse
|
|
22
|
+
*/
|
|
23
|
+
type: 'item' | 'group' | 'collapse';
|
|
24
|
+
/**
|
|
25
|
+
* URL da attribuire all'elemento del menu.
|
|
26
|
+
* Può puntare ad una risorsa o ad una pagina personalizzata purché la stessa sia stata registrata nell'appliazione.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* /entities/user
|
|
30
|
+
* /pages/foo
|
|
31
|
+
*/
|
|
32
|
+
url: string;
|
|
33
|
+
/**
|
|
34
|
+
* Indica se l'elemento del menu è una risorsa.
|
|
35
|
+
*/
|
|
36
|
+
resource: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Elenco dei ruoli che possono accedere all'elemento del menu.
|
|
39
|
+
* Se l'utente collegato non contiene almeno uno dei ruoli specificati l'elemento del menu non viene visualizzato.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ["ROLE_ADMIN", "ROLE_USER"]
|
|
43
|
+
*/
|
|
44
|
+
roles: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Elenco dei figli dell'elemento del menu.
|
|
47
|
+
* Valido solo per i tipi "group" e "collapse".
|
|
48
|
+
*/
|
|
49
|
+
children?: MenuItemProps[];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Indica come deve essere configurato il menu dell'applicazione.
|
|
54
|
+
*/
|
|
55
|
+
export type MenuProps = MenuItemProps[];
|
package/src/AdminContext.jsx
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { CoreAdminContext } from 'react-admin';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { ScrollTop } from './components';
|
|
4
|
-
import { ThemeCustomization } from './themes';
|
|
5
|
-
|
|
6
|
-
const AdminContext = ({ children, theme, ...props }) => (
|
|
7
|
-
<CoreAdminContext {...props}>
|
|
8
|
-
<ThemeCustomization themeOverrides={theme}>
|
|
9
|
-
<ScrollTop>{children}</ScrollTop>
|
|
10
|
-
</ThemeCustomization>
|
|
11
|
-
</CoreAdminContext>
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
AdminContext.displayName = 'ApplicaAdminContext';
|
|
15
|
-
AdminContext.defaultProps = {
|
|
16
|
-
...CoreAdminContext.defaultProps
|
|
17
|
-
};
|
|
18
|
-
AdminContext.propTypes = {
|
|
19
|
-
...CoreAdminContext.propTypes,
|
|
20
|
-
children: PropTypes.node.isRequired,
|
|
21
|
-
theme: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default AdminContext;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import MenuPropTypes from './MenuPropTypes';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { createContext } from 'react';
|
|
4
|
-
import { useLocalStorage } from '../hooks';
|
|
5
|
-
|
|
6
|
-
const initialState = {
|
|
7
|
-
openItem: ['dashboard'],
|
|
8
|
-
openComponent: 'buttons',
|
|
9
|
-
selectedID: null,
|
|
10
|
-
drawerOpen: false,
|
|
11
|
-
componentDrawerOpen: true,
|
|
12
|
-
menuDashboard: {},
|
|
13
|
-
error: null
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const MenuConfigContext = createContext(initialState);
|
|
17
|
-
|
|
18
|
-
const MenuConfigProvider = ({ menu: groups, children }) => {
|
|
19
|
-
const [menu, setMenu] = useLocalStorage('menu-config', { ...initialState });
|
|
20
|
-
|
|
21
|
-
const activeItem = (openItem) => {
|
|
22
|
-
setMenu((menu) => ({
|
|
23
|
-
...menu,
|
|
24
|
-
openItem
|
|
25
|
-
}));
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const activeID = (selectedID) => {
|
|
29
|
-
setMenu((menu) => ({
|
|
30
|
-
...menu,
|
|
31
|
-
selectedID
|
|
32
|
-
}));
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const activeComponent = (openComponent) => {
|
|
36
|
-
setMenu((menu) => ({
|
|
37
|
-
...menu,
|
|
38
|
-
openComponent
|
|
39
|
-
}));
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const openDrawer = (drawerOpen) => {
|
|
43
|
-
setMenu((menu) => ({
|
|
44
|
-
...menu,
|
|
45
|
-
drawerOpen
|
|
46
|
-
}));
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const openComponentDrawer = (componentDrawerOpen) => {
|
|
50
|
-
setMenu((menu) => ({
|
|
51
|
-
...menu,
|
|
52
|
-
componentDrawerOpen
|
|
53
|
-
}));
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const getMenuSuccess = (menuDashboard) => {
|
|
57
|
-
setMenu((menu) => ({
|
|
58
|
-
...menu,
|
|
59
|
-
menuDashboard
|
|
60
|
-
}));
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const hasError = (error) => {
|
|
64
|
-
setMenu((menu) => ({
|
|
65
|
-
...menu,
|
|
66
|
-
error
|
|
67
|
-
}));
|
|
68
|
-
};
|
|
69
|
-
return (
|
|
70
|
-
<MenuConfigContext.Provider
|
|
71
|
-
value={{
|
|
72
|
-
...menu,
|
|
73
|
-
groups,
|
|
74
|
-
activeItem,
|
|
75
|
-
activeComponent,
|
|
76
|
-
openDrawer,
|
|
77
|
-
openComponentDrawer,
|
|
78
|
-
activeID,
|
|
79
|
-
getMenuSuccess,
|
|
80
|
-
hasError
|
|
81
|
-
}}
|
|
82
|
-
>
|
|
83
|
-
{children}
|
|
84
|
-
</MenuConfigContext.Provider>
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
MenuConfigProvider.propTypes = {
|
|
89
|
-
children: PropTypes.node,
|
|
90
|
-
menu: PropTypes.arrayOf(MenuPropTypes)
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export { MenuConfigContext, MenuConfigProvider };
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
class CatchResult {
|
|
5
|
-
constructor({ catch: catchErr, display: displayErr, log: logErr, error }) {
|
|
6
|
-
this.catch = catchErr;
|
|
7
|
-
this.display = displayErr;
|
|
8
|
-
this.log = logErr;
|
|
9
|
-
this.error = error;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
isCatched() {
|
|
13
|
-
return this.catch;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
logError() {
|
|
17
|
-
return this.log;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
displayError() {
|
|
21
|
-
return this.display;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const putError = ({ apiUrl, endpoint, locale, message, bodyBuilder }) =>
|
|
26
|
-
fetch(`${apiUrl}${endpoint}`, {
|
|
27
|
-
method: 'PUT',
|
|
28
|
-
headers: new Headers({
|
|
29
|
-
Accept: 'application/json',
|
|
30
|
-
'Content-Type': 'application/json'
|
|
31
|
-
}),
|
|
32
|
-
body: JSON.stringify(bodyBuilder(locale, message))
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const useCliErrorCatcher = ({
|
|
36
|
-
enabled = true,
|
|
37
|
-
apiUrl,
|
|
38
|
-
endpoint = '/ui-errors/put',
|
|
39
|
-
loading,
|
|
40
|
-
catcherFn = (error) => new CatchResult({ catch: error != undefined, display: false, log: false }),
|
|
41
|
-
bodyBuilder = (locale, message) => ({
|
|
42
|
-
code: locale,
|
|
43
|
-
message: {
|
|
44
|
-
code: message,
|
|
45
|
-
text: message
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
}) => {
|
|
49
|
-
React.useMemo(() => {
|
|
50
|
-
if (loading) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (!enabled) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const consoleError = console.error;
|
|
58
|
-
|
|
59
|
-
console.error = function (error, ...args) {
|
|
60
|
-
if (!error || typeof error !== 'string') {
|
|
61
|
-
consoleError.apply(console, arguments);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const message = error.replace(/%s/g, () => args.shift());
|
|
65
|
-
const catchResult = catcherFn(message);
|
|
66
|
-
if (!catchResult.isCatched()) {
|
|
67
|
-
consoleError.apply(console, arguments);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (catchResult.logError()) {
|
|
72
|
-
putError({ apiUrl, endpoint, message, bodyBuilder });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (catchResult.displayError()) {
|
|
76
|
-
consoleError.apply(console, arguments);
|
|
77
|
-
} else {
|
|
78
|
-
console.debug.apply(console, arguments);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}, [apiUrl, loading, bodyBuilder, endpoint, catcherFn, enabled]);
|
|
82
|
-
return true;
|
|
83
|
-
};
|
|
84
|
-
export { CatchResult };
|
|
85
|
-
|
|
86
|
-
export default useCliErrorCatcher;
|
|
File without changes
|
|
File without changes
|