detailsTimeline.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {useEffect, useRef} from 'react';
  2. import styled from '@emotion/styled';
  3. import {
  4. GridLineLabels,
  5. GridLineOverlay,
  6. } from 'sentry/components/checkInTimeline/gridLines';
  7. import {useTimeWindowConfig} from 'sentry/components/checkInTimeline/hooks/useTimeWindowConfig';
  8. import Panel from 'sentry/components/panels/panel';
  9. import {useDebouncedValue} from 'sentry/utils/useDebouncedValue';
  10. import {useDimensions} from 'sentry/utils/useDimensions';
  11. import {OverviewRow} from 'sentry/views/insights/uptime/components/overviewTimeline/overviewRow';
  12. import {useUptimeMonitorStats} from 'sentry/views/insights/uptime/utils/useUptimeMonitorStats';
  13. import type {CheckStatusBucket, UptimeRule} from './types';
  14. interface Props {
  15. /**
  16. * Called when stats have been loaded for this timeline.
  17. */
  18. onStatsLoaded: (stats: CheckStatusBucket[]) => void;
  19. uptimeRule: UptimeRule;
  20. }
  21. export function DetailsTimeline({uptimeRule, onStatsLoaded}: Props) {
  22. const elementRef = useRef<HTMLDivElement>(null);
  23. const {width: containerWidth} = useDimensions<HTMLDivElement>({elementRef});
  24. const timelineWidth = useDebouncedValue(containerWidth, 500);
  25. const timeWindowConfig = useTimeWindowConfig({timelineWidth});
  26. const {data: uptimeStats} = useUptimeMonitorStats({
  27. ruleIds: [uptimeRule.id],
  28. timeWindowConfig,
  29. });
  30. useEffect(
  31. () => uptimeStats?.[uptimeRule.id] && onStatsLoaded?.(uptimeStats[uptimeRule.id]!),
  32. [onStatsLoaded, uptimeStats, uptimeRule.id]
  33. );
  34. return (
  35. <Panel>
  36. <TimelineWidthTracker ref={elementRef} />
  37. <Header>
  38. <GridLineLabels timeWindowConfig={timeWindowConfig} />
  39. </Header>
  40. <AlignedGridLineOverlay allowZoom showCursor timeWindowConfig={timeWindowConfig} />
  41. <OverviewRow
  42. uptimeRule={uptimeRule}
  43. timeWindowConfig={timeWindowConfig}
  44. singleRuleView
  45. />
  46. </Panel>
  47. );
  48. }
  49. const Header = styled('div')`
  50. border-bottom: 1px solid ${p => p.theme.border};
  51. z-index: 1;
  52. `;
  53. const AlignedGridLineOverlay = styled(GridLineOverlay)`
  54. position: absolute;
  55. top: 0;
  56. `;
  57. const TimelineWidthTracker = styled('div')`
  58. position: absolute;
  59. width: 100%;
  60. `;