index.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. enum DurationFunctionField {
  30. P50 = 'p50',
  31. P75 = 'p75',
  32. P95 = 'p95',
  33. P99 = 'p99',
  34. p100 = 'p100',
  35. }
  36. /**
  37. * Fetch and render a stacked area chart that shows duration percentiles over
  38. * the past 7 days
  39. */
  40. function DurationChart({
  41. project,
  42. environment,
  43. organization,
  44. query,
  45. statsPeriod,
  46. queryExtra,
  47. currentFilter,
  48. withoutZerofill,
  49. start: propsStart,
  50. end: propsEnd,
  51. queryExtras,
  52. }: Props) {
  53. const router = useRouter();
  54. const location = useLocation();
  55. const api = useApi();
  56. const theme = useTheme();
  57. function handleLegendSelectChanged(legendChange: {
  58. name: string;
  59. selected: Record<string, boolean>;
  60. type: string;
  61. }) {
  62. const {selected} = legendChange;
  63. const unselected = Object.keys(selected).filter(key => !selected[key]);
  64. const to = {
  65. ...location,
  66. query: {
  67. ...location.query,
  68. unselectedSeries: unselected,
  69. },
  70. };
  71. browserHistory.push(to);
  72. }
  73. const start = propsStart ? getUtcToLocalDateObject(propsStart) : null;
  74. const end = propsEnd ? getUtcToLocalDateObject(propsEnd) : null;
  75. const utc = normalizeDateTimeParams(location.query).utc === 'true';
  76. const period = statsPeriod;
  77. const legend = {right: 10, top: 5, selected: getSeriesSelection(location)};
  78. const datetimeSelection = {start, end, period};
  79. const contentCommonProps = {
  80. theme,
  81. router,
  82. start,
  83. end,
  84. utc,
  85. legend,
  86. queryExtra,
  87. period,
  88. projects: project,
  89. environments: environment,
  90. onLegendSelectChanged: handleLegendSelectChanged,
  91. };
  92. const requestCommonProps = {
  93. api,
  94. start,
  95. end,
  96. project,
  97. environment,
  98. query,
  99. period,
  100. interval: getInterval(datetimeSelection, 'high'),
  101. };
  102. const parameter = SPAN_OPERATION_BREAKDOWN_FILTER_TO_FIELD[currentFilter] ?? '';
  103. const header = (
  104. <HeaderTitleLegend>
  105. {currentFilter === SpanOperationBreakdownFilter.None
  106. ? t('Duration Breakdown')
  107. : tct('Span Operation Breakdown - [operationName]', {
  108. operationName: currentFilter,
  109. })}
  110. <QuestionTooltip
  111. size="sm"
  112. position="top"
  113. title={t(
  114. `Duration Breakdown reflects transaction durations by percentile over time.`
  115. )}
  116. />
  117. </HeaderTitleLegend>
  118. );
  119. const yAxis = Object.values(DurationFunctionField).map(v => `${v}(${parameter})`);
  120. return (
  121. <Fragment>
  122. {header}
  123. <EventsRequest
  124. {...requestCommonProps}
  125. organization={organization}
  126. showLoading={false}
  127. includePrevious={false}
  128. yAxis={yAxis}
  129. partial
  130. withoutZerofill={withoutZerofill}
  131. referrer="api.performance.transaction-summary.duration-chart"
  132. queryExtras={queryExtras}
  133. >
  134. {({results, errored, loading, reloading, timeframe: timeFrame}) => (
  135. <Content
  136. series={results}
  137. errored={errored}
  138. loading={loading}
  139. reloading={reloading}
  140. timeFrame={timeFrame}
  141. {...contentCommonProps}
  142. />
  143. )}
  144. </EventsRequest>
  145. </Fragment>
  146. );
  147. }
  148. export default DurationChart;