content.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 {axisLabelFormatter, tooltipFormatter} from 'sentry/utils/discover/charts';
  13. import getDynamicText from 'sentry/utils/getDynamicText';
  14. import {Theme} from 'sentry/utils/theme';
  15. import {TransactionsListOption} from 'sentry/views/releases/detail/overview';
  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: Omit<LineChartProps, 'series'> = {
  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',
  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. // p75(measurements.fcp) coerces the axis to be time based
  79. formatter: (value: number) => axisLabelFormatter(value, 'p75(measurements.fcp)'),
  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. const series = data
  86. ? data.map((values, i: number) => ({
  87. ...values,
  88. color: colors[i],
  89. }))
  90. : [];
  91. return (
  92. <ChartZoom router={router} period={period} start={start} end={end} utc={utc}>
  93. {zoomRenderProps => (
  94. <ReleaseSeries
  95. start={start}
  96. end={end}
  97. queryExtra={{
  98. ...queryExtra,
  99. showTransactions: TransactionsListOption.SLOW_LCP,
  100. }}
  101. period={period}
  102. utc={utc}
  103. projects={projects}
  104. environments={environments}
  105. >
  106. {({releaseSeries}) => (
  107. <TransitionChart loading={loading} reloading={reloading}>
  108. <TransparentLoadingMask visible={reloading} />
  109. {getDynamicText({
  110. value: (
  111. <LineChart
  112. {...zoomRenderProps}
  113. {...chartOptions}
  114. legend={legend}
  115. onLegendSelectChanged={onLegendSelectChanged}
  116. series={[...series, ...releaseSeries]}
  117. />
  118. ),
  119. fixed: <Placeholder height="200px" testId="skeleton-ui" />,
  120. })}
  121. </TransitionChart>
  122. )}
  123. </ReleaseSeries>
  124. )}
  125. </ChartZoom>
  126. );
  127. }
  128. export default Content;