@@ -394,8 +394,14 @@ function InnerWrapper({ children, project, dashboardName }) {
394394 const DEFAULT_DASHBOARD_DURATION = '30m' ;
395395 const DEFAULT_REFRESH_INTERVAL = '0s' ;
396396
397- const initialTimeRange = useInitialTimeRange ( DEFAULT_DASHBOARD_DURATION ) ;
398- const initialRefreshInterval = useInitialRefreshInterval ( DEFAULT_REFRESH_INTERVAL ) ;
397+ const dashboardDuration = persesDashboard ?. spec ?. duration ;
398+ const dashboardTimeInterval = persesDashboard ?. spec ?. refreshInterval ;
399+
400+ const effectiveDuration = dashboardDuration || DEFAULT_DASHBOARD_DURATION ;
401+ const effectiveRefreshInterval = dashboardTimeInterval || DEFAULT_REFRESH_INTERVAL ;
402+
403+ const initialTimeRange = useInitialTimeRange ( effectiveDuration ) ;
404+ const initialRefreshInterval = useInitialRefreshInterval ( effectiveRefreshInterval ) ;
399405
400406 const builtinVariables = useMemo ( ( ) => {
401407 const result = [
@@ -436,35 +442,21 @@ function InnerWrapper({ children, project, dashboardName }) {
436442 return < LoadingBox /> ;
437443 }
438444
439- let clearedDashboardResource : DashboardResource | undefined ;
440- if ( Array . isArray ( persesDashboard ) ) {
441- if ( persesDashboard . length === 0 ) {
442- clearedDashboardResource = undefined ;
443- } else {
444- clearedDashboardResource = persesDashboard [ 0 ] ;
445- }
446- } else {
447- clearedDashboardResource = persesDashboard ;
448- }
449-
450445 return (
451446 < TimeRangeProviderWithQueryParams
452447 initialTimeRange = { initialTimeRange }
453448 initialRefreshInterval = { initialRefreshInterval }
454449 >
455450 < VariableProviderWithQueryParams
456451 builtinVariableDefinitions = { builtinVariables }
457- initialVariableDefinitions = { clearedDashboardResource ?. spec ?. variables }
458- key = { clearedDashboardResource ?. metadata . name }
452+ initialVariableDefinitions = { persesDashboard ?. spec ?. variables }
453+ key = { persesDashboard ?. metadata . name }
459454 >
460- < PersesPrometheusDatasourceWrapper
461- queries = { [ ] }
462- dashboardResource = { clearedDashboardResource }
463- >
464- { clearedDashboardResource ? (
455+ < PersesPrometheusDatasourceWrapper queries = { [ ] } dashboardResource = { persesDashboard } >
456+ { persesDashboard ? (
465457 < DashboardProvider
466458 initialState = { {
467- dashboardResource : clearedDashboardResource ,
459+ dashboardResource : persesDashboard ,
468460 } }
469461 >
470462 < ValidationProvider > { children } </ ValidationProvider >
0 commit comments