Skip to content

Commit 2256495

Browse files
go to new version
1 parent f53075b commit 2256495

File tree

9 files changed

+26
-23
lines changed

9 files changed

+26
-23
lines changed

package-lock.json

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@emotion/react": "^11.11.4",
1818
"@emotion/styled": "^11.11.5",
19-
"@gridsuite/commons-ui": "0.63.2",
19+
"@gridsuite/commons-ui": "file:../commons-ui/gridsuite-commons-ui-0.63.2.tgz",
2020
"@hookform/resolvers": "^3.3.4",
2121
"@mui/icons-material": "^5.15.14",
2222
"@mui/lab": "5.0.0-alpha.169",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from 'react';
1616
import { capitalize, Tab, Tabs, useTheme } from '@mui/material';
1717
import { ManageAccounts, PeopleAlt } from '@mui/icons-material';
18-
import { logout, TopBar } from '@gridsuite/commons-ui';
18+
import { AppMetadataCommon, logout, TopBar } from '@gridsuite/commons-ui';
1919
import { useParameterState } from '../parameters';
2020
import {
2121
APP_NAME,
@@ -25,7 +25,7 @@ import {
2525
import { NavLink, useMatches, useNavigate } from 'react-router-dom';
2626
import { useDispatch, useSelector } from 'react-redux';
2727
import { FormattedMessage } from 'react-intl';
28-
import { AppsMetadataSrv, MetadataJson, StudySrv } from '../../services';
28+
import { AppsMetadataSrv, StudySrv } from '../../services';
2929
import GridAdminLogoLight from '../../images/GridAdmin_logo_light.svg?react';
3030
import GridAdminLogoDark from '../../images/GridAdmin_logo_dark.svg?react';
3131
import AppPackage from '../../../package.json';
@@ -67,7 +67,7 @@ const tabs = new Map<MainPaths, ReactElement>([
6767
const AppTopBar: FunctionComponent = () => {
6868
const theme = useTheme();
6969
const dispatch = useDispatch<AppDispatch>();
70-
const user = useSelector((state: AppState) => state.user);
70+
const user = useSelector((state: AppState) => state.user ?? null);
7171
const userManagerInstance = useSelector(
7272
(state: AppState) => state.userManager?.instance
7373
);
@@ -87,7 +87,7 @@ const AppTopBar: FunctionComponent = () => {
8787
const [languageLocal, handleChangeLanguage] =
8888
useParameterState(PARAM_LANGUAGE);
8989

90-
const [appsAndUrls, setAppsAndUrls] = useState<MetadataJson[]>([]);
90+
const [appsAndUrls, setAppsAndUrls] = useState<AppMetadataCommon[]>([]);
9191
useEffect(() => {
9292
if (user !== null) {
9393
AppsMetadataSrv.fetchAppsAndUrls().then((res) => {

src/components/App/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
3737
useDebugRender('app');
3838
const { snackError } = useSnackMessage();
3939
const dispatch = useDispatch<AppDispatch>();
40-
const user = useSelector((state: AppState) => state.user);
40+
const user = useSelector((state: AppState) => state.user ?? null);
4141

4242
const updateParams = useCallback(
4343
(params: ConfigParameters) => {

src/redux/reducer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
AuthenticationActions,
3131
AuthenticationRouterErrorAction,
3232
AuthenticationRouterErrorState,
33-
CommonStoreState,
3433
GsLang,
3534
GsLangUser,
3635
GsTheme,
@@ -51,8 +50,10 @@ import {
5150
} from '@gridsuite/commons-ui';
5251
import { PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params';
5352
import { ReducerWithInitialState } from '@reduxjs/toolkit/dist/createReducer';
53+
import { User } from 'oidc-client';
5454

55-
export type AppState = CommonStoreState & {
55+
export type AppState = {
56+
user?: User;
5657
computedLanguage: GsLangUser;
5758
[PARAM_THEME]: GsTheme;
5859
[PARAM_LANGUAGE]: GsLang;
@@ -69,7 +70,7 @@ const initialState: AppState = {
6970
instance: null,
7071
error: null,
7172
},
72-
user: null,
73+
user: undefined,
7374
signInCallbackError: null,
7475
authenticationRouterError: null,
7576
showAuthenticationRouterLogin: false,

src/redux/store.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
import { legacy_createStore as createStore, Store } from 'redux';
99
import { Actions, AppState, reducer } from './reducer';
10-
import { setCommonStore } from '@gridsuite/commons-ui';
10+
import { initCommonServices } from '@gridsuite/commons-ui';
11+
import { APP_NAME } from '../utils/config-params';
1112

1213
export const store: Store<AppState, Actions> = createStore(reducer);
13-
setCommonStore(store);
14+
initCommonServices(APP_NAME, () => store.getState().user);
1415
export type AppDispatch = typeof store.dispatch;
1516

1617
// to avoid to reset the state with HMR

src/routes/router.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export const AppWithAuthRouter: FunctionComponent<{
176176
basename: string;
177177
layout: App;
178178
}> = (props, context) => {
179-
const user = useSelector((state: AppState) => state.user);
179+
const user = useSelector((state: AppState) => state.user ?? null);
180180
const router = useMemo(
181181
() =>
182182
createBrowserRouter(

src/services/apps-metadata.ts

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

8-
import { Env } from '@gridsuite/commons-ui';
8+
import { AppMetadata, Env } from '@gridsuite/commons-ui';
99
import { getErrorMessage } from '../utils/error';
1010
import { Url } from '../utils/api-rest';
1111

@@ -84,7 +84,7 @@ export type MetadataStudy = MetadataCommon & {
8484
// https://github.com/gridsuite/deployment/blob/main/k8s/resources/common/config/apps-metadata.json
8585
export type MetadataJson = MetadataCommon | MetadataStudy;
8686

87-
export function fetchAppsAndUrls(): Promise<MetadataJson[]> {
87+
export function fetchAppsAndUrls(): Promise<AppMetadata[]> {
8888
console.debug('Fetching apps and urls...');
8989
return fetchEnv()
9090
.then((env: EnvJson) =>

src/utils/api.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import { User } from 'oidc-client';
9-
import { AppState } from '../redux/reducer';
109
import { store } from '../redux/store';
1110

1211
export type Token = string;
@@ -16,8 +15,7 @@ export function getToken(user?: User): Token | null {
1615
}
1716

1817
export function getUser(): User | null {
19-
const state: AppState = store.getState();
20-
return state.user;
18+
return store.getState().user ?? null;
2119
}
2220

2321
export function extractUserSub(user: User | null): Promise<unknown> {

0 commit comments

Comments
 (0)