userStats.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/organization';
  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. const hasTransactionSummaryCleanupFlag = organization.features.includes(
  45. 'performance-transaction-summary-cleanup'
  46. );
  47. let userMisery = error !== null ? <div>{'\u2014'}</div> : <Placeholder height="34px" />;
  48. if (!isLoading && error === null && totals) {
  49. const threshold: number | undefined = totals.project_threshold_config
  50. ? totals.project_threshold_config[1]
  51. : undefined;
  52. const miserableUsers: number | undefined = totals['count_miserable_user()'];
  53. const userMiseryScore: number = totals['user_misery()'] || 0;
  54. const totalUsers = totals['count_unique_user()'];
  55. userMisery = (
  56. <UserMisery
  57. bars={40}
  58. barHeight={30}
  59. userMisery={userMiseryScore}
  60. miseryLimit={threshold}
  61. totalUsers={totalUsers}
  62. miserableUsers={miserableUsers}
  63. />
  64. );
  65. }
  66. const orgSlug = organization.slug;
  67. const webVitalsTarget = vitalsRouteWithQuery({
  68. orgSlug,
  69. transaction: transactionName,
  70. projectID: decodeScalar(location.query.project),
  71. query: location.query,
  72. });
  73. const mepSetting = useMEPSettingContext();
  74. const mepCardinalityContext = useMetricsCardinalityContext();
  75. const queryExtras = getTransactionMEPParamsIfApplicable(
  76. mepSetting,
  77. mepCardinalityContext,
  78. organization
  79. );
  80. return (
  81. <Fragment>
  82. {hasWebVitals && (
  83. <Fragment>
  84. <VitalsHeading>
  85. <SectionHeading>
  86. {t('Web Vitals')}
  87. <QuestionTooltip
  88. position="top"
  89. title={t(
  90. 'Web Vitals with p75 better than the "poor" threshold, as defined by Google Web Vitals.'
  91. )}
  92. size="sm"
  93. />
  94. </SectionHeading>
  95. <Link to={webVitalsTarget}>
  96. <IconOpen />
  97. </Link>
  98. </VitalsHeading>
  99. <VitalInfo
  100. location={location}
  101. vital={[WebVital.FCP, WebVital.LCP, WebVital.FID, WebVital.CLS]}
  102. orgSlug={orgSlug}
  103. environment={eventView.environment}
  104. start={eventView.start}
  105. end={eventView.end}
  106. statsPeriod={eventView.statsPeriod}
  107. project={eventView.project}
  108. hideVitalThresholds
  109. hideDurationDetail
  110. queryExtras={queryExtras}
  111. />
  112. <SidebarSpacer />
  113. </Fragment>
  114. )}
  115. {!hasTransactionSummaryCleanupFlag && (
  116. <Fragment>
  117. <GuideAnchor target="user_misery" position="left">
  118. <SectionHeading>
  119. {t('User Misery')}
  120. <QuestionTooltip
  121. position="top"
  122. title={getTermHelp(organization, PerformanceTerm.USER_MISERY)}
  123. size="sm"
  124. />
  125. </SectionHeading>
  126. </GuideAnchor>
  127. {userMisery}
  128. </Fragment>
  129. )}
  130. <SidebarSpacer />
  131. </Fragment>
  132. );
  133. }
  134. const VitalsHeading = styled('div')`
  135. display: flex;
  136. justify-content: space-between;
  137. align-items: center;
  138. `;
  139. export default UserStats;