firstEventIndicator.tsx 4.1 KB

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