userStats.tsx 4.2 KB

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