index.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {Fragment} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import {useTheme} from '@emotion/react';
  4. import {Query} from 'history';
  5. import EventsRequest from 'sentry/components/charts/eventsRequest';
  6. import {HeaderTitleLegend} from 'sentry/components/charts/styles';
  7. import {getInterval, getSeriesSelection} from 'sentry/components/charts/utils';
  8. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  9. import QuestionTooltip from 'sentry/components/questionTooltip';
  10. import {t, tct} from 'sentry/locale';
  11. import {OrganizationSummary} from 'sentry/types';
  12. import {getUtcToLocalDateObject} from 'sentry/utils/dates';
  13. import useApi from 'sentry/utils/useApi';
  14. import {useLocation} from 'sentry/utils/useLocation';
  15. import useRouter from 'sentry/utils/useRouter';
  16. import {ViewProps} from '../../../types';
  17. import {
  18. SPAN_OPERATION_BREAKDOWN_FILTER_TO_FIELD,
  19. SpanOperationBreakdownFilter,
  20. } from '../../filter';
  21. import Content from './content';
  22. type Props = ViewProps & {
  23. currentFilter: SpanOperationBreakdownFilter;
  24. organization: OrganizationSummary;
  25. queryExtra: Query;
  26. withoutZerofill: boolean;
  27. queryExtras?: Record<string, string>;
  28. };
  29. const yAxisValues = ['p50', 'p75', 'p95', 'p99', 'p100'];
  30. /**
  31. * Fetch and render a stacked area chart that shows duration percentiles over
  32. * the past 7 days
  33. */
  34. function DurationChart({
  35. project,
  36. environment,
  37. organization,
  38. query,
  39. statsPeriod,
  40. queryExtra,
  41. currentFilter,
  42. withoutZerofill,
  43. start: propsStart,
  44. end: propsEnd,
  45. queryExtras,
  46. }: Props) {
  47. const router = useRouter();
  48. const location = useLocation();
  49. const api = useApi();
  50. const theme = useTheme();
  51. function handleLegendSelectChanged(legendChange: {
  52. name: string;
  53. selected: Record<string, boolean>;
  54. type: string;
  55. }) {
  56. const {selected} = legendChange;
  57. const unselected = Object.keys(selected).filter(key => !selected[key]);
  58. const to = {
  59. ...location,
  60. query: {
  61. ...location.query,
  62. unselectedSeries: unselected,
  63. },
  64. };
  65. browserHistory.push(to);
  66. }
  67. const start = propsStart ? getUtcToLocalDateObject(propsStart) : null;
  68. const end = propsEnd ? getUtcToLocalDateObject(propsEnd) : null;
  69. const utc = normalizeDateTimeParams(location.query).utc === 'true';
  70. const period = statsPeriod;
  71. const legend = {right: 10, top: 5, selected: getSeriesSelection(location)};
  72. const datetimeSelection = {start, end, period};
  73. const contentCommonProps = {
  74. theme,
  75. router,
  76. start,
  77. end,
  78. utc,
  79. legend,
  80. queryExtra,
  81. period,
  82. projects: project,
  83. environments: environment,
  84. onLegendSelectChanged: handleLegendSelectChanged,
  85. };
  86. const requestCommonProps = {
  87. api,
  88. start,
  89. end,
  90. project,
  91. environment,
  92. query,
  93. period,
  94. interval: getInterval(datetimeSelection, 'high'),
  95. };
  96. const parameter = SPAN_OPERATION_BREAKDOWN_FILTER_TO_FIELD[currentFilter] ?? '';
  97. const header = (
  98. <HeaderTitleLegend>
  99. {currentFilter === SpanOperationBreakdownFilter.NONE
  100. ? t('Duration Breakdown')
  101. : tct('Span Operation Breakdown - [operationName]', {
  102. operationName: currentFilter,
  103. })}
  104. <QuestionTooltip
  105. size="sm"
  106. position="top"
  107. title={t(
  108. `Duration Breakdown reflects transaction durations by percentile over time.`
  109. )}
  110. />
  111. </HeaderTitleLegend>
  112. );
  113. const yAxis = yAxisValues.map(v => `${v}(${parameter})`);
  114. return (
  115. <Fragment>
  116. {header}
  117. <EventsRequest
  118. {...requestCommonProps}
  119. organization={organization}
  120. showLoading={false}
  121. includePrevious={false}
  122. yAxis={yAxis}
  123. partial
  124. withoutZerofill={withoutZerofill}
  125. referrer="api.performance.transaction-summary.duration-chart"
  126. queryExtras={queryExtras}
  127. >
  128. {({results, errored, loading, reloading, timeframe: timeFrame}) => (
  129. <Content
  130. series={results}
  131. errored={errored}
  132. loading={loading}
  133. reloading={reloading}
  134. timeFrame={timeFrame}
  135. {...contentCommonProps}
  136. />
  137. )}
  138. </EventsRequest>
  139. </Fragment>
  140. );
  141. }
  142. export default DurationChart;