@@ -8,23 +8,15 @@ import {
88 FederatedComponentProps ,
99 SolutionUI ,
1010} from '@scality/module-federation' ;
11- import React , {
12- useEffect ,
13- useLayoutEffect ,
14- useMemo ,
15- useTransition ,
16- useRef ,
17- useState ,
18- } from 'react' ;
11+ import React , { useEffect , useMemo } from 'react' ;
1912import { ErrorBoundary } from 'react-error-boundary' ;
2013import { QueryClient } from 'react-query' ;
21- import { BrowserRouter , Route , Routes , useLocation } from 'react-router' ;
14+ import { BrowserRouter , Route , Routes } from 'react-router' ;
2215
2316import { loadShare } from '@module-federation/enhanced/runtime' ;
2417import { useQuery } from 'react-query' ;
25- import NotificationCenterProvider from './NotificationCenterProvider' ;
2618import { AuthConfigProvider , useAuthConfig } from './auth/AuthConfigProvider' ;
27- import { AuthProvider , useAuth } from './auth/AuthProvider' ;
19+ import { AuthProvider } from './auth/AuthProvider' ;
2820import { FirstTimeLoginProvider } from './auth/FirstTimeLoginProvider' ;
2921import {
3022 ShellAlerts ,
@@ -35,9 +27,8 @@ import {
3527import './index.css' ;
3628import {
3729 ConfigurationProvider ,
38- FederatedView ,
3930 useConfigRetriever ,
40- useDiscoveredViews ,
31+ useFederatedRoutes ,
4132} from './initFederation/ConfigurationProviders' ;
4233import {
4334 ShellConfigProvider ,
@@ -48,6 +39,7 @@ import { ShellThemeSelectorProvider } from './initFederation/ShellThemeSelectorP
4839import { UIListProvider } from './initFederation/UIListProvider' ;
4940import { SolutionsNavbar } from './navbar' ;
5041import { LanguageProvider , useLanguage } from './navbar/lang' ;
42+ import NotificationCenterProvider from './NotificationCenterProvider' ;
5143import { QueryClientProvider } from './QueryClientProvider' ;
5244
5345/**
@@ -73,19 +65,14 @@ export type FederatedAppProps = {
7365 shellAlerts : ShellAlerts ;
7466} ;
7567
76- function FederatedRoute ( {
77- url,
78- scope,
79- module,
80- app,
81- groups,
82- } : FederatedComponentProps & {
83- groups ?: string [ ] ;
68+ type FederatedRouteProps = Pick < FederatedComponentProps , 'scope' | 'module' > & {
8469 app : SolutionUI ;
85- } ) {
70+ } ;
71+ function FederatedRoute ( { scope, module, app } : FederatedRouteProps ) {
8672 const { retrieveConfiguration } = useConfigRetriever ( ) ;
8773 const { setAuthConfig } = useAuthConfig ( ) ;
8874 const { language } = useLanguage ( ) ;
75+
8976 useEffect ( ( ) => {
9077 const runtimeAppConfig = retrieveConfiguration < Record < string , unknown > > ( {
9178 configType : 'run' ,
@@ -96,76 +83,42 @@ function FederatedRoute({
9683 setAuthConfig ( runtimeAppConfig . spec . auth ) ;
9784 }
9885 } , [ retrieveConfiguration ] ) ;
99- return (
100- < ErrorBoundary
101- FallbackComponent = { ( ) => (
102- < ErrorPage500 data-cy = "sc-error-page500" locale = { language } />
103- ) }
104- >
105- < ProtectedFederatedRoute
106- url = { url }
107- scope = { scope }
108- module = { module }
109- app = { app }
110- groups = { groups }
111- />
112- </ ErrorBoundary >
113- ) ;
114- }
115-
116- function ProtectedFederatedRoute ( {
117- url,
118- scope,
119- module,
120- app,
121- groups,
122- } : FederatedComponentProps & {
123- groups ?: string [ ] ;
124- app : SolutionUI ;
125- } ) {
126- const { userData } = useAuth ( ) ;
127- const { retrieveConfiguration } = useConfigRetriever ( ) ;
12886
12987 const federatedAppProps : FederatedAppProps = {
13088 shellHooks,
13189 shellAlerts,
13290 } ;
13391
134- if (
135- userData &&
136- ( groups ?. some ( ( group ) => userData . groups . includes ( group ) ) ?? true )
137- ) {
138- const appBuildConfig = retrieveConfiguration < 'build' > ( {
139- configType : 'build' ,
140- name : app . name ,
141- } ) ;
142- return (
92+ const appBuildConfig = retrieveConfiguration < 'build' > ( {
93+ configType : 'build' ,
94+ name : app . name ,
95+ } ) ;
96+
97+ return (
98+ < ErrorBoundary
99+ FallbackComponent = { ( ) => (
100+ < ErrorPage500 data-cy = "sc-error-page500" locale = { language } />
101+ ) }
102+ >
143103 < FederatedComponent
144104 url = { `${ app . url } ${ appBuildConfig ?. spec . remoteEntryPath } ?version=${ app . version } ` }
145105 module = { module }
146106 props = { federatedAppProps }
147107 scope = { scope }
148108 app = { app }
149109 />
150- ) ;
151- }
152-
153- return < > </ > ;
110+ </ ErrorBoundary >
111+ ) ;
154112}
155113
156114function InternalRouter ( ) {
157- const discoveredViews = useDiscoveredViews ( ) ;
158- const { retrieveConfiguration } = useConfigRetriever ( ) ;
115+ const federatedRoutes = useFederatedRoutes ( ) ;
159116
160117 const routes = useMemo (
161118 ( ) =>
162- (
163- discoveredViews . filter (
164- ( discoveredView ) => discoveredView . isFederated ,
165- ) as FederatedView [ ]
166- )
167- //Sort the exact and strict routes first, to make sure to match the exact first.
168- . sort ( ( a , b ) => {
119+ //Sort the exact and strict routes first, to make sure to match the exact first.
120+ federatedRoutes
121+ . toSorted ( ( a , b ) => {
169122 if ( a . view . exact && ! b . view . exact ) {
170123 return - 1 ;
171124 }
@@ -183,30 +136,15 @@ function InternalRouter() {
183136 }
184137 return 0 ;
185138 } )
186-
187- . map ( ( { app, view, groups } ) => ( {
139+ . map ( ( { app, view } ) => ( {
188140 path : app . appHistoryBasePath + view . path ,
189141 basename : app . appHistoryBasePath ,
190- exact : view . exact ,
191- strict : view . strict ,
192142 sensitive : view . sensitive ,
193143 element : (
194- < FederatedRoute
195- url = {
196- app . url +
197- retrieveConfiguration < 'build' > ( {
198- configType : 'build' ,
199- name : app . name ,
200- } ) ?. spec . remoteEntryPath
201- }
202- module = { view . module }
203- scope = { view . scope }
204- app = { app }
205- groups = { groups }
206- />
144+ < FederatedRoute module = { view . module } scope = { view . scope } app = { app } />
207145 ) ,
208146 } ) ) ,
209- [ JSON . stringify ( discoveredViews ) ] ,
147+ [ JSON . stringify ( federatedRoutes ) ] ,
210148 ) ;
211149
212150 return (
0 commit comments