Skip to content

Commit 604e7d0

Browse files
Merge branch 'update-commons-ui' into remove-implicit-flow
2 parents b625887 + 5dd517b commit 604e7d0

21 files changed

+297
-221
lines changed

package-lock.json

+179-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
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.60.0",
19+
"@gridsuite/commons-ui": "0.62.0",
2020
"@hookform/resolvers": "^3.3.4",
2121
"@mui/icons-material": "^5.15.14",
2222
"@mui/lab": "5.0.0-alpha.169",
@@ -85,8 +85,8 @@
8585
"jest-environment-jsdom": "^29.7.0",
8686
"jest-svg-transformer": "^1.0.0",
8787
"prettier": "^2.8.8",
88-
"typescript": "5.1.6",
8988
"ts-node": "^10.9.2",
89+
"typescript": "5.1.6",
9090
"vite": "^5.2.7",
9191
"vite-plugin-eslint": "^1.8.1",
9292
"vite-plugin-svgr": "^4.2.0",

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import GridAdminLogoDark from '../../images/GridAdmin_logo_dark.svg?react';
3131
import AppPackage from '../../../package.json';
3232
import { AppState } from '../../redux/reducer';
3333
import { MainPaths } from '../../routes';
34+
import { AppDispatch } from '../../redux/store';
3435

3536
const tabs = new Map<MainPaths, ReactElement>([
3637
[
@@ -65,7 +66,7 @@ const tabs = new Map<MainPaths, ReactElement>([
6566

6667
const AppTopBar: FunctionComponent = () => {
6768
const theme = useTheme();
68-
const dispatch = useDispatch();
69+
const dispatch = useDispatch<AppDispatch>();
6970
const user = useSelector((state: AppState) => state.user);
7071
const userManagerInstance = useSelector(
7172
(state: AppState) => state.userManager?.instance
@@ -110,10 +111,12 @@ const AppTopBar: FunctionComponent = () => {
110111
appLicense={AppPackage.license}
111112
onLogoutClick={() => logout(dispatch, userManagerInstance)}
112113
onLogoClick={() => navigate('/', { replace: true })}
113-
user={user}
114+
user={user ?? undefined}
114115
appsAndUrls={appsAndUrls}
115116
globalVersionPromise={() =>
116-
AppsMetadataSrv.fetchVersion().then((res) => res?.deployVersion)
117+
AppsMetadataSrv.fetchVersion().then(
118+
(res) => res?.deployVersion ?? 'unknown'
119+
)
117120
}
118121
additionalModulesPromise={StudySrv.getServersInfos}
119122
onThemeClick={handleChangeTheme}

src/components/App/app-wrapper.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
card_error_boundary_en,
2020
card_error_boundary_fr,
2121
CardErrorBoundary,
22+
GsLangUser,
23+
GsTheme,
2224
LANG_ENGLISH,
2325
LANG_FRENCH,
2426
LIGHT_THEME,
@@ -30,7 +32,6 @@ import {
3032
} from '@gridsuite/commons-ui';
3133
import { IntlProvider } from 'react-intl';
3234
import { Provider, useSelector } from 'react-redux';
33-
import { SupportedLanguages } from '../../utils/language';
3435
import messages_en from '../../translations/en.json';
3536
import messages_fr from '../../translations/fr.json';
3637
import { store } from '../../redux/store';
@@ -91,7 +92,7 @@ const darkTheme: ThemeOptions = {
9192
agGridTheme: 'ag-theme-alpine-dark',
9293
};
9394

94-
const getMuiTheme = (theme: unknown, locale: SupportedLanguages): Theme => {
95+
const getMuiTheme = (theme: GsTheme, locale: GsLangUser): Theme => {
9596
return responsiveFontSizes(
9697
createTheme(
9798
theme === LIGHT_THEME ? lightTheme : darkTheme,
@@ -100,7 +101,7 @@ const getMuiTheme = (theme: unknown, locale: SupportedLanguages): Theme => {
100101
);
101102
};
102103

103-
const messages: Record<SupportedLanguages, IntlConfig['messages']> = {
104+
const messages: Record<GsLangUser, IntlConfig['messages']> = {
104105
en: {
105106
...messages_en,
106107
...login_en,

src/components/App/app.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ import { getComputedLanguage } from '../../utils/language';
3131
import AppTopBar from './app-top-bar';
3232
import ReconnectingWebSocket from 'reconnecting-websocket';
3333
import { useDebugRender } from '../../utils/hooks';
34+
import { AppDispatch } from '../../redux/store';
3435

3536
const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
3637
useDebugRender('app');
3738
const { snackError } = useSnackMessage();
38-
const dispatch = useDispatch();
39+
const dispatch = useDispatch<AppDispatch>();
3940
const user = useSelector((state: AppState) => state.user);
4041

4142
const updateParams = useCallback(

src/module-mui.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ declare module '@mui/material/styles/createTheme' {
2424
extends MuiThemeOptions,
2525
Partial<ThemeExtension> {}
2626
}
27+
28+
declare module '@mui/utils/capitalize' {
29+
export default function capitalize<S extends string>(
30+
string: S
31+
): Capitalize<S>;
32+
}

src/pages/profiles/modification/parameter-selection.tsx

+1-9
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ import { Grid, IconButton, Tooltip } from '@mui/material';
1212
import { useIntl } from 'react-intl';
1313
import { DirectoryItemSelector, ElementType } from '@gridsuite/commons-ui';
1414
import { useController, useWatch } from 'react-hook-form';
15-
import {
16-
fetchDirectoryContent,
17-
fetchPath,
18-
fetchRootFolders,
19-
} from 'services/directory';
20-
import { fetchElementsInfos } from 'services/explore';
15+
import { fetchPath } from 'services/directory';
2116
import LinkedPathDisplay from './linked-path-display';
2217

2318
export interface ParameterSelectionProps {
@@ -140,9 +135,6 @@ const ParameterSelection: FunctionComponent<ParameterSelectionProps> = (
140135
contentText={intl.formatMessage({
141136
id: 'profiles.form.modification.parameterSelection.dialog.message',
142137
})}
143-
fetchDirectoryContent={fetchDirectoryContent}
144-
fetchRootFolders={fetchRootFolders}
145-
fetchElementsInfos={fetchElementsInfos}
146138
/>
147139
</Grid>
148140
);

src/redux/actions.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8+
import { GsTheme, UserManagerState } from '@gridsuite/commons-ui';
89
import { PARAM_LANGUAGE } from '../utils/config-params';
910
import { Action } from 'redux';
1011
import { AppState } from './reducer';
11-
import { UserManagerState } from '../routes';
1212

1313
export const UPDATE_USER_MANAGER_STATE = 'UPDATE_USER_MANAGER_STATE';
1414
export type UserManagerAction = Readonly<
1515
Action<typeof UPDATE_USER_MANAGER_STATE>
1616
> & {
1717
userManager: UserManagerState;
1818
};
19+
1920
export function updateUserManager(
2021
userManager: UserManagerState
2122
): UserManagerAction {
2223
return { type: UPDATE_USER_MANAGER_STATE, userManager };
2324
}
25+
2426
export function updateUserManagerDestructured(
2527
instance: UserManagerState['instance'],
2628
error: UserManagerState['error']
@@ -32,6 +34,7 @@ export const UPDATE_USER_MANAGER_INSTANCE = 'UPDATE_USER_MANAGER_INSTANCE';
3234
export type UserManagerInstanceAction = Readonly<
3335
Action<typeof UPDATE_USER_MANAGER_INSTANCE>
3436
> & { instance: UserManagerState['instance'] };
37+
3538
export function updateUserManagerInstance(
3639
instance: UserManagerState['instance']
3740
): UserManagerInstanceAction {
@@ -42,6 +45,7 @@ export const UPDATE_USER_MANAGER_ERROR = 'UPDATE_USER_MANAGER_ERROR';
4245
export type UserManagerErrorAction = Readonly<
4346
Action<typeof UPDATE_USER_MANAGER_ERROR>
4447
> & { error: UserManagerState['error'] };
48+
4549
export function updateUserManagerError(
4650
error: UserManagerState['error']
4751
): UserManagerErrorAction {
@@ -50,16 +54,18 @@ export function updateUserManagerError(
5054

5155
export const SELECT_THEME = 'SELECT_THEME';
5256
export type ThemeAction = Readonly<Action<typeof SELECT_THEME>> & {
53-
theme: string;
57+
theme: GsTheme;
5458
};
55-
export function selectTheme(theme: string): ThemeAction {
59+
60+
export function selectTheme(theme: GsTheme): ThemeAction {
5661
return { type: SELECT_THEME, theme: theme };
5762
}
5863

5964
export const SELECT_LANGUAGE = 'SELECT_LANGUAGE';
6065
export type LanguageAction = Readonly<Action<typeof SELECT_LANGUAGE>> & {
6166
[PARAM_LANGUAGE]: AppState['language'];
6267
};
68+
6369
export function selectLanguage(language: AppState['language']): LanguageAction {
6470
return { type: SELECT_LANGUAGE, [PARAM_LANGUAGE]: language };
6571
}
@@ -70,6 +76,7 @@ export type ComputedLanguageAction = Readonly<
7076
> & {
7177
computedLanguage: AppState['computedLanguage'];
7278
};
79+
7380
export function selectComputedLanguage(
7481
computedLanguage: AppState['computedLanguage']
7582
): ComputedLanguageAction {

src/redux/local-storage.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,39 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { DARK_THEME, LANG_SYSTEM } from '@gridsuite/commons-ui';
8+
import {
9+
DARK_THEME,
10+
GsLang,
11+
GsTheme,
12+
LANG_SYSTEM,
13+
} from '@gridsuite/commons-ui';
914
import { getComputedLanguage } from '../utils/language';
1015
import { APP_NAME } from '../utils/config-params';
11-
import { AppState } from './reducer';
1216

1317
const LOCAL_STORAGE_THEME_KEY = (APP_NAME + '_THEME').toUpperCase();
1418
const LOCAL_STORAGE_LANGUAGE_KEY = (APP_NAME + '_LANGUAGE').toUpperCase();
1519

16-
export function getLocalStorageTheme(): string {
17-
return localStorage.getItem(LOCAL_STORAGE_THEME_KEY) || DARK_THEME;
20+
export function getLocalStorageTheme() {
21+
return (
22+
(localStorage.getItem(LOCAL_STORAGE_THEME_KEY) as GsTheme) || DARK_THEME
23+
);
1824
}
1925

20-
export function saveLocalStorageTheme(theme: string): void {
26+
export function saveLocalStorageTheme(theme: GsTheme): void {
2127
localStorage.setItem(LOCAL_STORAGE_THEME_KEY, theme);
2228
}
2329

24-
export function getLocalStorageLanguage(): AppState['language'] {
25-
return localStorage.getItem(LOCAL_STORAGE_LANGUAGE_KEY) || LANG_SYSTEM;
30+
export function getLocalStorageLanguage() {
31+
return (
32+
(localStorage.getItem(LOCAL_STORAGE_LANGUAGE_KEY) as GsLang) ||
33+
LANG_SYSTEM
34+
);
2635
}
2736

28-
export function saveLocalStorageLanguage(language: AppState['language']): void {
37+
export function saveLocalStorageLanguage(language: GsLang): void {
2938
localStorage.setItem(LOCAL_STORAGE_LANGUAGE_KEY, language);
3039
}
3140

32-
export function getLocalStorageComputedLanguage(): AppState['computedLanguage'] {
41+
export function getLocalStorageComputedLanguage() {
3342
return getComputedLanguage(getLocalStorageLanguage());
3443
}

src/redux/reducer.ts

+35-21
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 { AnyAction, createReducer, Draft } from '@reduxjs/toolkit';
9-
8+
import { createReducer, Draft } from '@reduxjs/toolkit';
109
import {
1110
getLocalStorageComputedLanguage,
1211
getLocalStorageLanguage,
@@ -27,31 +26,40 @@ import {
2726
UserManagerErrorAction,
2827
UserManagerInstanceAction,
2928
} from './actions';
30-
3129
import {
30+
AuthenticationActions,
31+
AuthenticationRouterErrorAction,
32+
AuthenticationRouterErrorState,
33+
CommonStoreState,
34+
GsLang,
35+
GsLangUser,
36+
GsTheme,
3237
LOGOUT_ERROR,
38+
LogoutErrorAction,
3339
RESET_AUTHENTICATION_ROUTER_ERROR,
3440
SHOW_AUTH_INFO_LOGIN,
41+
ShowAuthenticationRouterLoginAction,
3542
SIGNIN_CALLBACK_ERROR,
43+
SignInCallbackErrorAction,
3644
UNAUTHORIZED_USER_INFO,
45+
UnauthorizedUserAction,
3746
USER,
3847
USER_VALIDATION_ERROR,
48+
UserAction,
49+
UserManagerState,
50+
UserValidationErrorAction,
3951
} from '@gridsuite/commons-ui';
4052
import { PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params';
4153
import { ReducerWithInitialState } from '@reduxjs/toolkit/dist/createReducer';
42-
import { LanguageParameters, SupportedLanguages } from '../utils/language';
43-
import { User } from '../utils/auth';
44-
import { UserManagerState } from '../routes';
4554

46-
export type AppState = {
47-
computedLanguage: SupportedLanguages;
48-
[PARAM_THEME]: string;
49-
[PARAM_LANGUAGE]: LanguageParameters;
55+
export type AppState = CommonStoreState & {
56+
computedLanguage: GsLangUser;
57+
[PARAM_THEME]: GsTheme;
58+
[PARAM_LANGUAGE]: GsLang;
5059

5160
userManager: UserManagerState;
52-
user: User | null; //TODO delete when migrated into commons-ui
53-
signInCallbackError: unknown;
54-
authenticationRouterError: unknown;
61+
signInCallbackError: Error | null;
62+
authenticationRouterError: AuthenticationRouterErrorState | null;
5563
showAuthenticationRouterLogin: boolean;
5664
};
5765

@@ -73,7 +81,7 @@ const initialState: AppState = {
7381
};
7482

7583
export type Actions =
76-
| AnyAction
84+
| AuthenticationActions
7785
| UserManagerAction
7886
| UserManagerInstanceAction
7987
| UserManagerErrorAction
@@ -115,51 +123,57 @@ export const reducer: ReducerWithInitialState<AppState> = createReducer(
115123
}
116124
);
117125

118-
builder.addCase(USER, (state: Draft<AppState>, action: AnyAction) => {
126+
builder.addCase(USER, (state: Draft<AppState>, action: UserAction) => {
119127
state.user = action.user;
120128
});
121129

122130
builder.addCase(
123131
SIGNIN_CALLBACK_ERROR,
124-
(state: Draft<AppState>, action: AnyAction) => {
132+
(state: Draft<AppState>, action: SignInCallbackErrorAction) => {
125133
state.signInCallbackError = action.signInCallbackError;
126134
}
127135
);
128136

129137
builder.addCase(
130138
UNAUTHORIZED_USER_INFO,
131-
(state: Draft<AppState>, action: AnyAction) => {
139+
(state: Draft<AppState>, action: UnauthorizedUserAction) => {
132140
state.authenticationRouterError =
133141
action.authenticationRouterError;
134142
}
135143
);
136144

137145
builder.addCase(
138146
LOGOUT_ERROR,
139-
(state: Draft<AppState>, action: AnyAction) => {
147+
(state: Draft<AppState>, action: LogoutErrorAction) => {
140148
state.authenticationRouterError =
141149
action.authenticationRouterError;
142150
}
143151
);
144152

145153
builder.addCase(
146154
USER_VALIDATION_ERROR,
147-
(state: Draft<AppState>, action: AnyAction) => {
155+
(state: Draft<AppState>, action: UserValidationErrorAction) => {
148156
state.authenticationRouterError =
149157
action.authenticationRouterError;
150158
}
151159
);
152160

153161
builder.addCase(
154162
RESET_AUTHENTICATION_ROUTER_ERROR,
155-
(state: Draft<AppState>, action: AnyAction) => {
163+
(
164+
state: Draft<AppState>,
165+
action: AuthenticationRouterErrorAction
166+
) => {
156167
state.authenticationRouterError = null;
157168
}
158169
);
159170

160171
builder.addCase(
161172
SHOW_AUTH_INFO_LOGIN,
162-
(state: Draft<AppState>, action: AnyAction) => {
173+
(
174+
state: Draft<AppState>,
175+
action: ShowAuthenticationRouterLoginAction
176+
) => {
163177
state.showAuthenticationRouterLogin =
164178
action.showAuthenticationRouterLogin;
165179
}

src/redux/store.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { createStore, Store } from 'redux';
99
import { Actions, AppState, reducer } from './reducer';
1010

1111
export const store: Store<AppState, Actions> = createStore(reducer);
12+
export type AppDispatch = typeof store.dispatch;
1213

1314
// to avoid to reset the state with HMR
1415
// https://redux.js.org/usage/configuring-your-store#hot-reloading

0 commit comments

Comments
 (0)