@@ -60,18 +60,14 @@ type DeepPartial<T> = {
60
60
61
61
class createMfe {
62
62
private static readonly containerSelector = '#grafanaRoot' ;
63
-
64
- private static readonly logPrefix = '[FN Grafana]' ;
63
+ private static logger = FnLoggerService ;
65
64
66
65
mode : FNDashboardProps [ 'mode' ] ;
67
66
static Component : ComponentType < Omit < FNDashboardProps , FnPropMappedFromState > > ;
68
67
constructor ( readonly props : FNDashboardProps ) {
69
68
this . mode = props . mode ;
70
69
}
71
70
72
- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
73
- private static logger = ( ...args : any [ ] ) => console . log ( createMfe . logPrefix , ...args ) ;
74
-
75
71
static getLifeCycles ( component : ComponentType < Omit < FNDashboardProps , FnPropMappedFromState > > ) {
76
72
const lifeCycles : FrameworkLifeCycles = {
77
73
bootstrap : this . boot ( ) ,
@@ -168,7 +164,7 @@ class createMfe {
168
164
* If isRuntimeOnly then the stylesheets of the turned off theme are not removed
169
165
*/
170
166
private static loadFnTheme = ( mode : FNDashboardProps [ 'mode' ] = GrafanaThemeType . Light , isRuntimeOnly = false ) => {
171
- createMfe . logger ( 'Trying to load theme.' , { mode } ) ;
167
+ createMfe . logger . info ( 'Trying to load theme.' , { mode } ) ;
172
168
173
169
const grafanaTheme2 = createMfe . createGrafanaTheme2 ( mode ) ;
174
170
@@ -179,7 +175,7 @@ class createMfe {
179
175
createMfe . publishTheme ( bootConfigWithTheme . theme2 ) ;
180
176
181
177
if ( isRuntimeOnly ) {
182
- createMfe . logger ( 'Successfully loaded theme' , { mode } ) ;
178
+ createMfe . logger . info ( 'Successfully loaded theme' , { mode } ) ;
183
179
184
180
return ;
185
181
}
@@ -190,7 +186,7 @@ class createMfe {
190
186
newCssLink . href = config . bootData . themePaths [ mode ] ;
191
187
document . body . appendChild ( newCssLink ) ;
192
188
193
- createMfe . logger ( 'Successfully loaded theme.' , { mode } ) ;
189
+ createMfe . logger . info ( 'Successfully loaded theme.' , { mode } ) ;
194
190
} ;
195
191
196
192
private static getContainer ( props : FNDashboardProps ) {
@@ -201,8 +197,6 @@ class createMfe {
201
197
202
198
static mountFnApp ( Component : ComponentType < Omit < FNDashboardProps , FnPropMappedFromState > > ) {
203
199
const lifeCycleFn : FrameworkLifeCycles [ 'mount' ] = ( props : FNDashboardProps ) => {
204
- createMfe . logger ( 'Trying to mount grafana...' ) ;
205
-
206
200
return new Promise ( ( res , rej ) => {
207
201
try {
208
202
createMfe . loadFnTheme ( props . mode ) ;
@@ -214,19 +208,19 @@ class createMfe {
214
208
...pick ( props , ...fnStateProps ) ,
215
209
} ;
216
210
217
- FnLoggerService . log ( null , '[FN Grafana] Dispatching initial state.' , { initialState } ) ;
211
+ createMfe . logger . info ( '[FN Grafana] Dispatching initial state.' , { initialState } ) ;
218
212
219
213
dispatch ( updateFnState ( initialState ) ) ;
220
214
221
215
createMfe . renderMfeComponent ( props , ( ) => {
222
- createMfe . logger ( 'Mounted grafana.' , { props } ) ;
216
+ createMfe . logger . info ( 'Mounted grafana.' , { props } ) ;
223
217
224
218
return res ( true ) ;
225
219
} ) ;
226
220
} catch ( err ) {
227
221
const message = `[FN Grafana]: Failed to mount grafana. ${ err } ` ;
228
222
229
- FnLoggerService . log ( null , message ) ;
223
+ FnLoggerService . info ( null , message ) ;
230
224
231
225
const fnError = new Error ( message ) ;
232
226
@@ -246,13 +240,13 @@ class createMfe {
246
240
const container = createMfe . getContainer ( props ) ;
247
241
248
242
if ( container ) {
249
- createMfe . logger ( 'Trying to unmount grafana...' ) ;
243
+ createMfe . logger . info ( 'Trying to unmount grafana...' ) ;
250
244
251
245
ReactDOM . unmountComponentAtNode ( container ) ;
252
246
253
- createMfe . logger ( 'Successfully unmounted grafana.' ) ;
247
+ createMfe . logger . info ( 'Successfully unmounted grafana.' ) ;
254
248
} else {
255
- createMfe . logger ( 'Failed to unmount grafana. Container does not exist.' ) ;
249
+ createMfe . logger . error ( 'Failed to unmount grafana. Container does not exist.' ) ;
256
250
}
257
251
258
252
backendSrv . cancelAllInFlightRequests ( ) ;
@@ -266,26 +260,17 @@ class createMfe {
266
260
static updateFnApp ( ) {
267
261
const lifeCycleFn : FrameworkLifeCycles [ 'update' ] = ( { mode, ...other } : FNDashboardProps ) => {
268
262
if ( mode ) {
269
- createMfe . logger ( 'Trying to update grafana with theme.' , { mode } ) ;
270
-
271
263
dispatch (
272
264
updatePartialFnStates ( {
273
265
mode,
274
266
} )
275
267
) ;
276
- /**
277
- * NOTE:
278
- * Here happens the theme change.
279
- *
280
- * TODO:
281
- * We could probably made the theme change smoother
282
- * if we use state to update the theme
283
- */
268
+
284
269
createMfe . loadFnTheme ( mode ) ;
285
270
}
286
271
287
272
if ( other . uid ) {
288
- createMfe . logger ( 'Trying to update grafana with hidden variables. ' , { updatedProps : other } ) ;
273
+ createMfe . logger . info ( 'Trying to render dashboard using update: ' , { updatedProps : other } ) ;
289
274
290
275
dispatch (
291
276
updatePartialFnStates ( {
@@ -310,7 +295,7 @@ class createMfe {
310
295
const container = createMfe . getContainer ( props ) ;
311
296
312
297
ReactDOM . render ( React . createElement ( createMfe . Component , props ) , container , ( ) => {
313
- createMfe . logger ( 'Created mfe component.' , { props, container } ) ;
298
+ createMfe . logger . info ( 'Created mfe component.' , { props, container } ) ;
314
299
onSuccess ( ) ;
315
300
} ) ;
316
301
}
0 commit comments