1
1
import { cx } from '@emotion/css' ;
2
2
import React , { PureComponent } from 'react' ;
3
- import { connect , ConnectedProps } from 'react-redux' ;
3
+ import { connect , ConnectedProps , MapDispatchToProps , MapStateToProps } from 'react-redux' ;
4
4
5
5
import { NavModel , NavModelItem , TimeRange , PageLayoutType , locationUtil } from '@grafana/data' ;
6
6
import { selectors } from '@grafana/e2e-selectors' ;
@@ -13,11 +13,13 @@ import { GrafanaContext, GrafanaContextType } from 'app/core/context/GrafanaCont
13
13
import { createErrorNotification } from 'app/core/copy/appNotification' ;
14
14
import { getKioskMode } from 'app/core/navigation/kiosk' ;
15
15
import { GrafanaRouteComponentProps } from 'app/core/navigation/types' ;
16
+ import { FnGlobalState } from 'app/core/reducers/fn-slice' ;
16
17
import { getNavModel } from 'app/core/selectors/navModel' ;
17
18
import { PanelModel } from 'app/features/dashboard/state' ;
18
19
import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher' ;
19
20
import { getPageNavFromSlug , getRootContentNavModel } from 'app/features/storage/StorageFolderPage' ;
20
- import { DashboardRoutes , KioskMode , StoreState } from 'app/types' ;
21
+ import { FNDashboardProps } from 'app/fn-app/types' ;
22
+ import { DashboardRoutes , DashboardState , KioskMode , StoreState } from 'app/types' ;
21
23
import { PanelEditEnteredEvent , PanelEditExitedEvent } from 'app/types/events' ;
22
24
23
25
import { cancelVariables , templateVarsChangedInUrl } from '../../variables/state/actions' ;
@@ -26,6 +28,7 @@ import { AddWidgetModal } from '../components/AddWidgetModal/AddWidgetModal';
26
28
import { DashNav } from '../components/DashNav' ;
27
29
import { DashboardFailed } from '../components/DashboardLoading/DashboardFailed' ;
28
30
import { DashboardLoading } from '../components/DashboardLoading/DashboardLoading' ;
31
+ import { FnLoader } from '../components/DashboardLoading/FnLoader' ;
29
32
import { DashboardPrompt } from '../components/DashboardPrompt/DashboardPrompt' ;
30
33
import { DashboardSettings } from '../components/DashboardSettings' ;
31
34
import { PanelInspector } from '../components/Inspector/PanelInspector' ;
@@ -52,7 +55,7 @@ export type DashboardPageRouteSearchParams = {
52
55
editPanel ?: string ;
53
56
viewPanel ?: string ;
54
57
editview ?: string ;
55
- addWidget ?: boolean ;
58
+ shareView ?: string ;
56
59
panelType ?: string ;
57
60
inspect ?: string ;
58
61
from ?: string ;
@@ -61,14 +64,34 @@ export type DashboardPageRouteSearchParams = {
61
64
kiosk ?: string | true ;
62
65
} ;
63
66
64
- export const mapStateToProps = ( state : StoreState ) => ( {
67
+ export type MapStateToDashboardPageProps = MapStateToProps <
68
+ Pick < DashboardState , 'initPhase' | 'initError' > & { dashboard : ReturnType < DashboardState [ 'getModel' ] > } & Pick <
69
+ FnGlobalState ,
70
+ 'FNDashboard'
71
+ > ,
72
+ OwnProps ,
73
+ StoreState
74
+ > ;
75
+
76
+ export type MapDispatchToDashboardPageProps = MapDispatchToProps < MappedDispatch , OwnProps > ;
77
+
78
+ export type MappedDispatch = {
79
+ initDashboard : typeof initDashboard ;
80
+ cleanUpDashboardAndVariables : typeof cleanUpDashboardAndVariables ;
81
+ notifyApp : typeof notifyApp ;
82
+ cancelVariables : typeof cancelVariables ;
83
+ templateVarsChangedInUrl : typeof templateVarsChangedInUrl ;
84
+ } ;
85
+
86
+ export const mapStateToProps : MapStateToDashboardPageProps = ( state ) => ( {
65
87
initPhase : state . dashboard . initPhase ,
66
88
initError : state . dashboard . initError ,
67
89
dashboard : state . dashboard . getModel ( ) ,
68
90
navIndex : state . navIndex ,
91
+ FNDashboard : state . fnGlobalState . FNDashboard ,
69
92
} ) ;
70
93
71
- const mapDispatchToProps = {
94
+ const mapDispatchToProps : MapDispatchToDashboardPageProps = {
72
95
initDashboard,
73
96
cleanUpDashboardAndVariables,
74
97
notifyApp,
@@ -78,6 +101,16 @@ const mapDispatchToProps = {
78
101
79
102
const connector = connect ( mapStateToProps , mapDispatchToProps ) ;
80
103
104
+ type OwnProps = {
105
+ isPublic ?: boolean ;
106
+ controlsContainer ?: string | null ;
107
+ version ?: FNDashboardProps [ 'version' ] ;
108
+ isLoading ?: FNDashboardProps [ 'isLoading' ] ;
109
+ } ;
110
+
111
+ export type DashboardPageProps = OwnProps &
112
+ GrafanaRouteComponentProps < DashboardPageRouteParams , DashboardPageRouteSearchParams > ;
113
+
81
114
export type Props = Themeable2 &
82
115
GrafanaRouteComponentProps < DashboardPageRouteParams , DashboardPageRouteSearchParams > &
83
116
ConnectedProps < typeof connector > ;
@@ -114,7 +147,11 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
114
147
115
148
componentDidMount ( ) {
116
149
this . initDashboard ( ) ;
117
- this . forceRouteReloadCounter = ( this . props . history . location . state as any ) ?. routeReloadCounter || 0 ;
150
+ const { FNDashboard } = this . props ;
151
+
152
+ if ( ! FNDashboard ) {
153
+ this . forceRouteReloadCounter = ( this . props . history . location ?. state as any ) ?. routeReloadCounter || 0 ;
154
+ }
118
155
}
119
156
120
157
componentWillUnmount ( ) {
@@ -127,7 +164,7 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
127
164
}
128
165
129
166
initDashboard ( ) {
130
- const { dashboard, match, queryParams } = this . props ;
167
+ const { dashboard, match, queryParams, FNDashboard } = this . props ;
131
168
132
169
if ( dashboard ) {
133
170
this . closeDashboard ( ) ;
@@ -140,30 +177,34 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
140
177
urlFolderUid : queryParams . folderUid ,
141
178
panelType : queryParams . panelType ,
142
179
routeName : this . props . route . routeName ,
143
- fixUrl : true ,
180
+ fixUrl : ! FNDashboard ,
144
181
accessToken : match . params . accessToken ,
145
- keybindingSrv : this . context ? .keybindings ,
182
+ keybindingSrv : this . context . keybindings ,
146
183
} ) ;
147
184
148
185
// small delay to start live updates
149
186
setTimeout ( this . updateLiveTimer , 250 ) ;
150
187
}
151
188
152
189
componentDidUpdate ( prevProps : Props , prevState : State ) {
153
- const { dashboard, match, templateVarsChangedInUrl } = this . props ;
154
- const routeReloadCounter = ( this . props . history . location . state as any ) ?. routeReloadCounter ;
190
+ const { dashboard, match, templateVarsChangedInUrl, FNDashboard } = this . props ;
155
191
156
192
if ( ! dashboard ) {
157
193
return ;
158
194
}
159
195
160
- if (
161
- prevProps . match . params . uid !== match . params . uid ||
162
- ( routeReloadCounter !== undefined && this . forceRouteReloadCounter !== routeReloadCounter )
163
- ) {
164
- this . initDashboard ( ) ;
165
- this . forceRouteReloadCounter = routeReloadCounter ;
166
- return ;
196
+ if ( ! FNDashboard ) {
197
+ const routeReloadCounter = ( this . props . history . location ?. state as any ) ?. routeReloadCounter ;
198
+
199
+ if (
200
+ prevProps . match . params . uid !== match . params . uid ||
201
+ prevProps . match . params . version !== match . params . version ||
202
+ ( routeReloadCounter !== undefined && this . forceRouteReloadCounter !== routeReloadCounter )
203
+ ) {
204
+ this . initDashboard ( ) ;
205
+ this . forceRouteReloadCounter = routeReloadCounter ;
206
+ return ;
207
+ }
167
208
}
168
209
169
210
if ( prevProps . location . search !== this . props . location . search ) {
@@ -332,18 +373,18 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
332
373
}
333
374
334
375
render ( ) {
335
- const { dashboard, initError, queryParams } = this . props ;
376
+ const { dashboard, initError, queryParams, FNDashboard } = this . props ;
336
377
const { editPanel, viewPanel, updateScrollTop, pageNav, sectionNav } = this . state ;
337
378
const kioskMode = getKioskMode ( this . props . queryParams ) ;
338
379
339
- if ( ! dashboard || ! pageNav || ! sectionNav ) {
340
- return < DashboardLoading initPhase = { this . props . initPhase } /> ;
380
+ if ( ! dashboard ) {
381
+ return FNDashboard ? < FnLoader /> : < DashboardLoading initPhase = { this . props . initPhase } /> ;
341
382
}
342
383
343
384
const inspectPanel = this . getInspectPanel ( ) ;
344
385
const showSubMenu = ! editPanel && ! kioskMode && ! this . props . queryParams . editview ;
345
386
346
- const showToolbar = kioskMode !== KioskMode . Full && ! queryParams . editview ;
387
+ const showToolbar = FNDashboard || ( kioskMode !== KioskMode . Full && ! queryParams . editview ) ;
347
388
348
389
const pageClassName = cx ( {
349
390
'panel-in-fullscreen' : Boolean ( viewPanel ) ,
@@ -381,23 +422,23 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
381
422
/>
382
423
</ header >
383
424
) }
384
- < DashboardPrompt dashboard = { dashboard } />
425
+ { ! FNDashboard && < DashboardPrompt dashboard = { dashboard } /> }
385
426
{ initError && < DashboardFailed /> }
386
- { showSubMenu && (
427
+ { showSubMenu && ! FNDashboard && (
387
428
< section aria-label = { selectors . pages . Dashboard . SubMenu . submenu } >
388
429
< SubMenu dashboard = { dashboard } annotations = { dashboard . annotations . list } links = { dashboard . links } />
389
430
</ section >
390
431
) }
391
432
< DashboardGrid
392
433
dashboard = { dashboard }
393
- isEditable = { ! ! dashboard . meta . canEdit }
434
+ isEditable = { ! ! dashboard . meta . canEdit && ! FNDashboard }
394
435
viewPanel = { viewPanel }
395
436
editPanel = { editPanel }
396
437
/>
397
438
398
- { inspectPanel && < PanelInspector dashboard = { dashboard } panel = { inspectPanel } /> }
439
+ { inspectPanel && ! FNDashboard && < PanelInspector dashboard = { dashboard } panel = { inspectPanel } /> }
399
440
</ Page >
400
- { editPanel && (
441
+ { editPanel && ! FNDashboard && (
401
442
< PanelEditor
402
443
dashboard = { dashboard }
403
444
sourcePanel = { editPanel }
@@ -406,31 +447,31 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
406
447
pageNav = { pageNav }
407
448
/>
408
449
) }
409
- { queryParams . editview && (
450
+ { queryParams . editview && ! FNDashboard && (
410
451
< DashboardSettings
411
452
dashboard = { dashboard }
412
453
editview = { queryParams . editview }
413
454
pageNav = { pageNav }
414
455
sectionNav = { sectionNav }
415
456
/>
416
457
) }
417
- { queryParams . addWidget && config . featureToggles . vizAndWidgetSplit && < AddWidgetModal /> }
458
+ { ! FNDashboard && queryParams . addWidget && config . featureToggles . vizAndWidgetSplit && < AddWidgetModal /> }
418
459
</ >
419
460
) ;
420
461
}
421
462
}
422
463
423
464
function updateStatePageNavFromProps ( props : Props , state : State ) : State {
424
- const { dashboard, navIndex } = props ;
465
+ const { dashboard, FNDashboard } = props ;
425
466
426
- if ( ! dashboard ) {
467
+ if ( ! dashboard || FNDashboard ) {
427
468
return state ;
428
469
}
429
470
430
471
let pageNav = state . pageNav ;
431
472
let sectionNav = state . sectionNav ;
432
473
433
- if ( ! pageNav || dashboard . title !== pageNav . text || dashboard . meta . folderUrl !== pageNav . parentItem ?. url ) {
474
+ if ( ! pageNav || dashboard . title !== pageNav . text ) {
434
475
pageNav = {
435
476
text : dashboard . title ,
436
477
url : locationUtil . getUrlForPartial ( props . history . location , {
@@ -441,26 +482,16 @@ function updateStatePageNavFromProps(props: Props, state: State): State {
441
482
} ;
442
483
}
443
484
485
+ // Check if folder changed
444
486
const { folderTitle, folderUid } = dashboard . meta ;
445
- if ( folderUid && pageNav ) {
446
- if ( config . featureToggles . nestedFolders ) {
447
- const folderNavModel = getNavModel ( navIndex , `folder-dashboards-${ folderUid } ` ) . main ;
448
- pageNav = {
449
- ...pageNav ,
450
- parentItem : folderNavModel ,
451
- } ;
452
- } else {
453
- // Check if folder changed
454
- if ( folderTitle && pageNav . parentItem ?. text !== folderTitle ) {
455
- pageNav = {
456
- ...pageNav ,
457
- parentItem : {
458
- text : folderTitle ,
459
- url : `/dashboards/f/${ dashboard . meta . folderUid } ` ,
460
- } ,
461
- } ;
462
- }
463
- }
487
+ if ( folderTitle && folderUid && pageNav && pageNav . parentItem ?. text !== folderTitle ) {
488
+ pageNav = {
489
+ ...pageNav ,
490
+ parentItem : {
491
+ text : folderTitle ,
492
+ url : `/dashboards/f/${ dashboard . meta . folderUid } ` ,
493
+ } ,
494
+ } ;
464
495
}
465
496
466
497
if ( props . route . routeName === DashboardRoutes . Path ) {
@@ -470,7 +501,7 @@ function updateStatePageNavFromProps(props: Props, state: State): State {
470
501
pageNav . parentItem = pageNav . parentItem ;
471
502
}
472
503
} else {
473
- sectionNav = getNavModel ( props . navIndex , 'dashboards/browse' ) ;
504
+ sectionNav = getNavModel ( props . navIndex , config . featureToggles . topnav ? 'dashboards/browse' : 'dashboards ') ;
474
505
}
475
506
476
507
if ( state . editPanel || state . viewPanel ) {
0 commit comments