content.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import type {Theme} from '@emotion/react';
  2. import type {Query} from 'history';
  3. import ChartZoom from 'sentry/components/charts/chartZoom';
  4. import ErrorPanel from 'sentry/components/charts/errorPanel';
  5. import type {LineChartProps} from 'sentry/components/charts/lineChart';
  6. import {LineChart} 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 type {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 {TransactionsListOption} from 'sentry/views/releases/detail/overview';
  21. type Props = {
  22. errored: boolean;
  23. loading: boolean;
  24. queryExtra: Query;
  25. reloading: boolean;
  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. onLegendSelectChanged,
  50. }: Props) {
  51. if (errored) {
  52. return (
  53. <ErrorPanel>
  54. <IconWarning color="gray500" size="lg" />
  55. </ErrorPanel>
  56. );
  57. }
  58. const colors = (data && theme.charts.getColorPalette(data.length - 2)) || [];
  59. // Create a list of series based on the order of the fields,
  60. const series = data
  61. ? data.map((values, i: number) => ({
  62. ...values,
  63. color: colors[i],
  64. }))
  65. : [];
  66. const durationUnit = getDurationUnit(series, legend);
  67. const chartOptions: Omit<LineChartProps, 'series'> = {
  68. grid: {
  69. left: '10px',
  70. right: '10px',
  71. top: '40px',
  72. bottom: '0px',
  73. },
  74. seriesOptions: {
  75. showSymbol: false,
  76. },
  77. tooltip: {
  78. trigger: 'axis',
  79. valueFormatter: (value, label) =>
  80. tooltipFormatter(value, aggregateOutputType(label)),
  81. },
  82. xAxis: timeFrame
  83. ? {
  84. min: timeFrame.start,
  85. max: timeFrame.end,
  86. }
  87. : undefined,
  88. yAxis: {
  89. minInterval: durationUnit,
  90. axisLabel: {
  91. color: theme.chartLabel,
  92. // p75(measurements.fcp) coerces the axis to be time based
  93. formatter: (value: number) =>
  94. axisLabelFormatter(value, 'duration', undefined, durationUnit),
  95. },
  96. },
  97. };
  98. return (
  99. <ChartZoom period={period} start={start} end={end} utc={utc}>
  100. {zoomRenderProps => (
  101. <ReleaseSeries
  102. start={start}
  103. end={end}
  104. queryExtra={{
  105. ...queryExtra,
  106. showTransactions: TransactionsListOption.SLOW_LCP,
  107. }}
  108. period={period}
  109. utc={utc}
  110. projects={projects}
  111. environments={environments}
  112. >
  113. {({releaseSeries}) => (
  114. <TransitionChart loading={loading} reloading={reloading}>
  115. <TransparentLoadingMask visible={reloading} />
  116. {getDynamicText({
  117. value: (
  118. <LineChart
  119. {...zoomRenderProps}
  120. {...chartOptions}
  121. legend={legend}
  122. onLegendSelectChanged={onLegendSelectChanged}
  123. series={[...series, ...releaseSeries]}
  124. />
  125. ),
  126. fixed: <Placeholder height="200px" testId="skeleton-ui" />,
  127. })}
  128. </TransitionChart>
  129. )}
  130. </ReleaseSeries>
  131. )}
  132. </ChartZoom>
  133. );
  134. }
  135. export default Content;