Skip to content

Commit d5b70dd

Browse files
Fix codebase (#14)
* add logo, favicon and app color * fix APP_NAME case when used * move src/components/app* components in sub-folder * remove unused and empty parameters dialog * delete unused src/plugins from template * remove comments in dts * add MUI translations
1 parent 6b533d5 commit d5b70dd

19 files changed

+162
-341
lines changed

public/favicon.ico

114 KB
Binary file not shown.

src/components/App/app-top-bar.tsx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2021, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
import { FunctionComponent, useEffect, useState } from 'react';
9+
import { capitalize, useTheme } from '@mui/material';
10+
import { logout, TopBar } from '@gridsuite/commons-ui';
11+
import { useParameterState } from '../parameters';
12+
import {
13+
APP_NAME,
14+
PARAM_LANGUAGE,
15+
PARAM_THEME,
16+
} from '../../utils/config-params';
17+
import { useNavigate } from 'react-router-dom';
18+
import { useDispatch } from 'react-redux';
19+
import { AppsMetadataSrv, MetadataJson, StudySrv } from '../../services';
20+
import { ReactComponent as GridAdminLogoLight } from '../../images/GridAdmin_logo_light.svg';
21+
import { ReactComponent as GridAdminLogoDark } from '../../images/GridAdmin_logo_dark.svg';
22+
import AppPackage from '../../../package.json';
23+
import { AppState } from '../../redux/reducer';
24+
25+
export type AppTopBarProps = {
26+
user?: AppState['user'];
27+
userManager: {
28+
instance: unknown | null;
29+
error: string | null;
30+
};
31+
};
32+
33+
const AppTopBar: FunctionComponent<AppTopBarProps> = (props) => {
34+
const navigate = useNavigate();
35+
const theme = useTheme();
36+
const dispatch = useDispatch();
37+
38+
const [appsAndUrls, setAppsAndUrls] = useState<MetadataJson[]>([]);
39+
40+
const [themeLocal, handleChangeTheme] = useParameterState(PARAM_THEME);
41+
const [languageLocal, handleChangeLanguage] =
42+
useParameterState(PARAM_LANGUAGE);
43+
44+
useEffect(() => {
45+
if (props.user !== null) {
46+
AppsMetadataSrv.fetchAppsAndUrls().then((res) => {
47+
setAppsAndUrls(res);
48+
});
49+
}
50+
}, [props.user]);
51+
52+
return (
53+
<TopBar
54+
appName={capitalize(APP_NAME)}
55+
appColor="#FD3745"
56+
appLogo={
57+
theme.palette.mode === 'light' ? (
58+
<GridAdminLogoLight />
59+
) : (
60+
<GridAdminLogoDark />
61+
)
62+
}
63+
appVersion={AppPackage.version}
64+
appLicense={AppPackage.license}
65+
onLogoutClick={() => logout(dispatch, props.userManager.instance)}
66+
onLogoClick={() => navigate('/', { replace: true })}
67+
user={props.user}
68+
appsAndUrls={appsAndUrls}
69+
globalVersionPromise={() =>
70+
AppsMetadataSrv.fetchVersion().then((res) => res?.deployVersion)
71+
}
72+
additionalModulesPromise={StudySrv.getServersInfos}
73+
onThemeClick={handleChangeTheme}
74+
theme={themeLocal}
75+
onLanguageClick={handleChangeLanguage}
76+
language={languageLocal}
77+
/>
78+
);
79+
};
80+
export default AppTopBar;

src/components/app-wrapper.tsx renamed to src/components/App/app-wrapper.tsx

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66
*/
77

88
import App from './app';
9-
import { FunctionComponent } from 'react';
10-
import { CssBaseline } from '@mui/material';
9+
import { FunctionComponent, useMemo } from 'react';
10+
import { CssBaseline, responsiveFontSizes, ThemeOptions } from '@mui/material';
1111
import {
1212
createTheme,
1313
StyledEngineProvider,
1414
Theme,
1515
ThemeProvider,
1616
} from '@mui/material/styles';
17+
import { enUS as MuiCoreEnUS, frFR as MuiCoreFrFR } from '@mui/material/locale';
1718
import {
1819
card_error_boundary_en,
1920
card_error_boundary_fr,
2021
CardErrorBoundary,
22+
LANG_ENGLISH,
23+
LANG_FRENCH,
2124
LIGHT_THEME,
2225
login_en,
2326
login_fr,
@@ -28,17 +31,15 @@ import {
2831
import { IntlProvider } from 'react-intl';
2932
import { BrowserRouter } from 'react-router-dom';
3033
import { Provider, useSelector } from 'react-redux';
31-
import { SupportedLanguages } from '../utils/language';
32-
import messages_en from '../translations/en.json';
33-
import messages_fr from '../translations/fr.json';
34-
import messages_plugins_en from '../plugins/translations/en.json';
35-
import messages_plugins_fr from '../plugins/translations/fr.json';
36-
import { store } from '../redux/store';
37-
import { PARAM_THEME } from '../utils/config-params';
34+
import { SupportedLanguages } from '../../utils/language';
35+
import messages_en from '../../translations/en.json';
36+
import messages_fr from '../../translations/fr.json';
37+
import { store } from '../../redux/store';
38+
import { PARAM_THEME } from '../../utils/config-params';
3839
import { IntlConfig } from 'react-intl/src/types';
39-
import { AppState } from '../redux/reducer';
40+
import { AppState } from '../../redux/reducer';
4041

41-
const lightTheme: Theme = createTheme({
42+
const lightTheme: ThemeOptions = {
4243
palette: {
4344
mode: 'light',
4445
},
@@ -62,9 +63,9 @@ const lightTheme: Theme = createTheme({
6263
color: 'blue',
6364
},
6465
mapboxStyle: 'mapbox://styles/mapbox/light-v9',
65-
});
66+
};
6667

67-
const darkTheme: Theme = createTheme({
68+
const darkTheme: ThemeOptions = {
6869
palette: {
6970
mode: 'dark',
7071
},
@@ -88,14 +89,15 @@ const darkTheme: Theme = createTheme({
8889
color: 'green',
8990
},
9091
mapboxStyle: 'mapbox://styles/mapbox/dark-v9',
91-
});
92+
};
9293

93-
const getMuiTheme = (theme: string): Theme => {
94-
if (theme === LIGHT_THEME) {
95-
return lightTheme;
96-
} else {
97-
return darkTheme;
98-
}
94+
const getMuiTheme = (theme: unknown, locale: SupportedLanguages): Theme => {
95+
return responsiveFontSizes(
96+
createTheme(
97+
theme === LIGHT_THEME ? lightTheme : darkTheme,
98+
locale === LANG_FRENCH ? MuiCoreFrFR : MuiCoreEnUS // MUI core translations
99+
)
100+
);
99101
};
100102

101103
const messages: Record<SupportedLanguages, IntlConfig['messages']> = {
@@ -104,14 +106,12 @@ const messages: Record<SupportedLanguages, IntlConfig['messages']> = {
104106
...login_en,
105107
...top_bar_en,
106108
...card_error_boundary_en,
107-
...messages_plugins_en, // keep it at the end to allow translation overwriting
108109
},
109110
fr: {
110111
...messages_fr,
111112
...login_fr,
112113
...top_bar_fr,
113114
...card_error_boundary_fr,
114-
...messages_plugins_fr, // keep it at the end to allow translation overwriting
115115
},
116116
};
117117

@@ -122,14 +122,19 @@ const AppWrapperWithRedux: FunctionComponent = () => {
122122
(state: AppState) => state.computedLanguage
123123
);
124124
const theme = useSelector((state: AppState) => state[PARAM_THEME]);
125+
const themeCompiled = useMemo(
126+
() => getMuiTheme(theme, computedLanguage),
127+
[computedLanguage, theme]
128+
);
125129
return (
126130
<IntlProvider
127131
locale={computedLanguage}
132+
defaultLocale={LANG_ENGLISH}
128133
messages={messages[computedLanguage]}
129134
>
130135
<BrowserRouter basename={basename}>
131136
<StyledEngineProvider injectFirst>
132-
<ThemeProvider theme={getMuiTheme(theme)}>
137+
<ThemeProvider theme={themeCompiled}>
133138
<SnackbarProvider hideIconVariant={false}>
134139
<CssBaseline />
135140
<CardErrorBoundary>

src/components/app.test.tsx renamed to src/components/App/app.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IntlProvider } from 'react-intl';
77
import { Provider } from 'react-redux';
88
import { BrowserRouter } from 'react-router-dom';
99
import App from './app';
10-
import { store } from '../redux/store';
10+
import { store } from '../../redux/store';
1111
import {
1212
createTheme,
1313
StyledEngineProvider,

src/components/app.tsx renamed to src/components/App/app.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ import {
2828
selectComputedLanguage,
2929
selectLanguage,
3030
selectTheme,
31-
} from '../redux/actions';
32-
import { AppState } from '../redux/reducer';
31+
} from '../../redux/actions';
32+
import { AppState } from '../../redux/reducer';
3333
import {
3434
AppsMetadataSrv,
3535
ConfigNotif,
3636
ConfigParameters,
3737
ConfigSrv,
3838
UserAdminSrv,
39-
} from '../services';
39+
} from '../../services';
4040
import {
4141
APP_NAME,
4242
COMMON_APP_NAME,
4343
PARAM_LANGUAGE,
4444
PARAM_THEME,
45-
} from '../utils/config-params';
46-
import { getComputedLanguage } from '../utils/language';
45+
} from '../../utils/config-params';
46+
import { getComputedLanguage } from '../../utils/language';
4747
import AppTopBar, { AppTopBarProps } from './app-top-bar';
4848
import ReconnectingWebSocket from 'reconnecting-websocket';
49-
import { getErrorMessage } from '../utils/error';
49+
import { getErrorMessage } from '../../utils/error';
5050

5151
const App: FunctionComponent = () => {
5252
const { snackError } = useSnackMessage();
@@ -171,7 +171,7 @@ const App: FunctionComponent = () => {
171171
})
172172
);
173173

174-
ConfigSrv.fetchConfigParameters(APP_NAME.toLowerCase())
174+
ConfigSrv.fetchConfigParameters(APP_NAME)
175175
.then((params) => updateParams(params))
176176
.catch((error) =>
177177
snackError({

src/components/App/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as AppWrapper } from './app-wrapper';

src/components/app-top-bar.tsx

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)