@applica-software-guru/react-admin 1.0.45 → 1.0.47
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/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/Notification.d.ts +2 -2
- package/dist/components/ra-forms/TabbedForm.d.ts +2 -2
- package/dist/components/ra-lists/Datagrid.d.ts +6 -6
- 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 +3891 -3885
- 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/Layout/Header/HeaderContent/Profile.jsx +1 -1
- 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/dev/{index.jsx → index.ts} +0 -0
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
|