Skip to content

Commit b77ab9d

Browse files
migrate to new arch
1 parent ba6affb commit b77ab9d

19 files changed

+169
-509
lines changed

.env.development

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
REACT_APP_USE_AUTHENTICATION=false
2-
3-
REACT_APP_SRV_STUDY_URI=study-server

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This template setup the authentication mechanism and provides a configured empty
55

66
To customize this repository for an app, search and replace the string `XXX` with the name of the app. For example, GridXXX -> GridFoo, gridXXX-app -> gridfoo-app.
77

8-
Create a new view in study-server and replace `yyy` with the new token in rest api `src/rest/study.ts`.
8+
Create a new view in study-server and replace `yyy` with the new token in rest api `src/services/index.ts`.
99

1010
## Typescript config
1111

src/components/app-top-bar.tsx

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@ import React, {
1111
useEffect,
1212
useState,
1313
} from 'react';
14-
import {
15-
AppMetadataCommon,
16-
LIGHT_THEME,
17-
logout,
18-
TopBar,
19-
UserManagerState,
20-
} from '@gridsuite/commons-ui';
2114
import Parameters, { useParameterState } from './parameters';
22-
import { APP_NAME, PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params';
15+
import { APP_NAME } from '../utils/config-params';
2316
import { useDispatch, useSelector } from 'react-redux';
24-
import { fetchAppsAndUrls, fetchVersion } from '../utils/rest-api';
25-
import { getServersInfos } from '../rest/study';
17+
import { appsMetadataSrv, studySrv } from '../services';
2618
import { useNavigate } from 'react-router-dom';
2719
import { ReactComponent as PowsyblLogo } from '../images/powsybl_logo.svg';
2820
import AppPackage from '../../package.json';
2921
import { AppState } from '../redux/reducer';
3022
import { AppDispatch } from '../redux/store';
23+
import {
24+
AppMetadataCommon,
25+
LIGHT_THEME,
26+
logout,
27+
PARAM_LANGUAGE,
28+
PARAM_THEME,
29+
TopBar,
30+
UserManagerState,
31+
} from '@gridsuite/commons-ui';
3132

3233
export type AppTopBarProps = {
3334
user?: AppState['user'];
@@ -50,14 +51,29 @@ const AppTopBar: FunctionComponent<AppTopBarProps> = (props) => {
5051
const [showParameters, setShowParameters] = useState(false);
5152
const displayParameters = useCallback(() => setShowParameters(true), []);
5253
const hideParameters = useCallback(() => setShowParameters(false), []);
54+
const onLogoutClick = useCallback(
55+
() => logout(dispatch, props.userManager.instance),
56+
[dispatch, props.userManager.instance]
57+
);
5358

5459
useEffect(() => {
5560
if (props.user !== undefined) {
56-
fetchAppsAndUrls().then((res) => {
61+
appsMetadataSrv.fetchAppsMetadata().then((res) => {
5762
setAppsAndUrls(res);
5863
});
5964
}
6065
}, [props.user]);
66+
const globalVersionFetcher = useCallback(
67+
() =>
68+
appsMetadataSrv
69+
.fetchVersion()
70+
.then((res) => res?.deployVersion ?? 'unknown'),
71+
[]
72+
);
73+
const additionalModulesFetcher = useCallback(
74+
() => studySrv.getServersInfos('yyy'),
75+
[]
76+
);
6177

6278
return (
6379
<>
@@ -74,18 +90,12 @@ const AppTopBar: FunctionComponent<AppTopBarProps> = (props) => {
7490
appVersion={AppPackage.version}
7591
appLicense={AppPackage.license}
7692
onParametersClick={displayParameters}
77-
onLogoutClick={() =>
78-
logout(dispatch, props.userManager.instance)
79-
}
93+
onLogoutClick={onLogoutClick}
8094
onLogoClick={() => navigate('/', { replace: true })}
8195
user={props.user}
8296
appsAndUrls={appsAndUrls}
83-
globalVersionPromise={() =>
84-
fetchVersion().then(
85-
(res) => res?.deployVersion ?? 'unknown'
86-
)
87-
}
88-
additionalModulesPromise={getServersInfos}
97+
globalVersionPromise={globalVersionFetcher}
98+
additionalModulesPromise={additionalModulesFetcher}
8999
onThemeClick={handleChangeTheme}
90100
theme={themeLocal}
91101
onLanguageClick={handleChangeLanguage}

src/components/app-wrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
LIGHT_THEME,
2323
login_en,
2424
login_fr,
25+
PARAM_THEME,
2526
SnackbarProvider,
2627
top_bar_en,
2728
top_bar_fr,
@@ -34,7 +35,6 @@ import messages_fr from '../translations/fr.json';
3435
import messages_plugins_en from '../plugins/translations/en.json';
3536
import messages_plugins_fr from '../plugins/translations/fr.json';
3637
import { store } from '../redux/store';
37-
import { PARAM_THEME } from '../utils/config-params';
3838
import { IntlConfig } from 'react-intl/src/types';
3939
import { AppState } from '../redux/reducer';
4040

src/components/app.tsx

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ import { Box, Typography } from '@mui/material';
2525
import {
2626
AuthenticationRouter,
2727
CardErrorBoundary,
28+
COMMON_APP_NAME,
29+
ConfigParameters,
30+
getComputedLanguage,
31+
getErrorMessage,
2832
getPreLoginPath,
2933
initializeAuthenticationDev,
3034
initializeAuthenticationProd,
35+
PARAM_LANGUAGE,
36+
PARAM_THEME,
3137
useSnackMessage,
3238
} from '@gridsuite/commons-ui';
3339
import {
@@ -37,23 +43,14 @@ import {
3743
} from '../redux/actions';
3844
import { AppState } from '../redux/reducer';
3945
import {
40-
ConfigParameters,
41-
connectNotificationsWsUpdateConfig,
42-
fetchConfigParameter,
43-
fetchConfigParameters,
44-
fetchIdpSettings,
45-
fetchValidateUser,
46-
} from '../utils/rest-api';
47-
import {
48-
APP_NAME,
49-
COMMON_APP_NAME,
50-
PARAM_LANGUAGE,
51-
PARAM_THEME,
52-
} from '../utils/config-params';
53-
import { getComputedLanguage } from '../utils/language';
46+
appLocalSrv,
47+
configNotificationSrv,
48+
configSrv,
49+
userAdminSrv,
50+
} from '../services';
51+
import { APP_NAME } from '../utils/config-params';
5452
import AppTopBar, { AppTopBarProps } from './app-top-bar';
5553
import ReconnectingWebSocket from 'reconnecting-websocket';
56-
import { getErrorMessage } from '../utils/error';
5754
import { AppDispatch } from '../redux/store';
5855

5956
const App: FunctionComponent = () => {
@@ -107,11 +104,15 @@ const App: FunctionComponent = () => {
107104

108105
const connectNotificationsUpdateConfig =
109106
useCallback((): ReconnectingWebSocket => {
110-
const ws = connectNotificationsWsUpdateConfig();
107+
const ws =
108+
configNotificationSrv.connectNotificationsWsUpdateConfig(
109+
APP_NAME
110+
);
111111
ws.onmessage = function (event) {
112112
let eventData = JSON.parse(event.data);
113113
if (eventData.headers?.parameterName) {
114-
fetchConfigParameter(eventData.headers.parameterName)
114+
configSrv
115+
.fetchConfigParameter(eventData.headers.parameterName)
115116
.then((param) => updateParams([param]))
116117
.catch((error) =>
117118
snackError({
@@ -152,8 +153,8 @@ const App: FunctionComponent = () => {
152153
? initializeAuthenticationProd(
153154
dispatch,
154155
initialMatchSilentRenewCallbackUrl != null,
155-
fetchIdpSettings,
156-
fetchValidateUser,
156+
appLocalSrv.fetchIdpSettings,
157+
userAdminSrv.fetchValidateUser,
157158
initialMatchSigninCallbackUrl != null
158159
)
159160
: initializeAuthenticationDev(
@@ -182,7 +183,8 @@ const App: FunctionComponent = () => {
182183

183184
useEffect(() => {
184185
if (user !== undefined) {
185-
fetchConfigParameters(COMMON_APP_NAME)
186+
configSrv
187+
.fetchConfigParameters(COMMON_APP_NAME)
186188
.then((params) => updateParams(params))
187189
.catch((error) =>
188190
snackError({
@@ -191,7 +193,8 @@ const App: FunctionComponent = () => {
191193
})
192194
);
193195

194-
fetchConfigParameters(APP_NAME)
196+
configSrv
197+
.fetchConfigParameters(APP_NAME)
195198
.then((params) => updateParams(params))
196199
.catch((error) =>
197200
snackError({

src/components/parameters.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
TypographyTypeMap,
3030
} from '@mui/material';
3131
import { CSSObject, Theme } from '@emotion/react';
32-
import { updateConfigParameter } from '../utils/rest-api';
32+
import { configSrv } from '../services';
3333
import { useSnackMessage } from '@gridsuite/commons-ui';
3434
import { AppState, AppStateKey } from '../redux/reducer';
3535

@@ -62,7 +62,8 @@ export function useParameterState<K extends AppStateKey>(
6262
const handleChangeParamLocalState = useCallback(
6363
(value: AppState[K]) => {
6464
setParamLocalState(value);
65-
updateConfigParameter(paramName, value as string) //TODO how to check/cast?
65+
configSrv
66+
.updateConfigParameter(paramName, value as string) //TODO how to check/cast?
6667
.catch((error) => {
6768
setParamLocalState(paramGlobalState);
6869
snackError({

src/react-app-env.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
/**
2-
* Copyright (c) 2024, RTE (http://www.rte-france.com)
1+
/*
2+
* Copyright © 2024, RTE (http://www.rte-france.com)
33
* This Source Code Form is subject to the terms of the Mozilla Public
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

88
/// <reference types="react-scripts" />
99

10-
import { UrlString } from '@gridsuite/commons-ui';
11-
1210
type EnvDev = {
1311
REACT_APP_USE_AUTHENTICATION: true;
1412
REACT_APP_SRV_STUDY_URI: string;

src/redux/actions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { GsTheme } from '@gridsuite/commons-ui';
9-
import { PARAM_LANGUAGE } from '../utils/config-params';
8+
import { GsTheme, PARAM_LANGUAGE } from '@gridsuite/commons-ui';
109
import { Action } from 'redux';
1110
import { AppState } from './reducer';
1211

src/redux/local-storage.ts

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

src/redux/reducer.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
*/
77

88
import { createReducer, Draft } from '@reduxjs/toolkit';
9-
import {
10-
getLocalStorageComputedLanguage,
11-
getLocalStorageLanguage,
12-
getLocalStorageTheme,
13-
saveLocalStorageTheme,
14-
} from './local-storage';
159
import {
1610
ComputedLanguageAction,
1711
LanguageAction,
@@ -23,12 +17,18 @@ import {
2317
AuthenticationActions,
2418
AuthenticationRouterErrorAction,
2519
AuthenticationRouterErrorState,
20+
getLocalStorageComputedLanguage,
21+
getLocalStorageLanguage,
22+
getLocalStorageTheme,
2623
GsLang,
2724
GsLangUser,
2825
GsTheme,
2926
LOGOUT_ERROR,
3027
LogoutErrorAction,
28+
PARAM_LANGUAGE,
29+
PARAM_THEME,
3130
RESET_AUTHENTICATION_ROUTER_ERROR,
31+
saveLocalStorageTheme,
3232
SHOW_AUTH_INFO_LOGIN,
3333
ShowAuthenticationRouterLoginAction,
3434
SIGNIN_CALLBACK_ERROR,
@@ -40,9 +40,9 @@ import {
4040
UserAction,
4141
UserValidationErrorAction,
4242
} from '@gridsuite/commons-ui';
43-
import { PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params';
4443
import { ReducerWithInitialState } from '@reduxjs/toolkit/dist/createReducer';
4544
import { User } from 'oidc-client';
45+
import { APP_NAME } from '../utils/config-params';
4646

4747
export type AppState = {
4848
user: User | undefined;
@@ -63,9 +63,9 @@ const initialState: AppState = {
6363
showAuthenticationRouterLogin: false,
6464

6565
// params
66-
[PARAM_THEME]: getLocalStorageTheme(),
67-
[PARAM_LANGUAGE]: getLocalStorageLanguage(),
68-
computedLanguage: getLocalStorageComputedLanguage(),
66+
[PARAM_THEME]: getLocalStorageTheme(APP_NAME),
67+
[PARAM_LANGUAGE]: getLocalStorageLanguage(APP_NAME),
68+
computedLanguage: getLocalStorageComputedLanguage(APP_NAME),
6969
};
7070

7171
export type Actions =
@@ -83,7 +83,7 @@ export const reducer: ReducerWithInitialState<AppState> = createReducer(
8383
SELECT_THEME,
8484
(state: Draft<AppState>, action: ThemeAction) => {
8585
state.theme = action.theme;
86-
saveLocalStorageTheme(state.theme);
86+
saveLocalStorageTheme(APP_NAME, state.theme);
8787
}
8888
);
8989

0 commit comments

Comments
 (0)