content.tsx 3.9 KB

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