index.tsx 4.4 KB

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