lineChartWidget.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import styled from '@emotion/styled';
  2. import TransparentLoadingMask from 'sentry/components/charts/transparentLoadingMask';
  3. import LoadingIndicator from 'sentry/components/loadingIndicator';
  4. import {defined} from 'sentry/utils';
  5. import {
  6. WidgetFrame,
  7. type WidgetFrameProps,
  8. } from 'sentry/views/dashboards/widgets/common/widgetFrame';
  9. import {
  10. LineChartWidgetVisualization,
  11. type LineChartWidgetVisualizationProps,
  12. } from 'sentry/views/dashboards/widgets/lineChartWidget/lineChartWidgetVisualization';
  13. import {MISSING_DATA_MESSAGE, X_GUTTER, Y_GUTTER} from '../common/settings';
  14. import type {StateProps} from '../common/types';
  15. export interface LineChartWidgetProps
  16. extends StateProps,
  17. Omit<WidgetFrameProps, 'children'>,
  18. Partial<LineChartWidgetVisualizationProps> {}
  19. export function LineChartWidget(props: LineChartWidgetProps) {
  20. const {timeseries} = props;
  21. if (props.isLoading) {
  22. return (
  23. <WidgetFrame title={props.title} description={props.description}>
  24. <LoadingPlaceholder>
  25. <TransparentLoadingMask visible />
  26. <LoadingIndicator mini />
  27. </LoadingPlaceholder>
  28. </WidgetFrame>
  29. );
  30. }
  31. let parsingError: string | undefined = undefined;
  32. if (!defined(timeseries)) {
  33. parsingError = MISSING_DATA_MESSAGE;
  34. }
  35. const error = props.error ?? parsingError;
  36. return (
  37. <WidgetFrame
  38. title={props.title}
  39. description={props.description}
  40. actions={props.actions}
  41. error={error}
  42. onRetry={props.onRetry}
  43. >
  44. {defined(timeseries) && (
  45. <LineChartWrapper>
  46. <LineChartWidgetVisualization
  47. timeseries={timeseries}
  48. releases={props.releases}
  49. meta={props.meta}
  50. dataCompletenessDelay={props.dataCompletenessDelay}
  51. />
  52. </LineChartWrapper>
  53. )}
  54. </WidgetFrame>
  55. );
  56. }
  57. const LineChartWrapper = styled('div')`
  58. flex-grow: 1;
  59. padding: 0 ${X_GUTTER} ${Y_GUTTER} ${X_GUTTER};
  60. `;
  61. const LoadingPlaceholder = styled('div')`
  62. position: absolute;
  63. inset: 0;
  64. display: flex;
  65. justify-content: center;
  66. align-items: center;
  67. `;