@@ -84,11 +84,12 @@ type AppIndexProps = {
84
84
getIsCommonSettingFetched : boolean ;
85
85
currentOrgId ?: string ;
86
86
currentUserId : string ;
87
+ currentUserAnonymous : boolean ;
87
88
orgDev : boolean ;
88
89
defaultHomePage : string | null | undefined ;
89
90
fetchHomeDataFinished : boolean ;
90
91
fetchConfig : ( orgId ?: string ) => void ;
91
- fetchHomeData : ( ) => void ;
92
+ fetchHomeData : ( currentUserAnonymous ?: boolean | undefined ) => void ;
92
93
getCurrentUser : ( ) => void ;
93
94
favicon : string ;
94
95
brandName : string ;
@@ -98,7 +99,9 @@ type AppIndexProps = {
98
99
class AppIndex extends React . Component < AppIndexProps , any > {
99
100
componentDidMount ( ) {
100
101
this . props . getCurrentUser ( ) ;
101
- this . props . fetchHomeData ( ) ;
102
+ if ( ! this . props . currentUserAnonymous ) {
103
+ this . props . fetchHomeData ( this . props . currentUserAnonymous ) ;
104
+ }
102
105
}
103
106
104
107
componentDidUpdate ( prevProps : AppIndexProps ) {
@@ -107,7 +110,9 @@ class AppIndex extends React.Component<AppIndexProps, any> {
107
110
this . props . currentOrgId !== ''
108
111
) {
109
112
this . props . fetchConfig ( this . props . currentOrgId ) ;
110
- this . props . fetchHomeData ( ) ;
113
+ if ( ! this . props . currentUserAnonymous ) {
114
+ this . props . fetchHomeData ( this . props . currentUserAnonymous ) ;
115
+ }
111
116
}
112
117
}
113
118
render ( ) {
@@ -123,7 +128,7 @@ class AppIndex extends React.Component<AppIndexProps, any> {
123
128
}
124
129
125
130
// make sure all users in this app have checked login info
126
- if ( ! this . props . isFetchUserFinished || ( this . props . currentUserId && ! this . props . fetchHomeDataFinished ) ) {
131
+ if ( ! this . props . isFetchUserFinished ) { // || (this.props.currentUserId && !this.props.fetchHomeDataFinished)
127
132
const hideLoadingHeader = isTemplate || isAuthUnRequired ( pathname ) ;
128
133
return < ProductLoading hideHeader = { hideLoadingHeader } /> ;
129
134
}
@@ -280,16 +285,6 @@ class AppIndex extends React.Component<AppIndexProps, any> {
280
285
< SystemWarning />
281
286
< Router history = { history } >
282
287
< Switch >
283
- { this . props . isFetchUserFinished && this . props . defaultHomePage ? (
284
- ! this . props . orgDev ? (
285
- < Redirect exact from = { BASE_URL } to = { APPLICATION_VIEW_URL ( this . props . defaultHomePage || "" , "view" ) } />
286
- ) : (
287
- < Redirect exact from = { BASE_URL } to = { ORG_HOME_URL } />
288
- )
289
- ) : (
290
- < Redirect exact from = { BASE_URL } to = { ALL_APPLICATIONS_URL } />
291
- ) }
292
-
293
288
< LazyRoute
294
289
exact
295
290
path = { IMPORT_APP_FROM_TEMPLATE_URL }
@@ -351,7 +346,19 @@ class AppIndex extends React.Component<AppIndexProps, any> {
351
346
path = { `/playground/:name/:dsl` }
352
347
component = { LazyComponentPlayground }
353
348
/>
349
+
350
+ { this . props . isFetchUserFinished && this . props . defaultHomePage ? (
351
+ ! this . props . orgDev ? (
352
+ < Redirect exact from = { BASE_URL } to = { APPLICATION_VIEW_URL ( this . props . defaultHomePage || "" , "view" ) } />
353
+ ) : (
354
+ < Redirect exact from = { BASE_URL } to = { ORG_HOME_URL } />
355
+ )
356
+ ) : (
357
+ < Redirect exact from = { BASE_URL } to = { ALL_APPLICATIONS_URL } />
358
+ ) }
359
+
354
360
< Redirect to = { `${ COMPONENT_DOC_URL } /input` } path = "/components" />
361
+
355
362
{ developEnv ( ) && (
356
363
< >
357
364
< LazyRoute
@@ -379,6 +386,7 @@ const mapStateToProps = (state: AppState) => ({
379
386
getIsCommonSettingFetched : getIsCommonSettingFetched ( state ) ,
380
387
orgDev : state . ui . users . user . orgDev ,
381
388
currentUserId : state . ui . users . currentUser . id ,
389
+ currentUserAnonymous : state . ui . users . currentUser . name === "ANONYMOUS" ,
382
390
currentOrgId : state . ui . users . user . currentOrgId ,
383
391
defaultHomePage : state . ui . application . homeOrg ?. commonSettings . defaultHomePage ,
384
392
fetchHomeDataFinished : Boolean ( state . ui . application . homeOrg ?. commonSettings ) ,
@@ -394,7 +402,15 @@ const mapDispatchToProps = (dispatch: any) => ({
394
402
dispatch ( fetchUserAction ( ) ) ;
395
403
} ,
396
404
fetchConfig : ( orgId ?: string ) => dispatch ( fetchConfigAction ( orgId ) ) ,
397
- fetchHomeData : ( ) => dispatch ( fetchHomeData ( { } ) )
405
+ fetchHomeData : ( currentUserAnonymous : boolean | undefined ) => {
406
+ // the rule should be that if the user is not logged in and if he want to view an App, we should not fetch the home data
407
+ if ( window . location . pathname == APP_EDITOR_URL && ! currentUserAnonymous && ! currentUserAnonymous === undefined ) {
408
+ dispatch ( fetchHomeData ( { } ) ) ;
409
+ }
410
+ else {
411
+ dispatch ( fetchHomeData ( { } ) ) ;
412
+ }
413
+ }
398
414
} ) ;
399
415
400
416
const AppIndexWithProps = connect ( mapStateToProps , mapDispatchToProps ) ( AppIndex ) ;
0 commit comments