Skip to content

Commit ef71b8b

Browse files
Remove old authentication flag and update fn call (#34) & Update commons-ui ts (#39)
Co-authored-by: Joris Mancini <[email protected]>
1 parent 3b5b707 commit ef71b8b

27 files changed

+354
-431
lines changed

jest.config.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ const config: Config = {
1313
'^.+\\.svg\\?react$': 'jest-svg-transformer',
1414
'^.+\\.(css|less|scss)$': 'identity-obj-proxy',
1515
},
16-
// if need to test with AG Grid, see https://www.ag-grid.com/react-data-grid/testing/
17-
transformIgnorePatterns: ['node_modules/(?!@gridsuite/commons-ui)'], // transform from ESM
18-
moduleDirectories: ['node_modules', 'src'], // to allow absolute path from ./src
16+
// see https://github.com/react-dnd/react-dnd/issues/3443
17+
transformIgnorePatterns: ['node_modules/(?!react-dnd)/'],
1918
setupFiles: ['<rootDir>/jest.setup.ts'],
2019
};
2120

jest.setup.ts

+1-1
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 { TextEncoder, TextDecoder } from 'util';
8+
import { TextEncoder, TextDecoder } from 'node:util';
99

1010
// fix for ReferenceError: TextDecoder / TextEncoder is not defined
1111
Object.assign(global, { TextDecoder, TextEncoder });

package-lock.json

+182-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.53.0",
19+
"@gridsuite/commons-ui": "0.63.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

+5-5
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,
@@ -28,14 +30,12 @@ import {
2830
top_bar_en,
2931
top_bar_fr,
3032
} from '@gridsuite/commons-ui';
31-
import { IntlProvider } from 'react-intl';
33+
import { IntlConfig, 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';
3738
import { PARAM_THEME } from '../../utils/config-params';
38-
import { IntlConfig } from 'react-intl/src/types';
3939
import { AppState } from '../../redux/reducer';
4040
import { AppWithAuthRouter } from '../../routes';
4141

@@ -91,7 +91,7 @@ const darkTheme: ThemeOptions = {
9191
agGridTheme: 'ag-theme-alpine-dark',
9292
};
9393

94-
const getMuiTheme = (theme: unknown, locale: SupportedLanguages): Theme => {
94+
const getMuiTheme = (theme: GsTheme, locale: GsLangUser): Theme => {
9595
return responsiveFontSizes(
9696
createTheme(
9797
theme === LIGHT_THEME ? lightTheme : darkTheme,
@@ -100,7 +100,7 @@ const getMuiTheme = (theme: unknown, locale: SupportedLanguages): Theme => {
100100
);
101101
};
102102

103-
const messages: Record<SupportedLanguages, IntlConfig['messages']> = {
103+
const messages: Record<GsLangUser, IntlConfig['messages']> = {
104104
en: {
105105
...messages_en,
106106
...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/custom-mui-dialog.tsx

-120
This file was deleted.

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

+2-10
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 { DirectorySrv } from '../../../services';
2116
import LinkedPathDisplay from './linked-path-display';
2217

2318
export interface ParameterSelectionProps {
@@ -50,7 +45,7 @@ const ParameterSelection: FunctionComponent<ParameterSelectionProps> = (
5045
setSelectedElementName(undefined);
5146
setParameterLinkValid(undefined);
5247
} else {
53-
fetchPath(watchParamId)
48+
DirectorySrv.fetchPath(watchParamId)
5449
.then((res: any) => {
5550
setParameterLinkValid(true);
5651
setSelectedElementName(
@@ -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/pages/profiles/modification/profile-modification-dialog.tsx

+15-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ProfileModificationForm, {
1010
PROFILE_NAME,
1111
USER_QUOTAS,
1212
} from './profile-modification-form';
13-
import yup from 'utils/yup-config';
13+
import yup from '../../../utils/yup-config';
1414
import { yupResolver } from '@hookform/resolvers/yup';
1515
import { useForm } from 'react-hook-form';
1616
import {
@@ -20,18 +20,17 @@ import {
2020
useMemo,
2121
useState,
2222
} from 'react';
23-
import { useSnackMessage } from '@gridsuite/commons-ui';
24-
import { getProfile, modifyProfile, UserProfile } from 'services/user-admin';
25-
import CustomMuiDialog from './custom-mui-dialog';
23+
import { CustomMuiDialog, useSnackMessage } from '@gridsuite/commons-ui';
24+
import { UserAdminSrv, UserProfile } from '../../../services';
2625
import { UUID } from 'crypto';
2726

28-
// TODO remove FetchStatus when available in commons-ui (available soon)
29-
export const FetchStatus = {
30-
IDLE: 'IDLE',
31-
FETCHING: 'FETCHING',
32-
FETCH_SUCCESS: 'FETCH_SUCCESS',
33-
FETCH_ERROR: 'FETCH_ERROR',
34-
};
27+
// TODO remove FetchStatus when exported in commons-ui (available soon)
28+
export enum FetchStatus {
29+
IDLE = 'IDLE',
30+
FETCHING = 'FETCHING',
31+
FETCH_SUCCESS = 'FETCH_SUCCESS',
32+
FETCH_ERROR = 'FETCH_ERROR',
33+
}
3534

3635
export interface ProfileModificationDialogProps {
3736
profileId: UUID | undefined;
@@ -44,7 +43,9 @@ const ProfileModificationDialog: FunctionComponent<
4443
ProfileModificationDialogProps
4544
> = ({ profileId, open, onClose, onUpdate }) => {
4645
const { snackError } = useSnackMessage();
47-
const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE);
46+
const [dataFetchStatus, setDataFetchStatus] = useState<FetchStatus>(
47+
FetchStatus.IDLE
48+
);
4849

4950
const formSchema = yup
5051
.object()
@@ -73,7 +74,7 @@ const ProfileModificationDialog: FunctionComponent<
7374
loadFlowParameterId: profileFormData[LF_PARAM_ID],
7475
maxAllowedCases: profileFormData[USER_QUOTAS],
7576
};
76-
modifyProfile(profileData)
77+
UserAdminSrv.modifyProfile(profileData)
7778
.catch((error) => {
7879
snackError({
7980
messageTxt: error.message,
@@ -96,7 +97,7 @@ const ProfileModificationDialog: FunctionComponent<
9697
useEffect(() => {
9798
if (profileId && open) {
9899
setDataFetchStatus(FetchStatus.FETCHING);
99-
getProfile(profileId)
100+
UserAdminSrv.getProfile(profileId)
100101
.then((response) => {
101102
setDataFetchStatus(FetchStatus.FETCH_SUCCESS);
102103
reset({

0 commit comments

Comments
 (0)