userStats.tsx 4.3 KB

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