firstEventIndicator.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import styled from '@emotion/styled';
  2. import {AnimatePresence, HTMLMotionProps, motion, Variants} from 'framer-motion';
  3. import {Button} from 'sentry/components/button';
  4. import {IconCheckmark} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import pulsingIndicatorStyles from 'sentry/styles/pulsingIndicator';
  7. import {space} from 'sentry/styles/space';
  8. import {Group} from 'sentry/types';
  9. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  10. import EventWaiter, {EventWaiterProps} from 'sentry/utils/eventWaiter';
  11. import testableTransition from 'sentry/utils/testableTransition';
  12. type RenderProps = {
  13. firstEventButton: React.ReactNode;
  14. indicator: React.ReactNode;
  15. };
  16. interface FirstEventIndicatorProps extends Omit<EventWaiterProps, 'children' | 'api'> {
  17. children: (props: RenderProps) => React.ReactNode;
  18. }
  19. const FirstEventIndicator = ({children, ...props}: FirstEventIndicatorProps) => (
  20. <EventWaiter {...props}>
  21. {({firstIssue}) =>
  22. children({
  23. indicator: <Indicator firstIssue={firstIssue} {...props} />,
  24. firstEventButton: (
  25. <Button
  26. title={t("You'll need to send your first error to continue")}
  27. tooltipProps={{disabled: !!firstIssue}}
  28. disabled={!firstIssue}
  29. priority="primary"
  30. onClick={() =>
  31. trackAdvancedAnalyticsEvent('growth.onboarding_take_to_error', {
  32. organization: props.organization,
  33. })
  34. }
  35. to={`/organizations/${props.organization.slug}/issues/${
  36. firstIssue && firstIssue !== true && 'id' in firstIssue
  37. ? `${firstIssue.id}/`
  38. : ''
  39. }?referrer=onboarding-first-event-indicator`}
  40. >
  41. {t('Take me to my error')}
  42. </Button>
  43. ),
  44. })
  45. }
  46. </EventWaiter>
  47. );
  48. interface IndicatorProps extends Omit<EventWaiterProps, 'children' | 'api'> {
  49. firstIssue: null | boolean | Group;
  50. }
  51. const Indicator = ({firstIssue}: IndicatorProps) => (
  52. <Container>
  53. <AnimatePresence>
  54. {!firstIssue ? <Waiting key="waiting" /> : <Success key="received" />}
  55. </AnimatePresence>
  56. </Container>
  57. );
  58. const Container = styled('div')`
  59. display: grid;
  60. grid-template-columns: 1fr;
  61. justify-content: right;
  62. `;
  63. const StatusWrapper = styled(motion.div)`
  64. display: grid;
  65. grid-template-columns: 1fr max-content;
  66. gap: ${space(1)};
  67. align-items: center;
  68. font-size: ${p => p.theme.fontSizeMedium};
  69. /* Keep the wrapper in the parent grids first cell for transitions */
  70. grid-column: 1;
  71. grid-row: 1;
  72. `;
  73. StatusWrapper.defaultProps = {
  74. initial: 'initial',
  75. animate: 'animate',
  76. exit: 'exit',
  77. variants: {
  78. initial: {opacity: 0, y: -10},
  79. animate: {
  80. opacity: 1,
  81. y: 0,
  82. transition: testableTransition({when: 'beforeChildren', staggerChildren: 0.35}),
  83. },
  84. exit: {opacity: 0, y: 10},
  85. },
  86. };
  87. const Waiting = (props: HTMLMotionProps<'div'>) => (
  88. <StatusWrapper {...props}>
  89. <AnimatedText>{t('Waiting to receive first event to continue')}</AnimatedText>
  90. <WaitingIndicator />
  91. </StatusWrapper>
  92. );
  93. const Success = (props: HTMLMotionProps<'div'>) => (
  94. <StatusWrapper {...props}>
  95. <AnimatedText>{t('Event was received!')}</AnimatedText>
  96. <ReceivedIndicator />
  97. </StatusWrapper>
  98. );
  99. const indicatorAnimation: Variants = {
  100. initial: {opacity: 0, y: -10},
  101. animate: {opacity: 1, y: 0},
  102. exit: {opacity: 0, y: 10},
  103. };
  104. const AnimatedText = styled(motion.div)``;
  105. AnimatedText.defaultProps = {
  106. variants: indicatorAnimation,
  107. transition: testableTransition(),
  108. };
  109. const WaitingIndicator = styled(motion.div)`
  110. margin: 0 6px;
  111. ${pulsingIndicatorStyles};
  112. `;
  113. WaitingIndicator.defaultProps = {
  114. variants: indicatorAnimation,
  115. transition: testableTransition(),
  116. };
  117. const ReceivedIndicator = styled(IconCheckmark)`
  118. color: #fff;
  119. background: ${p => p.theme.green300};
  120. border-radius: 50%;
  121. padding: 3px;
  122. margin: 0 ${space(0.25)};
  123. `;
  124. ReceivedIndicator.defaultProps = {
  125. size: 'sm',
  126. };
  127. export {Indicator};
  128. export default FirstEventIndicator;