index.tsx 4.2 KB

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