userStats.tsx 4.0 KB

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