Skip to content

Commit

Permalink
set print width to 120 instead of default 80.
Browse files Browse the repository at this point in the history
refresh from main

Signed-off-by: Tristan Chuine <[email protected]>
  • Loading branch information
Tristan-WorkGH committed Aug 5, 2024
1 parent b95795d commit 3c0caa5
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 401 deletions.
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"printWidth": 120,
"singleQuote": true
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This template setup the authentication mechanism and provides a configured empty

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.

Create a new view in study-server and replace `yyy` with the new token in rest api `src/rest/study.ts`.
Create a new view in study-server and replace `yyy` with the new token in rest api `src/rest/study.ts`.

## Typescript config

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

Notes :
Notes :
* Check [license-checker-config.json](license-checker-config.json) for license white list and exclusion.
If you need to update this list, please inform organization's owners.
* Excluded dependencies :
Expand Down
2 changes: 1 addition & 1 deletion license-checker-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"onlyAllow" : [
"onlyAllow": [
"MPL-2.0",
"MIT",
"BSD-3-Clause",
Expand Down
4 changes: 1 addition & 3 deletions src/__mocks__/svgrMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

import React from 'react';

const SvgrMock = React.forwardRef((props, ref) => (
<span ref={ref} {...props} />
));
const SvgrMock = React.forwardRef((props, ref) => <span ref={ref} {...props} />);

export const ReactComponent = SvgrMock;
export default SvgrMock;
38 changes: 7 additions & 31 deletions src/components/app-top-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import React, {
FunctionComponent,
useCallback,
useEffect,
useState,
} from 'react';
import {
LIGHT_THEME,
logout,
TopBar,
UserManagerState,
} from '@gridsuite/commons-ui';
import React, { FunctionComponent, useCallback, useEffect, useState } from 'react';
import { LIGHT_THEME, logout, TopBar, UserManagerState } from '@gridsuite/commons-ui';
import Parameters, { useParameterState } from './parameters';
import { APP_NAME, PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params';
import { useDispatch, useSelector } from 'react-redux';
import {
fetchAppsAndUrls,
fetchVersion,
MetadataJson,
} from '../utils/rest-api';
import { fetchAppsAndUrls, fetchVersion, MetadataJson } from '../utils/rest-api';
import { getServersInfos } from '../rest/study';
import { useNavigate } from 'react-router-dom';
import { ReactComponent as PowsyblLogo } from '../images/powsybl_logo.svg';
Expand All @@ -47,8 +33,7 @@ const AppTopBar: FunctionComponent<AppTopBarProps> = (props) => {

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

const [languageLocal, handleChangeLanguage] =
useParameterState(PARAM_LANGUAGE);
const [languageLocal, handleChangeLanguage] = useParameterState(PARAM_LANGUAGE);

const [showParameters, setShowParameters] = useState(false);
const displayParameters = useCallback(() => setShowParameters(true), []);
Expand Down Expand Up @@ -77,27 +62,18 @@ const AppTopBar: FunctionComponent<AppTopBarProps> = (props) => {
appVersion={AppPackage.version}
appLicense={AppPackage.license}
onParametersClick={displayParameters}
onLogoutClick={() =>
logout(dispatch, props.userManager.instance)
}
onLogoutClick={() => logout(dispatch, props.userManager.instance)}
onLogoClick={() => navigate('/', { replace: true })}
user={props.user ?? undefined}
appsAndUrls={appsAndUrls}
globalVersionPromise={() =>
fetchVersion().then(
(res) => res?.deployVersion ?? 'unknown'
)
}
globalVersionPromise={() => fetchVersion().then((res) => res?.deployVersion ?? 'unknown')}
additionalModulesPromise={getServersInfos}
onThemeClick={handleChangeTheme}
theme={themeLocal}
onLanguageClick={handleChangeLanguage}
language={languageLocal}
/>
<Parameters
showParameters={showParameters}
hideParameters={hideParameters}
/>
<Parameters showParameters={showParameters} hideParameters={hideParameters} />
</>
);
};
Expand Down
16 changes: 3 additions & 13 deletions src/components/app-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
import App from './app';
import React, { FunctionComponent } from 'react';
import { CssBaseline } from '@mui/material';
import {
createTheme,
StyledEngineProvider,
Theme,
ThemeProvider,
} from '@mui/material/styles';
import { createTheme, StyledEngineProvider, Theme, ThemeProvider } from '@mui/material/styles';
import {
card_error_boundary_en,
card_error_boundary_fr,
Expand Down Expand Up @@ -118,15 +113,10 @@ const messages: Record<GsLangUser, IntlConfig['messages']> = {
const basename = new URL(document.querySelector('base')?.href ?? '').pathname;

const AppWrapperWithRedux: FunctionComponent = () => {
const computedLanguage = useSelector(
(state: AppState) => state.computedLanguage
);
const computedLanguage = useSelector((state: AppState) => state.computedLanguage);
const theme = useSelector((state: AppState) => state[PARAM_THEME]);
return (
<IntlProvider
locale={computedLanguage}
messages={messages[computedLanguage]}
>
<IntlProvider locale={computedLanguage} messages={messages[computedLanguage]}>
<BrowserRouter basename={basename}>
<StyledEngineProvider injectFirst>
<ThemeProvider theme={getMuiTheme(theme)}>
Expand Down
6 changes: 1 addition & 5 deletions src/components/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import App from './app';
import { store } from '../redux/store';
import {
createTheme,
StyledEngineProvider,
ThemeProvider,
} from '@mui/material/styles';
import { createTheme, StyledEngineProvider, ThemeProvider } from '@mui/material/styles';
import { SnackbarProvider } from '@gridsuite/commons-ui';
import { CssBaseline } from '@mui/material';

Expand Down
141 changes: 37 additions & 104 deletions src/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import React, {
FunctionComponent,
useCallback,
useEffect,
useState,
} from 'react';
import React, { FunctionComponent, useCallback, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
Navigate,
Route,
Routes,
useLocation,
useMatch,
useNavigate,
} from 'react-router-dom';
import { Navigate, Route, Routes, useLocation, useMatch, useNavigate } from 'react-router-dom';
import { FormattedMessage } from 'react-intl';
import { Box, Typography } from '@mui/material';
import {
Expand All @@ -30,11 +18,7 @@ import {
initializeAuthenticationProd,
useSnackMessage,
} from '@gridsuite/commons-ui';
import {
selectComputedLanguage,
selectLanguage,
selectTheme,
} from '../redux/actions';
import { selectComputedLanguage, selectLanguage, selectTheme } from '../redux/actions';
import { AppState } from '../redux/reducer';
import {
ConfigParameters,
Expand All @@ -44,12 +28,7 @@ import {
fetchIdpSettings,
fetchValidateUser,
} from '../utils/rest-api';
import {
APP_NAME,
COMMON_APP_NAME,
PARAM_LANGUAGE,
PARAM_THEME,
} from '../utils/config-params';
import { APP_NAME, COMMON_APP_NAME, PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params';
import { getComputedLanguage } from '../utils/language';
import AppTopBar, { AppTopBarProps } from './app-top-bar';
import ReconnectingWebSocket from 'reconnecting-websocket';
Expand All @@ -61,19 +40,11 @@ const App: FunctionComponent = () => {

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

const signInCallbackError = useSelector(
(state: AppState) => state.signInCallbackError
);
const authenticationRouterError = useSelector(
(state: AppState) => state.authenticationRouterError
);
const showAuthenticationRouterLogin = useSelector(
(state: AppState) => state.showAuthenticationRouterLogin
);
const signInCallbackError = useSelector((state: AppState) => state.signInCallbackError);
const authenticationRouterError = useSelector((state: AppState) => state.authenticationRouterError);
const showAuthenticationRouterLogin = useSelector((state: AppState) => state.showAuthenticationRouterLogin);

const [userManager, setUserManager] = useState<
AppTopBarProps['userManager']
>({ instance: null, error: null });
const [userManager, setUserManager] = useState<AppTopBarProps['userManager']>({ instance: null, error: null });

const navigate = useNavigate();

Expand All @@ -91,11 +62,7 @@ const App: FunctionComponent = () => {
break;
case PARAM_LANGUAGE:
dispatch(selectLanguage(param.value));
dispatch(
selectComputedLanguage(
getComputedLanguage(param.value)
)
);
dispatch(selectComputedLanguage(getComputedLanguage(param.value)));
break;
default:
break;
Expand All @@ -105,27 +72,26 @@ const App: FunctionComponent = () => {
[dispatch]
);

const connectNotificationsUpdateConfig =
useCallback((): ReconnectingWebSocket => {
const ws = connectNotificationsWsUpdateConfig();
ws.onmessage = function (event) {
let eventData = JSON.parse(event.data);
if (eventData.headers?.parameterName) {
fetchConfigParameter(eventData.headers.parameterName)
.then((param) => updateParams([param]))
.catch((error) =>
snackError({
messageTxt: error.message,
headerId: 'paramsRetrievingError',
})
);
}
};
ws.onerror = function (event) {
console.error('Unexpected Notification WebSocket error', event);
};
return ws;
}, [updateParams, snackError]);
const connectNotificationsUpdateConfig = useCallback((): ReconnectingWebSocket => {
const ws = connectNotificationsWsUpdateConfig();
ws.onmessage = function (event) {
let eventData = JSON.parse(event.data);
if (eventData.headers?.parameterName) {
fetchConfigParameter(eventData.headers.parameterName)
.then((param) => updateParams([param]))
.catch((error) =>
snackError({
messageTxt: error.message,
headerId: 'paramsRetrievingError',
})
);
}
};
ws.onerror = function (event) {
console.error('Unexpected Notification WebSocket error', event);
};
return ws;
}, [updateParams, snackError]);

// Can't use lazy initializer because useMatch is a hook
const [initialMatchSilentRenewCallbackUrl] = useState(
Expand All @@ -144,9 +110,7 @@ const App: FunctionComponent = () => {
// need subfunction when async as suggested by rule react-hooks/exhaustive-deps
(async function initializeAuthentication() {
try {
console.debug(
`auth dev mode: ${process.env.REACT_APP_USE_AUTHENTICATION}`
);
console.debug(`auth dev mode: ${process.env.REACT_APP_USE_AUTHENTICATION}`);
const initAuth =
process.env.REACT_APP_USE_AUTHENTICATION === 'true'
? initializeAuthenticationProd(
Expand Down Expand Up @@ -174,11 +138,7 @@ const App: FunctionComponent = () => {
}
})();
// Note: dispatch and initialMatchSilentRenewCallbackUrl won't change
}, [
initialMatchSigninCallbackUrl,
initialMatchSilentRenewCallbackUrl,
dispatch,
]);
}, [initialMatchSigninCallbackUrl, initialMatchSilentRenewCallbackUrl, dispatch]);

useEffect(() => {
if (user !== null) {
Expand All @@ -203,13 +163,7 @@ const App: FunctionComponent = () => {
const ws = connectNotificationsUpdateConfig();
return () => ws.close();
}
}, [
user,
dispatch,
updateParams,
snackError,
connectNotificationsUpdateConfig,
]);
}, [user, dispatch, updateParams, snackError, connectNotificationsUpdateConfig]);

return (
<>
Expand All @@ -221,33 +175,16 @@ const App: FunctionComponent = () => {
path="/"
element={
<Box mt={20}>
<Typography
variant="h3"
color="textPrimary"
align="center"
>
<Typography variant="h3" color="textPrimary" align="center">
Connected
</Typography>
</Box>
}
/>
<Route
path="/sign-in-callback"
element={
<Navigate
replace
to={getPreLoginPath() || '/'}
/>
}
/>
<Route path="/sign-in-callback" element={<Navigate replace to={getPreLoginPath() || '/'} />} />
<Route
path="/logout-callback"
element={
<h1>
Error: logout failed; you are still logged
in.
</h1>
}
element={<h1>Error: logout failed; you are still logged in.</h1>}
/>
<Route
path="*"
Expand All @@ -263,9 +200,7 @@ const App: FunctionComponent = () => {
userManager={userManager}
signInCallbackError={signInCallbackError}
authenticationRouterError={authenticationRouterError}
showAuthenticationRouterLogin={
showAuthenticationRouterLogin
}
showAuthenticationRouterLogin={showAuthenticationRouterLogin}
dispatch={dispatch}
navigate={navigate}
location={location}
Expand All @@ -278,7 +213,5 @@ const App: FunctionComponent = () => {
export default App;

function validateUserDev(): Promise<boolean> {
return new Promise((resolve) =>
window.setTimeout(() => resolve(true), 500)
);
return new Promise((resolve) => window.setTimeout(() => resolve(true), 500));
}
Loading

0 comments on commit 3c0caa5

Please sign in to comment.