content.tsx 3.7 KB

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