lineChartWidget.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. interface Props
  16. extends StateProps,
  17. Omit<WidgetFrameProps, 'children'>,
  18. Partial<LineChartWidgetVisualizationProps> {}
  19. export function LineChartWidget(props: Props) {
  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. utc={props.utc}
  50. meta={props.meta}
  51. dataCompletenessDelay={props.dataCompletenessDelay}
  52. />
  53. </LineChartWrapper>
  54. )}
  55. </WidgetFrame>
  56. );
  57. }
  58. const LineChartWrapper = styled('div')`
  59. flex-grow: 1;
  60. padding: 0 ${X_GUTTER} ${Y_GUTTER} ${X_GUTTER};
  61. `;
  62. const LoadingPlaceholder = styled('div')`
  63. position: absolute;
  64. inset: 0;
  65. display: flex;
  66. justify-content: center;
  67. align-items: center;
  68. `;