5
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- import React , {
9
- FunctionComponent ,
10
- useCallback ,
11
- useEffect ,
12
- useState ,
13
- } from 'react' ;
8
+ import React , { FunctionComponent , useCallback , useEffect , useState } from 'react' ;
14
9
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' ;
23
11
import { FormattedMessage } from 'react-intl' ;
24
12
import { Box , Typography } from '@mui/material' ;
25
13
import {
@@ -30,11 +18,7 @@ import {
30
18
initializeAuthenticationProd ,
31
19
useSnackMessage ,
32
20
} from '@gridsuite/commons-ui' ;
33
- import {
34
- selectComputedLanguage ,
35
- selectLanguage ,
36
- selectTheme ,
37
- } from '../redux/actions' ;
21
+ import { selectComputedLanguage , selectLanguage , selectTheme } from '../redux/actions' ;
38
22
import { AppState } from '../redux/reducer' ;
39
23
import {
40
24
ConfigParameters ,
@@ -44,12 +28,7 @@ import {
44
28
fetchIdpSettings ,
45
29
fetchValidateUser ,
46
30
} 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' ;
53
32
import { getComputedLanguage } from '../utils/language' ;
54
33
import AppTopBar , { AppTopBarProps } from './app-top-bar' ;
55
34
import ReconnectingWebSocket from 'reconnecting-websocket' ;
@@ -61,19 +40,11 @@ const App: FunctionComponent = () => {
61
40
62
41
const user = useSelector ( ( state : AppState ) => state . user ) ;
63
42
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 ) ;
73
46
74
- const [ userManager , setUserManager ] = useState <
75
- AppTopBarProps [ 'userManager' ]
76
- > ( { instance : null , error : null } ) ;
47
+ const [ userManager , setUserManager ] = useState < AppTopBarProps [ 'userManager' ] > ( { instance : null , error : null } ) ;
77
48
78
49
const navigate = useNavigate ( ) ;
79
50
@@ -91,11 +62,7 @@ const App: FunctionComponent = () => {
91
62
break ;
92
63
case PARAM_LANGUAGE :
93
64
dispatch ( selectLanguage ( param . value ) ) ;
94
- dispatch (
95
- selectComputedLanguage (
96
- getComputedLanguage ( param . value )
97
- )
98
- ) ;
65
+ dispatch ( selectComputedLanguage ( getComputedLanguage ( param . value ) ) ) ;
99
66
break ;
100
67
default :
101
68
break ;
@@ -105,27 +72,26 @@ const App: FunctionComponent = () => {
105
72
[ dispatch ]
106
73
) ;
107
74
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 ] ) ;
129
95
130
96
// Can't use lazy initializer because useMatch is a hook
131
97
const [ initialMatchSilentRenewCallbackUrl ] = useState (
@@ -144,9 +110,7 @@ const App: FunctionComponent = () => {
144
110
// need subfunction when async as suggested by rule react-hooks/exhaustive-deps
145
111
( async function initializeAuthentication ( ) {
146
112
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 } ` ) ;
150
114
const initAuth =
151
115
process . env . REACT_APP_USE_AUTHENTICATION === 'true'
152
116
? initializeAuthenticationProd (
@@ -174,11 +138,7 @@ const App: FunctionComponent = () => {
174
138
}
175
139
} ) ( ) ;
176
140
// Note: dispatch and initialMatchSilentRenewCallbackUrl won't change
177
- } , [
178
- initialMatchSigninCallbackUrl ,
179
- initialMatchSilentRenewCallbackUrl ,
180
- dispatch ,
181
- ] ) ;
141
+ } , [ initialMatchSigninCallbackUrl , initialMatchSilentRenewCallbackUrl , dispatch ] ) ;
182
142
183
143
useEffect ( ( ) => {
184
144
if ( user !== null ) {
@@ -203,13 +163,7 @@ const App: FunctionComponent = () => {
203
163
const ws = connectNotificationsUpdateConfig ( ) ;
204
164
return ( ) => ws . close ( ) ;
205
165
}
206
- } , [
207
- user ,
208
- dispatch ,
209
- updateParams ,
210
- snackError ,
211
- connectNotificationsUpdateConfig ,
212
- ] ) ;
166
+ } , [ user , dispatch , updateParams , snackError , connectNotificationsUpdateConfig ] ) ;
213
167
214
168
return (
215
169
< >
@@ -221,33 +175,16 @@ const App: FunctionComponent = () => {
221
175
path = "/"
222
176
element = {
223
177
< Box mt = { 20 } >
224
- < Typography
225
- variant = "h3"
226
- color = "textPrimary"
227
- align = "center"
228
- >
178
+ < Typography variant = "h3" color = "textPrimary" align = "center" >
229
179
Connected
230
180
</ Typography >
231
181
</ Box >
232
182
}
233
183
/>
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 ( ) || '/' } /> } />
243
185
< Route
244
186
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 > }
251
188
/>
252
189
< Route
253
190
path = "*"
@@ -263,9 +200,7 @@ const App: FunctionComponent = () => {
263
200
userManager = { userManager }
264
201
signInCallbackError = { signInCallbackError }
265
202
authenticationRouterError = { authenticationRouterError }
266
- showAuthenticationRouterLogin = {
267
- showAuthenticationRouterLogin
268
- }
203
+ showAuthenticationRouterLogin = { showAuthenticationRouterLogin }
269
204
dispatch = { dispatch }
270
205
navigate = { navigate }
271
206
location = { location }
@@ -278,7 +213,5 @@ const App: FunctionComponent = () => {
278
213
export default App ;
279
214
280
215
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 ) ) ;
284
217
}
0 commit comments