content.tsx 4.0 KB

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