powerFeatureHovercard.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/core/button';
  4. import {Hovercard} from 'sentry/components/hovercard';
  5. import {t} from 'sentry/locale';
  6. import type {Organization} from 'sentry/types/organization';
  7. import withOrganization from 'sentry/utils/withOrganization';
  8. import {openUpsellModal} from 'getsentry/actionCreators/modal';
  9. import PlanFeature from 'getsentry/components/features/planFeature';
  10. import withSubscription from 'getsentry/components/withSubscription';
  11. import type {Subscription} from 'getsentry/types';
  12. import {PlanTier} from 'getsentry/types';
  13. import {displayPlanName} from 'getsentry/utils/billing';
  14. import trackGetsentryAnalytics from 'getsentry/utils/trackGetsentryAnalytics';
  15. type Props = {
  16. /**
  17. * The set of features that are required for this feature. Used to
  18. * determine which plan is required for the feature.
  19. *
  20. * NOTE: If the user has all features the hovercard will NOT be hidden. It
  21. * is up to the parent component to decide whether this should be rendered.
  22. */
  23. features: Organization['features'];
  24. organization: Organization;
  25. subscription: Subscription;
  26. children?: React.ReactNode;
  27. containerClassName?: string;
  28. containerDisplayMode?: React.ComponentProps<
  29. typeof StyledHovercard
  30. >['containerDisplayMode'];
  31. /**
  32. * The key passed to analytics when clicking learn more, as well as the key
  33. * used as the source when opening the landing modal.
  34. */
  35. id?: string;
  36. /**
  37. * When enabled the hovercard will indicate that *some* features will
  38. * require an upgraded plan.
  39. */
  40. partial?: boolean;
  41. upsellDefaultSelection?: string;
  42. };
  43. class PowerFeatureHovercard extends Component<Props> {
  44. recordAnalytics() {
  45. const {id, organization, subscription} = this.props;
  46. trackGetsentryAnalytics('power_icon.clicked', {
  47. organization,
  48. subscription,
  49. source: id,
  50. });
  51. }
  52. handleClick = (e: React.MouseEvent) => {
  53. e.preventDefault();
  54. const {organization, id} = this.props;
  55. this.recordAnalytics();
  56. openUpsellModal({
  57. organization,
  58. source: id ?? '',
  59. defaultSelection: this.props.upsellDefaultSelection,
  60. });
  61. };
  62. render() {
  63. const {
  64. containerClassName,
  65. containerDisplayMode,
  66. organization,
  67. subscription,
  68. partial,
  69. features,
  70. children,
  71. } = this.props;
  72. const hoverBody = (
  73. <PlanFeature features={features} {...{organization, subscription}}>
  74. {({plan, tierChange}) => {
  75. let planName = displayPlanName(plan);
  76. if (tierChange === PlanTier.AM1) {
  77. planName = `Performance ${planName}`;
  78. }
  79. return (
  80. <HovercardBody data-test-id="power-hovercard">
  81. <Text>
  82. {partial
  83. ? t('Better With %s Plan', planName)
  84. : t('Requires %s Plan', planName)}
  85. </Text>
  86. <UpsellModalButton
  87. priority="primary"
  88. size="sm"
  89. onClick={this.handleClick}
  90. data-test-id="power-learn-more"
  91. >
  92. {t('Learn More')}
  93. </UpsellModalButton>
  94. </HovercardBody>
  95. );
  96. }}
  97. </PlanFeature>
  98. );
  99. return (
  100. <StyledHovercard
  101. containerClassName={containerClassName}
  102. containerDisplayMode={containerDisplayMode}
  103. bodyClassName="power-icon"
  104. body={hoverBody}
  105. position="right"
  106. delay={200}
  107. >
  108. {children}
  109. </StyledHovercard>
  110. );
  111. }
  112. }
  113. const UpsellModalButton = styled(Button)`
  114. height: auto;
  115. border-radius: 0 ${p => p.theme.borderRadius} ${p => p.theme.borderRadius} 0;
  116. white-space: pre;
  117. margin-top: -1px;
  118. margin-bottom: -1px;
  119. margin-right: -1px;
  120. box-shadow: none;
  121. `;
  122. const HovercardBody = styled('div')`
  123. display: flex;
  124. justify-content: space-between;
  125. `;
  126. const StyledHovercard = styled(Hovercard)`
  127. width: auto;
  128. border-radius: ${p => p.theme.borderRadius};
  129. .power-icon {
  130. padding: 0;
  131. align-items: center;
  132. }
  133. `;
  134. const Text = styled('span')`
  135. margin: 10px;
  136. font-size: 14px;
  137. white-space: pre;
  138. `;
  139. export default withOrganization(
  140. withSubscription(PowerFeatureHovercard, {noLoader: true})
  141. );