@applica-software-guru/react-admin 1.5.267 → 1.5.269
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/ApplicaAdmin.d.ts +5 -1
- package/dist/ApplicaAdmin.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts +4 -0
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/i18n/createI18nProvider.d.ts +11 -1
- package/dist/i18n/createI18nProvider.d.ts.map +1 -1
- package/dist/react-admin.cjs.js +36 -36
- package/dist/react-admin.cjs.js.gz +0 -0
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +835 -822
- package/dist/react-admin.es.js.gz +0 -0
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +25 -25
- package/dist/react-admin.umd.js.gz +0 -0
- package/dist/react-admin.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/ApplicaAdmin.tsx +20 -3
- package/src/components/Layout/Layout.tsx +5 -3
- package/src/i18n/createI18nProvider.tsx +15 -4
- package/src/playground/App.jsx +3 -3
package/package.json
CHANGED
package/src/ApplicaAdmin.tsx
CHANGED
|
@@ -52,6 +52,7 @@ function ApplicaAdmin({
|
|
|
52
52
|
enableRegistration = false,
|
|
53
53
|
enablePasswordRecover = false,
|
|
54
54
|
enableThemeToggler = false,
|
|
55
|
+
enableLocaleSwitcher = false,
|
|
55
56
|
queryClient = defaultQueryClient,
|
|
56
57
|
background,
|
|
57
58
|
notificationAPI = 'entities/notification',
|
|
@@ -76,7 +77,7 @@ function ApplicaAdmin({
|
|
|
76
77
|
const result = new CatchResult({
|
|
77
78
|
catch: isKnowBug,
|
|
78
79
|
display: !isKnowBug,
|
|
79
|
-
log: !isKnowBug,
|
|
80
|
+
log: !isKnowBug && development === true,
|
|
80
81
|
error: errorMessage
|
|
81
82
|
});
|
|
82
83
|
return result;
|
|
@@ -106,17 +107,29 @@ function ApplicaAdmin({
|
|
|
106
107
|
{...props}
|
|
107
108
|
name={name}
|
|
108
109
|
copy={copy}
|
|
109
|
-
enableThemeToggler={enableThemeToggler}
|
|
110
110
|
version={version}
|
|
111
111
|
logoMain={_logoMain}
|
|
112
112
|
logoIcon={_logoIcon}
|
|
113
113
|
notification={notificationAPI}
|
|
114
|
+
enableThemeToggler={enableThemeToggler}
|
|
114
115
|
enableNotification={enableNotification}
|
|
116
|
+
enableLocaleSwitcher={enableLocaleSwitcher}
|
|
115
117
|
error={error}
|
|
116
118
|
/>
|
|
117
119
|
);
|
|
118
120
|
},
|
|
119
|
-
[
|
|
121
|
+
[
|
|
122
|
+
logoMain,
|
|
123
|
+
logoIcon,
|
|
124
|
+
name,
|
|
125
|
+
copy,
|
|
126
|
+
version,
|
|
127
|
+
error,
|
|
128
|
+
notificationAPI,
|
|
129
|
+
enableNotification,
|
|
130
|
+
enableThemeToggler,
|
|
131
|
+
enableLocaleSwitcher
|
|
132
|
+
]
|
|
120
133
|
);
|
|
121
134
|
|
|
122
135
|
const i18nProvider = useI18nProvider({
|
|
@@ -292,6 +305,10 @@ type ApplicaAdminProps = AdminProps & {
|
|
|
292
305
|
* Indicates whether the theme toggler should be displayed.
|
|
293
306
|
*/
|
|
294
307
|
enableThemeToggler: boolean;
|
|
308
|
+
/**
|
|
309
|
+
* Indicates whether the locale switcher should be displayed.
|
|
310
|
+
*/
|
|
311
|
+
enableLocaleSwitcher: boolean;
|
|
295
312
|
};
|
|
296
313
|
|
|
297
314
|
export { ApplicaAdmin };
|
|
@@ -18,21 +18,23 @@ type ILayoutProps = React.PropsWithChildren<{
|
|
|
18
18
|
copy?: string;
|
|
19
19
|
error?: React.ComponentType<ErrorProps>;
|
|
20
20
|
enableThemeToggler: boolean;
|
|
21
|
+
enableNotification: boolean;
|
|
22
|
+
enableLocaleSwitcher: boolean;
|
|
21
23
|
}>;
|
|
22
24
|
|
|
23
25
|
const Layout = withLayoutProvider(function Layout(props: ILayoutProps) {
|
|
24
|
-
const { name, version, enableThemeToggler } = props;
|
|
26
|
+
const { name, version, enableThemeToggler, enableNotification, enableLocaleSwitcher } = props;
|
|
25
27
|
const { isLoading, navigation, breadcrumbs } = useBreadcrumbs();
|
|
26
28
|
|
|
27
29
|
return (
|
|
28
30
|
<LayoutWrapper>
|
|
29
31
|
<Header>
|
|
30
32
|
<HeaderSpacer />
|
|
31
|
-
<LocaleButton />
|
|
33
|
+
{enableLocaleSwitcher ? <LocaleButton /> : null}
|
|
32
34
|
{enableThemeToggler ? <ThemeToggler /> : null}
|
|
33
35
|
<ThemeColor />
|
|
34
36
|
<LoadingIndicator />
|
|
35
|
-
<HeaderNotification />
|
|
37
|
+
{enableNotification ? <HeaderNotification /> : null}
|
|
36
38
|
<ResponsiveSection>
|
|
37
39
|
<HeaderProfile />
|
|
38
40
|
</ResponsiveSection>
|
|
@@ -18,6 +18,10 @@ type ICreateI18nProviderData = {
|
|
|
18
18
|
createMissing?: boolean;
|
|
19
19
|
customProvider?: Promise<I18nProvider>;
|
|
20
20
|
};
|
|
21
|
+
type ICreateJsonI18nProviderData = {
|
|
22
|
+
path: string;
|
|
23
|
+
defaultLocale: string;
|
|
24
|
+
};
|
|
21
25
|
type IPolyglotOptions = {
|
|
22
26
|
phrases?: IDictionary;
|
|
23
27
|
locale?: string;
|
|
@@ -88,19 +92,26 @@ function createI18nProvider(data: ICreateI18nProviderData): Promise<any> {
|
|
|
88
92
|
});
|
|
89
93
|
});
|
|
90
94
|
}
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Create an I18nProvider that fetches translations from JSON files.
|
|
98
|
+
*
|
|
99
|
+
* @param data {ICreateI18nProviderData} - The data to create the I18nProvider
|
|
100
|
+
* @returns {Promise<I18nProvider>} - The I18nProvider
|
|
101
|
+
*/
|
|
102
|
+
function createJsonI18nProvider(data: ICreateJsonI18nProviderData): Promise<I18nProvider> {
|
|
103
|
+
const { defaultLocale, path } = data;
|
|
93
104
|
const defaultLanguages: Array<Locale> = [{ locale: defaultLocale, name: defaultLocale }];
|
|
94
105
|
const headers = new Headers({ Accept: 'application/json', 'Content-Type': 'application/json' });
|
|
95
106
|
function getLanguages(): Promise<Locale> {
|
|
96
|
-
return fetch(`${
|
|
107
|
+
return fetch(`${path}/languages.json`, { headers: headers, method: 'get' })
|
|
97
108
|
.then((response) => response.json())
|
|
98
109
|
.catch(() => {
|
|
99
110
|
return Promise.resolve(defaultLanguages);
|
|
100
111
|
});
|
|
101
112
|
}
|
|
102
113
|
function getMessages(): Promise<ITranslations> {
|
|
103
|
-
return fetch(`${
|
|
114
|
+
return fetch(`${path}/messages.json`, { headers: headers, method: 'get' })
|
|
104
115
|
.then((response) => response.json())
|
|
105
116
|
.then((response: Array<IMessage>): ITranslations => {
|
|
106
117
|
return response.reduce(
|
package/src/playground/App.jsx
CHANGED
|
@@ -9,7 +9,7 @@ import { ApplicaDataProvider, createAttachmentsParser } from '@applica-software-
|
|
|
9
9
|
import { ApplicaAuthProvider, LocalStorage } from '@applica-software-guru/iam-client';
|
|
10
10
|
import { CustomRoutes } from 'ra-core';
|
|
11
11
|
import { Route } from 'react-router-dom';
|
|
12
|
-
|
|
12
|
+
import { createJsonI18nProvider } from '@/i18n';
|
|
13
13
|
|
|
14
14
|
const authProvider = new ApplicaAuthProvider(API_URL, new LocalStorage());
|
|
15
15
|
const dataProvider = new ApplicaDataProvider({
|
|
@@ -20,7 +20,7 @@ const dataProvider = new ApplicaDataProvider({
|
|
|
20
20
|
attachmentsParser: createAttachmentsParser(),
|
|
21
21
|
HttpErrorClass: HttpError
|
|
22
22
|
});
|
|
23
|
-
|
|
23
|
+
const i18nProvider = createJsonI18nProvider({ path: `//${document.location.host}/i18n`, defaultLocale: 'en' });
|
|
24
24
|
function App() {
|
|
25
25
|
return (
|
|
26
26
|
<ApplicaAdmin
|
|
@@ -31,7 +31,7 @@ function App() {
|
|
|
31
31
|
apiUrl={API_URL}
|
|
32
32
|
authProvider={authProvider}
|
|
33
33
|
dataProvider={dataProvider}
|
|
34
|
-
|
|
34
|
+
i18nProvider={i18nProvider}
|
|
35
35
|
defaultLocale="it"
|
|
36
36
|
menu={menu}
|
|
37
37
|
name={APP_NAME}
|