@@ -22,6 +22,7 @@ import { LANGUAGES } from 'app/core/internationalization/constants';
2222import  {  PreferencesService  }  from  'app/core/services/PreferencesService' ; 
2323import  {  backendSrv  }  from  "app/core/services/backend_srv" ; // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard 
2424import  {  changeTheme  }  from  'app/core/services/theme' ; 
25+ import  {  DashboardSearchItem  }  from  'app/features/search/types' ; 
2526
2627export  interface  Props  { 
2728  resourceUri : string ; 
@@ -30,7 +31,7 @@ export interface Props {
3031  onConfirm ?: ( )  =>  Promise < boolean > ; 
3132} 
3233
33- export  type  State  =  UserPreferencesDTO ; 
34+ export  type  State  =  UserPreferencesDTO   &   {   homeDashboardId ?:  number ;   dashboards :  Array < DashboardSearchItem   &   { id ?:  number } > } ;   // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard 
3435
3536function  getLanguageOptions ( ) : Array < SelectableValue < string > >  { 
3637  const  languageOptions  =  LANGUAGES . map ( ( v )  =>  ( { 
@@ -63,6 +64,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
6364      weekStart : '' , 
6465      language : '' , 
6566      queryHistory : {  homeTab : ''  } , 
67+       dashboards : [ ] , 
6668    } ; 
6769
6870    this . themeOptions  =  getBuiltInThemes ( config . featureToggles . extraThemes ) . map ( ( theme )  =>  ( { 
@@ -75,16 +77,35 @@ export class SharedPreferences extends PureComponent<Props, State> {
7577  } 
7678
7779  async  componentDidMount ( )  { 
78-     const  prefs  =  await  backendSrv . get ( `/api/${ this . props . resourceUri . toLowerCase ( ) }  ) ; // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard 
80+     // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard 
81+     const  prefs  =  await  backendSrv . get ( `/api/${ this . props . resourceUri . toLowerCase ( ) }  ) ; 
82+     const  dashboards  =  await  backendSrv . search ( {  starred : true  } ) ; 
83+     // 
84+     // this.setState({ 
85+     //   homeDashboardUID: prefs.homeDashboardUID, 
86+     //   theme: prefs.theme, 
87+     //   timezone: prefs.timezone, 
88+     //   weekStart: prefs.weekStart, 
89+     //   language: prefs.language, 
90+     //   queryHistory: prefs.queryHistory, 
91+     // }); 
92+ 
93+     if  ( prefs . homeDashboardId  >  0  &&  ! dashboards . find ( ( d )  =>  d . id  ===  prefs . homeDashboardId ) )  { 
94+       const  missing  =  await  backendSrv . search ( {  dashboardIds : [ prefs . homeDashboardId ]  } ) ; 
95+       if  ( missing  &&  missing . length  >  0 )  { 
96+         dashboards . push ( missing [ 0 ] ) ; 
97+       } 
98+     } 
7999
80100    this . setState ( { 
101+       homeDashboardId : prefs . homeDashboardId , 
81102      homeDashboardUID : prefs . homeDashboardUID , 
82103      theme : prefs . theme , 
83104      timezone : prefs . timezone , 
84105      weekStart : prefs . weekStart , 
85-       language : prefs . language , 
86-       queryHistory : prefs . queryHistory , 
106+       dashboards, 
87107    } ) ; 
108+     // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Remove default dashboard end 
88109  } 
89110
90111  onSubmitForm  =  async  ( event : React . FormEvent < HTMLFormElement > )  =>  { 
@@ -94,8 +115,9 @@ export class SharedPreferences extends PureComponent<Props, State> {
94115    if  ( confirmationResult )  { 
95116      // LOGZ.IO GRAFANA CHANGE :: DEV-20609 Home dashboard 
96117      const  {  homeDashboardUID,  theme,  timezone }  =  this . state ; 
118+       const  homeDashboard  =  this . state . dashboards . find ( d  =>  d . uid  ===  homeDashboardUID ) ; 
97119      await  backendSrv . put ( `/api/${ this . props . resourceUri . toLowerCase ( ) }  ,  { 
98-         homeDashboardId : homeDashboardUID , 
120+         homeDashboardId : homeDashboard ?. id   ||   null , 
99121        theme, 
100122        timezone, 
101123      } ) ; 
0 commit comments