1- import { useRef } from 'react' ;
1+ import { useEffect , useRef } from 'react' ;
22import styled from '@emotion/styled' ;
33
44import {
@@ -9,24 +9,30 @@ import Panel from 'sentry/components/panels/panel';
99import Text from 'sentry/components/text' ;
1010import { t } from 'sentry/locale' ;
1111import { space } from 'sentry/styles/space' ;
12- import type { Organization } from 'sentry/types/organization' ;
1312import { setApiQueryData , useQueryClient } from 'sentry/utils/queryClient' ;
1413import useApi from 'sentry/utils/useApi' ;
1514import { useDimensions } from 'sentry/utils/useDimensions' ;
1615import { useLocation } from 'sentry/utils/useLocation' ;
16+ import useOrganization from 'sentry/utils/useOrganization' ;
1717import type { Monitor } from 'sentry/views/monitors/types' ;
1818import { makeMonitorDetailsQueryKey } from 'sentry/views/monitors/utils' ;
1919
2020import { OverviewRow } from './overviewTimeline/overviewRow' ;
2121import { GridLineLabels , GridLineOverlay } from './timeline/gridLines' ;
22+ import { useMonitorStats } from './timeline/hooks/useMonitorStats' ;
2223import { useTimeWindowConfig } from './timeline/hooks/useTimeWindowConfig' ;
24+ import type { MonitorBucket } from './timeline/types' ;
2325
2426interface Props {
2527 monitor : Monitor ;
26- organization : Organization ;
28+ /**
29+ * Called when monitor stats have been loaded for this timeline.
30+ */
31+ onStatsLoaded : ( stats : MonitorBucket [ ] ) => void ;
2732}
2833
29- export function DetailsTimeline ( { monitor, organization} : Props ) {
34+ export function DetailsTimeline ( { monitor, onStatsLoaded} : Props ) {
35+ const organization = useOrganization ( ) ;
3036 const location = useLocation ( ) ;
3137 const api = useApi ( ) ;
3238 const queryClient = useQueryClient ( ) ;
@@ -43,6 +49,16 @@ export function DetailsTimeline({monitor, organization}: Props) {
4349 { ...location . query }
4450 ) ;
4551
52+ const { data : monitorStats } = useMonitorStats ( {
53+ monitors : [ monitor . id ] ,
54+ timeWindowConfig,
55+ } ) ;
56+
57+ useEffect (
58+ ( ) => monitorStats ?. [ monitor . id ] && onStatsLoaded ?.( monitorStats [ monitor . id ] ) ,
59+ [ onStatsLoaded , monitorStats , monitor . id ]
60+ ) ;
61+
4662 const handleDeleteEnvironment = async ( env : string ) => {
4763 const success = await deleteMonitorEnvironment ( api , organization . slug , monitor , env ) ;
4864 if ( ! success ) {
0 commit comments