Skip to content

Commit 0f321bf

Browse files
Apply latest template
Use TypeScript template instead
1 parent 6ea54b5 commit 0f321bf

25 files changed

+717
-502
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# GridXXX-App
22

3-
Template app that bootstraps the creation of gridsuite apps.
4-
The template setup the authentication mechanism and provide a configured empty application.
3+
Template app that bootstraps the creation of GridSuite apps.
4+
This template setup the authentication mechanism and provides a configured empty application.
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

88
## Typescript config
99

1010
Files tsconfig.json and src/react-app-env.d.ts both results from create-react-app typescript template (version 5).
11-
Some property values have been changed to meet the project needs (ex: target, baseUrl,...).
11+
Some property values have been changed to meet the project needs (ex: target, baseUrl, ...).

package-lock.json

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

package.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"license": "MPL-2.0",
55
"homepage": ".",
66
"private": true,
7+
"engines": {
8+
"node": ">=18",
9+
"npm": "^10.2.0"
10+
},
711
"dependencies": {
812
"@emotion/react": "^11.8.2",
913
"@emotion/styled": "^11.8.1",
@@ -13,9 +17,12 @@
1317
"@mui/lab": "^5.0.0-alpha.75",
1418
"@mui/material": "^5.5.3",
1519
"@reduxjs/toolkit": "^1.2.3",
16-
"@types/node": "^20.2.5",
20+
"@types/core-js": "^2.5.8",
21+
"@types/node": "^18.19.3",
22+
"@types/prop-types": "^15.7.11",
1723
"@types/react": "^18.2.9",
1824
"@types/react-dom": "^18.2.4",
25+
"@types/react-window": "^1.8.8",
1926
"core-js": "^3.6.4",
2027
"notistack": "^3.0.0",
2128
"prop-types": "^15.7.2",
@@ -36,13 +43,18 @@
3643
"scripts": {
3744
"start": "react-scripts start",
3845
"build": "react-scripts build",
39-
"test": "react-scripts test --watchAll=false --transformIgnorePatterns \"node_modules/(?!@gridsuite/commons-ui)/\"",
46+
"test": "react-scripts test --watchAll=false",
47+
"test:watch": "react-scripts test",
48+
"test:coverage": "react-scripts test --coverage",
4049
"eject": "react-scripts eject"
4150
},
4251
"jest": {
4352
"moduleNameMapper": {
4453
"\\.svg": "<rootDir>/src/__mocks__/svgrMock.js"
45-
}
54+
},
55+
"transformIgnorePatterns": [
56+
"node_modules/(?!@gridsuite/commons-ui)/"
57+
]
4658
},
4759
"eslintConfig": {
4860
"extends": [
@@ -67,6 +79,10 @@
6779
]
6880
},
6981
"devDependencies": {
82+
"@types/eslint-config-prettier": "^6.11.3",
83+
"@types/eslint-plugin-prettier": "^3.1.3",
84+
"@types/jest": "^27.5.1",
85+
"@types/prettier": "^2.0.2",
7086
"eslint-config-prettier": "^8.0.0",
7187
"eslint-plugin-prettier": "^4.0.0",
7288
"http-proxy-middleware": "^2.0.0",

src/components/app-top-bar.js renamed to src/components/app-top-bar.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,37 @@
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
*/
7-
import React, { useEffect, useState } from 'react';
7+
8+
import React, { FunctionComponent, useEffect, useState } from 'react';
89
import { LIGHT_THEME, logout, TopBar } from '@gridsuite/commons-ui';
910
import Parameters, { useParameterState } from './parameters';
1011
import { APP_NAME, PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params';
1112
import { useDispatch, useSelector } from 'react-redux';
1213
import { fetchAppsAndUrls, fetchVersion } from '../utils/rest-api';
1314
import { getServersInfos } from '../rest/study';
14-
import PropTypes from 'prop-types';
1515
import { useNavigate } from 'react-router-dom';
1616
import { ReactComponent as PowsyblLogo } from '../images/powsybl_logo.svg';
1717
import AppPackage from '../../package.json';
18+
import { AppState } from '../redux/reducer';
19+
import { UserManager } from 'oidc-client';
1820

19-
const AppTopBar = ({ user, userManager }) => {
21+
export type AppTopBarProps = {
22+
user?: AppState['user'];
23+
userManager: {
24+
instance: UserManager | null;
25+
error: string | null;
26+
};
27+
};
28+
const AppTopBar: FunctionComponent<AppTopBarProps> = (props) => {
2029
const navigate = useNavigate();
2130

2231
const dispatch = useDispatch();
2332

24-
const [appsAndUrls, setAppsAndUrls] = useState([]);
33+
const [appsAndUrls, setAppsAndUrls] = useState<
34+
Awaited<ReturnType<typeof fetchAppsAndUrls>>
35+
>([]);
2536

26-
const theme = useSelector((state) => state[PARAM_THEME]);
37+
const theme = useSelector((state: AppState) => state[PARAM_THEME]);
2738

2839
const [themeLocal, handleChangeTheme] = useParameterState(PARAM_THEME);
2940

@@ -33,12 +44,12 @@ const AppTopBar = ({ user, userManager }) => {
3344
const [showParameters, setShowParameters] = useState(false);
3445

3546
useEffect(() => {
36-
if (user !== null) {
47+
if (props.user !== null) {
3748
fetchAppsAndUrls().then((res) => {
3849
setAppsAndUrls(res);
3950
});
4051
}
41-
}, [user]);
52+
}, [props.user]);
4253

4354
return (
4455
<>
@@ -55,9 +66,11 @@ const AppTopBar = ({ user, userManager }) => {
5566
appVersion={AppPackage.version}
5667
appLicense={AppPackage.license}
5768
onParametersClick={() => setShowParameters(true)}
58-
onLogoutClick={() => logout(dispatch, userManager.instance)}
59-
onLogoClick={() => navigate.replace('/')}
60-
user={user}
69+
onLogoutClick={() =>
70+
logout(dispatch, props.userManager.instance)
71+
}
72+
onLogoClick={() => navigate('/', { replace: true })}
73+
user={props.user}
6174
appsAndUrls={appsAndUrls}
6275
globalVersionPromise={() =>
6376
fetchVersion().then((res) => res?.deployVersion)
@@ -75,10 +88,4 @@ const AppTopBar = ({ user, userManager }) => {
7588
</>
7689
);
7790
};
78-
79-
AppTopBar.propTypes = {
80-
user: PropTypes.object,
81-
userManager: PropTypes.object.isRequired,
82-
};
83-
8491
export default AppTopBar;

0 commit comments

Comments
 (0)