content.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import {InjectedRouter} from 'react-router';
  2. import {Query} from 'history';
  3. import ChartZoom from 'sentry/components/charts/chartZoom';
  4. import ErrorPanel from 'sentry/components/charts/errorPanel';
  5. import {LineChart, LineChartProps} from 'sentry/components/charts/lineChart';
  6. import ReleaseSeries from 'sentry/components/charts/releaseSeries';
  7. import TransitionChart from 'sentry/components/charts/transitionChart';
  8. import TransparentLoadingMask from 'sentry/components/charts/transparentLoadingMask';
  9. import Placeholder from 'sentry/components/placeholder';
  10. import {IconWarning} from 'sentry/icons';
  11. import {t} from 'sentry/locale';
  12. import {Series} from 'sentry/types/echarts';
  13. import {axisLabelFormatter, tooltipFormatter} from 'sentry/utils/discover/charts';
  14. import getDynamicText from 'sentry/utils/getDynamicText';
  15. import {Theme} from 'sentry/utils/theme';
  16. import {transformEventStatsSmoothed} from '../../../trends/utils';
  17. type Props = {
  18. errored: boolean;
  19. loading: boolean;
  20. queryExtra: Query;
  21. reloading: boolean;
  22. router: InjectedRouter;
  23. theme: Theme;
  24. series?: Series[];
  25. timeFrame?: {
  26. end: number;
  27. start: number;
  28. };
  29. } & Omit<React.ComponentProps<typeof ReleaseSeries>, 'children' | 'queryExtra'> &
  30. Pick<LineChartProps, 'onLegendSelectChanged' | 'legend'>;
  31. function Content({
  32. errored,
  33. theme,
  34. series: data,
  35. timeFrame,
  36. start,
  37. end,
  38. period,
  39. projects,
  40. environments,
  41. loading,
  42. reloading,
  43. legend,
  44. utc,
  45. queryExtra,
  46. router,
  47. onLegendSelectChanged,
  48. }: Props) {
  49. if (errored) {
  50. return (
  51. <ErrorPanel>
  52. <IconWarning color="gray500" size="lg" />
  53. </ErrorPanel>
  54. );
  55. }
  56. const chartOptions: Omit<LineChartProps, 'series'> = {
  57. grid: {
  58. left: '10px',
  59. right: '10px',
  60. top: '40px',
  61. bottom: '0px',
  62. },
  63. seriesOptions: {
  64. showSymbol: false,
  65. },
  66. tooltip: {
  67. trigger: 'axis',
  68. valueFormatter: (value: number | null) => tooltipFormatter(value, 'p50()'),
  69. },
  70. xAxis: timeFrame
  71. ? {
  72. min: timeFrame.start,
  73. max: timeFrame.end,
  74. }
  75. : undefined,
  76. yAxis: {
  77. min: 0,
  78. axisLabel: {
  79. color: theme.chartLabel,
  80. // p50() coerces the axis to be time based
  81. formatter: (value: number) => axisLabelFormatter(value, 'p50()'),
  82. },
  83. },
  84. };
  85. const series = data
  86. ? data
  87. .map(values => {
  88. return {
  89. ...values,
  90. color: theme.purple300,
  91. lineStyle: {
  92. opacity: 0.75,
  93. width: 1,
  94. },
  95. };
  96. })
  97. .reverse()
  98. : [];
  99. const {smoothedResults} = transformEventStatsSmoothed(data, t('Smoothed'));
  100. const smoothedSeries = smoothedResults
  101. ? smoothedResults.map(values => {
  102. return {
  103. ...values,
  104. color: theme.purple300,
  105. lineStyle: {
  106. opacity: 1,
  107. },
  108. };
  109. })
  110. : [];
  111. return (
  112. <ChartZoom router={router} period={period} start={start} end={end} utc={utc}>
  113. {zoomRenderProps => (
  114. <ReleaseSeries
  115. start={start}
  116. end={end}
  117. queryExtra={queryExtra}
  118. period={period}
  119. utc={utc}
  120. projects={projects}
  121. environments={environments}
  122. >
  123. {({releaseSeries}) => (
  124. <TransitionChart loading={loading} reloading={reloading}>
  125. <TransparentLoadingMask visible={reloading} />
  126. {getDynamicText({
  127. value: (
  128. <LineChart
  129. {...zoomRenderProps}
  130. {...chartOptions}
  131. legend={legend}
  132. onLegendSelectChanged={onLegendSelectChanged}
  133. series={[...series, ...smoothedSeries, ...releaseSeries]}
  134. />
  135. ),
  136. fixed: <Placeholder height="200px" testId="skeleton-ui" />,
  137. })}
  138. </TransitionChart>
  139. )}
  140. </ReleaseSeries>
  141. )}
  142. </ChartZoom>
  143. );
  144. }
  145. export default Content;