Skip to content

Commit 72c3cfa

Browse files
authored
set print width to 120 instead of default 80. (#79)
1 parent b95795d commit 72c3cfa

21 files changed

+142
-401
lines changed

.prettierrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"trailingComma": "es5",
33
"tabWidth": 4,
4+
"printWidth": 120,
45
"singleQuote": true
56
}

README.md

+2-2
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/rest/study.ts`.
99

1010
## Typescript config
1111

@@ -20,7 +20,7 @@ To check dependencies license compatibility with this project one locally, pleas
2020
npm run licenses-check
2121
```
2222

23-
Notes :
23+
Notes :
2424
* Check [license-checker-config.json](license-checker-config.json) for license white list and exclusion.
2525
If you need to update this list, please inform organization's owners.
2626
* Excluded dependencies :

license-checker-config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"onlyAllow" : [
2+
"onlyAllow": [
33
"MPL-2.0",
44
"MIT",
55
"BSD-3-Clause",

src/__mocks__/svgrMock.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
import React from 'react';
99

10-
const SvgrMock = React.forwardRef((props, ref) => (
11-
<span ref={ref} {...props} />
12-
));
10+
const SvgrMock = React.forwardRef((props, ref) => <span ref={ref} {...props} />);
1311

1412
export const ReactComponent = SvgrMock;
1513
export default SvgrMock;

src/components/app-top-bar.tsx

+7-31
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,12 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import React, {
9-
FunctionComponent,
10-
useCallback,
11-
useEffect,
12-
useState,
13-
} from 'react';
14-
import {
15-
LIGHT_THEME,
16-
logout,
17-
TopBar,
18-
UserManagerState,
19-
} from '@gridsuite/commons-ui';
8+
import React, { FunctionComponent, useCallback, useEffect, useState } from 'react';
9+
import { LIGHT_THEME, logout, TopBar, UserManagerState } from '@gridsuite/commons-ui';
2010
import Parameters, { useParameterState } from './parameters';
2111
import { APP_NAME, PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params';
2212
import { useDispatch, useSelector } from 'react-redux';
23-
import {
24-
fetchAppsAndUrls,
25-
fetchVersion,
26-
MetadataJson,
27-
} from '../utils/rest-api';
13+
import { fetchAppsAndUrls, fetchVersion, MetadataJson } from '../utils/rest-api';
2814
import { getServersInfos } from '../rest/study';
2915
import { useNavigate } from 'react-router-dom';
3016
import { ReactComponent as PowsyblLogo } from '../images/powsybl_logo.svg';
@@ -47,8 +33,7 @@ const AppTopBar: FunctionComponent<AppTopBarProps> = (props) => {
4733

4834
const [themeLocal, handleChangeTheme] = useParameterState(PARAM_THEME);
4935

50-
const [languageLocal, handleChangeLanguage] =
51-
useParameterState(PARAM_LANGUAGE);
36+
const [languageLocal, handleChangeLanguage] = useParameterState(PARAM_LANGUAGE);
5237

5338
const [showParameters, setShowParameters] = useState(false);
5439
const displayParameters = useCallback(() => setShowParameters(true), []);
@@ -77,27 +62,18 @@ const AppTopBar: FunctionComponent<AppTopBarProps> = (props) => {
7762
appVersion={AppPackage.version}
7863
appLicense={AppPackage.license}
7964
onParametersClick={displayParameters}
80-
onLogoutClick={() =>
81-
logout(dispatch, props.userManager.instance)
82-
}
65+
onLogoutClick={() => logout(dispatch, props.userManager.instance)}
8366
onLogoClick={() => navigate('/', { replace: true })}
8467
user={props.user ?? undefined}
8568
appsAndUrls={appsAndUrls}
86-
globalVersionPromise={() =>
87-
fetchVersion().then(
88-
(res) => res?.deployVersion ?? 'unknown'
89-
)
90-
}
69+
globalVersionPromise={() => fetchVersion().then((res) => res?.deployVersion ?? 'unknown')}
9170
additionalModulesPromise={getServersInfos}
9271
onThemeClick={handleChangeTheme}
9372
theme={themeLocal}
9473
onLanguageClick={handleChangeLanguage}
9574
language={languageLocal}
9675
/>
97-
<Parameters
98-
showParameters={showParameters}
99-
hideParameters={hideParameters}
100-
/>
76+
<Parameters showParameters={showParameters} hideParameters={hideParameters} />
10177
</>
10278
);
10379
};

src/components/app-wrapper.tsx

+3-13
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
import App from './app';
99
import React, { FunctionComponent } from 'react';
1010
import { CssBaseline } from '@mui/material';
11-
import {
12-
createTheme,
13-
StyledEngineProvider,
14-
Theme,
15-
ThemeProvider,
16-
} from '@mui/material/styles';
11+
import { createTheme, StyledEngineProvider, Theme, ThemeProvider } from '@mui/material/styles';
1712
import {
1813
card_error_boundary_en,
1914
card_error_boundary_fr,
@@ -118,15 +113,10 @@ const messages: Record<GsLangUser, IntlConfig['messages']> = {
118113
const basename = new URL(document.querySelector('base')?.href ?? '').pathname;
119114

120115
const AppWrapperWithRedux: FunctionComponent = () => {
121-
const computedLanguage = useSelector(
122-
(state: AppState) => state.computedLanguage
123-
);
116+
const computedLanguage = useSelector((state: AppState) => state.computedLanguage);
124117
const theme = useSelector((state: AppState) => state[PARAM_THEME]);
125118
return (
126-
<IntlProvider
127-
locale={computedLanguage}
128-
messages={messages[computedLanguage]}
129-
>
119+
<IntlProvider locale={computedLanguage} messages={messages[computedLanguage]}>
130120
<BrowserRouter basename={basename}>
131121
<StyledEngineProvider injectFirst>
132122
<ThemeProvider theme={getMuiTheme(theme)}>

src/components/app.test.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ import { Provider } from 'react-redux';
1515
import { BrowserRouter } from 'react-router-dom';
1616
import App from './app';
1717
import { store } from '../redux/store';
18-
import {
19-
createTheme,
20-
StyledEngineProvider,
21-
ThemeProvider,
22-
} from '@mui/material/styles';
18+
import { createTheme, StyledEngineProvider, ThemeProvider } from '@mui/material/styles';
2319
import { SnackbarProvider } from '@gridsuite/commons-ui';
2420
import { CssBaseline } from '@mui/material';
2521

src/components/app.tsx

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

8-
import React, {
9-
FunctionComponent,
10-
useCallback,
11-
useEffect,
12-
useState,
13-
} from 'react';
8+
import React, { FunctionComponent, useCallback, useEffect, useState } from 'react';
149
import { useDispatch, useSelector } from 'react-redux';
15-
import {
16-
Navigate,
17-
Route,
18-
Routes,
19-
useLocation,
20-
useMatch,
21-
useNavigate,
22-
} from 'react-router-dom';
10+
import { Navigate, Route, Routes, useLocation, useMatch, useNavigate } from 'react-router-dom';
2311
import { FormattedMessage } from 'react-intl';
2412
import { Box, Typography } from '@mui/material';
2513
import {
@@ -30,11 +18,7 @@ import {
3018
initializeAuthenticationProd,
3119
useSnackMessage,
3220
} from '@gridsuite/commons-ui';
33-
import {
34-
selectComputedLanguage,
35-
selectLanguage,
36-
selectTheme,
37-
} from '../redux/actions';
21+
import { selectComputedLanguage, selectLanguage, selectTheme } from '../redux/actions';
3822
import { AppState } from '../redux/reducer';
3923
import {
4024
ConfigParameters,
@@ -44,12 +28,7 @@ import {
4428
fetchIdpSettings,
4529
fetchValidateUser,
4630
} from '../utils/rest-api';
47-
import {
48-
APP_NAME,
49-
COMMON_APP_NAME,
50-
PARAM_LANGUAGE,
51-
PARAM_THEME,
52-
} from '../utils/config-params';
31+
import { APP_NAME, COMMON_APP_NAME, PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params';
5332
import { getComputedLanguage } from '../utils/language';
5433
import AppTopBar, { AppTopBarProps } from './app-top-bar';
5534
import ReconnectingWebSocket from 'reconnecting-websocket';
@@ -61,19 +40,11 @@ const App: FunctionComponent = () => {
6140

6241
const user = useSelector((state: AppState) => state.user);
6342

64-
const signInCallbackError = useSelector(
65-
(state: AppState) => state.signInCallbackError
66-
);
67-
const authenticationRouterError = useSelector(
68-
(state: AppState) => state.authenticationRouterError
69-
);
70-
const showAuthenticationRouterLogin = useSelector(
71-
(state: AppState) => state.showAuthenticationRouterLogin
72-
);
43+
const signInCallbackError = useSelector((state: AppState) => state.signInCallbackError);
44+
const authenticationRouterError = useSelector((state: AppState) => state.authenticationRouterError);
45+
const showAuthenticationRouterLogin = useSelector((state: AppState) => state.showAuthenticationRouterLogin);
7346

74-
const [userManager, setUserManager] = useState<
75-
AppTopBarProps['userManager']
76-
>({ instance: null, error: null });
47+
const [userManager, setUserManager] = useState<AppTopBarProps['userManager']>({ instance: null, error: null });
7748

7849
const navigate = useNavigate();
7950

@@ -91,11 +62,7 @@ const App: FunctionComponent = () => {
9162
break;
9263
case PARAM_LANGUAGE:
9364
dispatch(selectLanguage(param.value));
94-
dispatch(
95-
selectComputedLanguage(
96-
getComputedLanguage(param.value)
97-
)
98-
);
65+
dispatch(selectComputedLanguage(getComputedLanguage(param.value)));
9966
break;
10067
default:
10168
break;
@@ -105,27 +72,26 @@ const App: FunctionComponent = () => {
10572
[dispatch]
10673
);
10774

108-
const connectNotificationsUpdateConfig =
109-
useCallback((): ReconnectingWebSocket => {
110-
const ws = connectNotificationsWsUpdateConfig();
111-
ws.onmessage = function (event) {
112-
let eventData = JSON.parse(event.data);
113-
if (eventData.headers?.parameterName) {
114-
fetchConfigParameter(eventData.headers.parameterName)
115-
.then((param) => updateParams([param]))
116-
.catch((error) =>
117-
snackError({
118-
messageTxt: error.message,
119-
headerId: 'paramsRetrievingError',
120-
})
121-
);
122-
}
123-
};
124-
ws.onerror = function (event) {
125-
console.error('Unexpected Notification WebSocket error', event);
126-
};
127-
return ws;
128-
}, [updateParams, snackError]);
75+
const connectNotificationsUpdateConfig = useCallback((): ReconnectingWebSocket => {
76+
const ws = connectNotificationsWsUpdateConfig();
77+
ws.onmessage = function (event) {
78+
let eventData = JSON.parse(event.data);
79+
if (eventData.headers?.parameterName) {
80+
fetchConfigParameter(eventData.headers.parameterName)
81+
.then((param) => updateParams([param]))
82+
.catch((error) =>
83+
snackError({
84+
messageTxt: error.message,
85+
headerId: 'paramsRetrievingError',
86+
})
87+
);
88+
}
89+
};
90+
ws.onerror = function (event) {
91+
console.error('Unexpected Notification WebSocket error', event);
92+
};
93+
return ws;
94+
}, [updateParams, snackError]);
12995

13096
// Can't use lazy initializer because useMatch is a hook
13197
const [initialMatchSilentRenewCallbackUrl] = useState(
@@ -144,9 +110,7 @@ const App: FunctionComponent = () => {
144110
// need subfunction when async as suggested by rule react-hooks/exhaustive-deps
145111
(async function initializeAuthentication() {
146112
try {
147-
console.debug(
148-
`auth dev mode: ${process.env.REACT_APP_USE_AUTHENTICATION}`
149-
);
113+
console.debug(`auth dev mode: ${process.env.REACT_APP_USE_AUTHENTICATION}`);
150114
const initAuth =
151115
process.env.REACT_APP_USE_AUTHENTICATION === 'true'
152116
? initializeAuthenticationProd(
@@ -174,11 +138,7 @@ const App: FunctionComponent = () => {
174138
}
175139
})();
176140
// Note: dispatch and initialMatchSilentRenewCallbackUrl won't change
177-
}, [
178-
initialMatchSigninCallbackUrl,
179-
initialMatchSilentRenewCallbackUrl,
180-
dispatch,
181-
]);
141+
}, [initialMatchSigninCallbackUrl, initialMatchSilentRenewCallbackUrl, dispatch]);
182142

183143
useEffect(() => {
184144
if (user !== null) {
@@ -203,13 +163,7 @@ const App: FunctionComponent = () => {
203163
const ws = connectNotificationsUpdateConfig();
204164
return () => ws.close();
205165
}
206-
}, [
207-
user,
208-
dispatch,
209-
updateParams,
210-
snackError,
211-
connectNotificationsUpdateConfig,
212-
]);
166+
}, [user, dispatch, updateParams, snackError, connectNotificationsUpdateConfig]);
213167

214168
return (
215169
<>
@@ -221,33 +175,16 @@ const App: FunctionComponent = () => {
221175
path="/"
222176
element={
223177
<Box mt={20}>
224-
<Typography
225-
variant="h3"
226-
color="textPrimary"
227-
align="center"
228-
>
178+
<Typography variant="h3" color="textPrimary" align="center">
229179
Connected
230180
</Typography>
231181
</Box>
232182
}
233183
/>
234-
<Route
235-
path="/sign-in-callback"
236-
element={
237-
<Navigate
238-
replace
239-
to={getPreLoginPath() || '/'}
240-
/>
241-
}
242-
/>
184+
<Route path="/sign-in-callback" element={<Navigate replace to={getPreLoginPath() || '/'} />} />
243185
<Route
244186
path="/logout-callback"
245-
element={
246-
<h1>
247-
Error: logout failed; you are still logged
248-
in.
249-
</h1>
250-
}
187+
element={<h1>Error: logout failed; you are still logged in.</h1>}
251188
/>
252189
<Route
253190
path="*"
@@ -263,9 +200,7 @@ const App: FunctionComponent = () => {
263200
userManager={userManager}
264201
signInCallbackError={signInCallbackError}
265202
authenticationRouterError={authenticationRouterError}
266-
showAuthenticationRouterLogin={
267-
showAuthenticationRouterLogin
268-
}
203+
showAuthenticationRouterLogin={showAuthenticationRouterLogin}
269204
dispatch={dispatch}
270205
navigate={navigate}
271206
location={location}
@@ -278,7 +213,5 @@ const App: FunctionComponent = () => {
278213
export default App;
279214

280215
function validateUserDev(): Promise<boolean> {
281-
return new Promise((resolve) =>
282-
window.setTimeout(() => resolve(true), 500)
283-
);
216+
return new Promise((resolve) => window.setTimeout(() => resolve(true), 500));
284217
}

0 commit comments

Comments
 (0)