userStats.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  5. import {SectionHeading} from 'sentry/components/charts/styles';
  6. import Link from 'sentry/components/links/link';
  7. import Placeholder from 'sentry/components/placeholder';
  8. import QuestionTooltip from 'sentry/components/questionTooltip';
  9. import UserMisery from 'sentry/components/userMisery';
  10. import {IconOpen} from 'sentry/icons';
  11. import {t} from 'sentry/locale';
  12. import type {Organization} from 'sentry/types';
  13. import type EventView from 'sentry/utils/discover/eventView';
  14. import type {QueryError} from 'sentry/utils/discover/genericDiscoverQuery';
  15. import {WebVital} from 'sentry/utils/fields';
  16. import {useMetricsCardinalityContext} from 'sentry/utils/performance/contexts/metricsCardinality';
  17. import {useMEPSettingContext} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  18. import {decodeScalar} from 'sentry/utils/queryString';
  19. import {getTermHelp, PerformanceTerm} from 'sentry/views/performance/data';
  20. import {getTransactionMEPParamsIfApplicable} from 'sentry/views/performance/transactionSummary/transactionOverview/utils';
  21. import {vitalsRouteWithQuery} from 'sentry/views/performance/transactionSummary/transactionVitals/utils';
  22. import {SidebarSpacer} from 'sentry/views/performance/transactionSummary/utils';
  23. import VitalInfo from 'sentry/views/performance/vitalDetail/vitalInfo';
  24. type Props = {
  25. error: QueryError | null;
  26. eventView: EventView;
  27. hasWebVitals: boolean;
  28. isLoading: boolean;
  29. location: Location;
  30. organization: Organization;
  31. totals: Record<string, number> | null;
  32. transactionName: string;
  33. };
  34. function UserStats({
  35. isLoading,
  36. hasWebVitals,
  37. error,
  38. totals,
  39. location,
  40. organization,
  41. transactionName,
  42. eventView,
  43. }: Props) {
  44. let userMisery = error !== null ? <div>{'\u2014'}</div> : <Placeholder height="34px" />;
  45. if (!isLoading && error === null && totals) {
  46. const threshold: number | undefined = totals.project_threshold_config
  47. ? totals.project_threshold_config[1]
  48. : undefined;
  49. const miserableUsers: number | undefined = totals['count_miserable_user()'];
  50. const userMiseryScore: number = totals['user_misery()'] || 0;
  51. const totalUsers = totals['count_unique_user()'];
  52. userMisery = (
  53. <UserMisery
  54. bars={40}
  55. barHeight={30}
  56. userMisery={userMiseryScore}
  57. miseryLimit={threshold}
  58. totalUsers={totalUsers}
  59. miserableUsers={miserableUsers}
  60. />
  61. );
  62. }
  63. const orgSlug = organization.slug;
  64. const webVitalsTarget = vitalsRouteWithQuery({
  65. orgSlug,
  66. transaction: transactionName,
  67. projectID: decodeScalar(location.query.project),
  68. query: location.query,
  69. });
  70. const mepSetting = useMEPSettingContext();
  71. const mepCardinalityContext = useMetricsCardinalityContext();
  72. const queryExtras = getTransactionMEPParamsIfApplicable(
  73. mepSetting,
  74. mepCardinalityContext,
  75. organization
  76. );
  77. return (
  78. <Fragment>
  79. {hasWebVitals && (
  80. <Fragment>
  81. <VitalsHeading>
  82. <SectionHeading>
  83. {t('Web Vitals')}
  84. <QuestionTooltip
  85. position="top"
  86. title={t(
  87. 'Web Vitals with p75 better than the "poor" threshold, as defined by Google Web Vitals.'
  88. )}
  89. size="sm"
  90. />
  91. </SectionHeading>
  92. <Link to={webVitalsTarget}>
  93. <IconOpen />
  94. </Link>
  95. </VitalsHeading>
  96. <VitalInfo
  97. location={location}
  98. vital={[WebVital.FCP, WebVital.LCP, WebVital.FID, WebVital.CLS]}
  99. orgSlug={orgSlug}
  100. environment={eventView.environment}
  101. start={eventView.start}
  102. end={eventView.end}
  103. statsPeriod={eventView.statsPeriod}
  104. project={eventView.project}
  105. hideVitalThresholds
  106. hideDurationDetail
  107. queryExtras={queryExtras}
  108. />
  109. <SidebarSpacer />
  110. </Fragment>
  111. )}
  112. <GuideAnchor target="user_misery" position="left">
  113. <SectionHeading>
  114. {t('User Misery')}
  115. <QuestionTooltip
  116. position="top"
  117. title={getTermHelp(organization, PerformanceTerm.USER_MISERY)}
  118. size="sm"
  119. />
  120. </SectionHeading>
  121. </GuideAnchor>
  122. {userMisery}
  123. <SidebarSpacer />
  124. </Fragment>
  125. );
  126. }
  127. const VitalsHeading = styled('div')`
  128. display: flex;
  129. justify-content: space-between;
  130. align-items: center;
  131. `;
  132. export default UserStats;