content.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 {Series} from 'sentry/types/echarts';
  12. import {
  13. axisLabelFormatter,
  14. getDurationUnit,
  15. tooltipFormatter,
  16. } from 'sentry/utils/discover/charts';
  17. import {aggregateOutputType} from 'sentry/utils/discover/fields';
  18. import getDynamicText from 'sentry/utils/getDynamicText';
  19. import {Theme} from 'sentry/utils/theme';
  20. import {TransactionsListOption} from 'sentry/views/releases/detail/overview';
  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. const series = data
  63. ? data.map((values, i: number) => ({
  64. ...values,
  65. color: colors[i],
  66. }))
  67. : [];
  68. const durationUnit = getDurationUnit(series, legend);
  69. const chartOptions: Omit<LineChartProps, 'series'> = {
  70. grid: {
  71. left: '10px',
  72. right: '10px',
  73. top: '40px',
  74. bottom: '0px',
  75. },
  76. seriesOptions: {
  77. showSymbol: false,
  78. },
  79. tooltip: {
  80. trigger: 'axis',
  81. valueFormatter: (value, label) =>
  82. tooltipFormatter(value, aggregateOutputType(label)),
  83. },
  84. xAxis: timeFrame
  85. ? {
  86. min: timeFrame.start,
  87. max: timeFrame.end,
  88. }
  89. : undefined,
  90. yAxis: {
  91. minInterval: durationUnit,
  92. axisLabel: {
  93. color: theme.chartLabel,
  94. // p75(measurements.fcp) coerces the axis to be time based
  95. formatter: (value: number) =>
  96. axisLabelFormatter(value, 'duration', undefined, durationUnit),
  97. },
  98. },
  99. };
  100. return (
  101. <ChartZoom router={router} period={period} start={start} end={end} utc={utc}>
  102. {zoomRenderProps => (
  103. <ReleaseSeries
  104. start={start}
  105. end={end}
  106. queryExtra={{
  107. ...queryExtra,
  108. showTransactions: TransactionsListOption.SLOW_LCP,
  109. }}
  110. period={period}
  111. utc={utc}
  112. projects={projects}
  113. environments={environments}
  114. >
  115. {({releaseSeries}) => (
  116. <TransitionChart loading={loading} reloading={reloading}>
  117. <TransparentLoadingMask visible={reloading} />
  118. {getDynamicText({
  119. value: (
  120. <LineChart
  121. {...zoomRenderProps}
  122. {...chartOptions}
  123. legend={legend}
  124. onLegendSelectChanged={onLegendSelectChanged}
  125. series={[...series, ...releaseSeries]}
  126. />
  127. ),
  128. fixed: <Placeholder height="200px" testId="skeleton-ui" />,
  129. })}
  130. </TransitionChart>
  131. )}
  132. </ReleaseSeries>
  133. )}
  134. </ChartZoom>
  135. );
  136. }
  137. export default Content;