index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import {Fragment} from 'react';
  2. import type {Query} from 'history';
  3. import EventsRequest from 'sentry/components/charts/eventsRequest';
  4. import {HeaderTitleLegend} from 'sentry/components/charts/styles';
  5. import {getInterval} from 'sentry/components/charts/utils';
  6. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  7. import QuestionTooltip from 'sentry/components/questionTooltip';
  8. import {t} from 'sentry/locale';
  9. import type {Organization, OrganizationSummary} from 'sentry/types';
  10. import type {Series} from 'sentry/types/echarts';
  11. import {getUtcToLocalDateObject} from 'sentry/utils/dates';
  12. import {useMEPSettingContext} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  13. import useApi from 'sentry/utils/useApi';
  14. import {useLocation} from 'sentry/utils/useLocation';
  15. import DurationChart from 'sentry/views/performance/charts/chart';
  16. import {getTermHelp, PerformanceTerm} from 'sentry/views/performance/data';
  17. import {getMEPQueryParams} from 'sentry/views/performance/landing/widgets/utils';
  18. import type {ViewProps} from 'sentry/views/performance/types';
  19. type Props = ViewProps & {
  20. organization: OrganizationSummary;
  21. queryExtra: Query;
  22. withoutZerofill: boolean;
  23. };
  24. /**
  25. * Fetch and render an area chart that shows user misery over a period
  26. */
  27. function UserMiseryChart({
  28. project,
  29. environment,
  30. organization,
  31. query,
  32. statsPeriod,
  33. withoutZerofill,
  34. start: propsStart,
  35. end: propsEnd,
  36. }: Props) {
  37. const location = useLocation();
  38. const api = useApi();
  39. const mepContext = useMEPSettingContext();
  40. const start = propsStart ? getUtcToLocalDateObject(propsStart) : null;
  41. const end = propsEnd ? getUtcToLocalDateObject(propsEnd) : null;
  42. const utc = normalizeDateTimeParams(location.query).utc === 'true';
  43. const period = statsPeriod;
  44. const datetimeSelection = {start, end, period};
  45. const requestCommonProps = {
  46. api,
  47. start,
  48. end,
  49. project,
  50. environment,
  51. query,
  52. period,
  53. interval: getInterval(datetimeSelection, 'high'),
  54. };
  55. const header = (
  56. <HeaderTitleLegend>
  57. {t('User Misery')}
  58. <QuestionTooltip
  59. size="sm"
  60. position="top"
  61. title={getTermHelp(organization as Organization, PerformanceTerm.USER_MISERY)}
  62. />
  63. </HeaderTitleLegend>
  64. );
  65. const yAxis = 'user_misery()';
  66. return (
  67. <Fragment>
  68. {header}
  69. <EventsRequest
  70. {...requestCommonProps}
  71. organization={organization}
  72. showLoading={false}
  73. includePrevious={false}
  74. yAxis={yAxis}
  75. partial
  76. withoutZerofill={withoutZerofill}
  77. referrer="api.performance.transaction-summary.user-misery-chart"
  78. queryExtras={getMEPQueryParams(mepContext)}
  79. >
  80. {({loading, reloading, timeseriesData}) => {
  81. const data: Series[] = timeseriesData?.[0]
  82. ? [{...timeseriesData[0], seriesName: yAxis}]
  83. : [];
  84. return (
  85. <DurationChart
  86. grid={{left: '10px', right: '10px', top: '40px', bottom: '0px'}}
  87. data={data}
  88. statsPeriod={statsPeriod}
  89. loading={loading || reloading}
  90. disableMultiAxis
  91. definedAxisTicks={4}
  92. start={start}
  93. end={end}
  94. utc={utc}
  95. />
  96. );
  97. }}
  98. </EventsRequest>
  99. </Fragment>
  100. );
  101. }
  102. export default UserMiseryChart;