demoSandboxButton.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import Button, {ButtonPropsWithoutAriaLabel} from 'sentry/components/button';
  2. import {Organization, SandboxData} from 'sentry/types';
  3. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. interface DemoSandboxButtonProps extends ButtonPropsWithoutAriaLabel {
  6. /**
  7. * The deep link scenario
  8. */
  9. scenario:
  10. | 'performance'
  11. | 'releases'
  12. | 'alerts'
  13. | 'discover'
  14. | 'dashboards'
  15. | 'projects'
  16. | 'oneDiscoverQuery'
  17. | 'oneIssue'
  18. | 'oneBreadcrumb'
  19. | 'oneStackTrace'
  20. | 'oneTransaction'
  21. | 'oneWebVitals'
  22. | 'oneTransactionSummary'
  23. | 'oneRelease';
  24. clientData?: SandboxData;
  25. /**
  26. * Matching on the error type or title
  27. */
  28. errorType?: string;
  29. /**
  30. * Which project we should link to in the sandbox
  31. */
  32. projectSlug?: 'react' | 'python' | 'ios' | 'android' | 'react-native';
  33. /**
  34. * Where is the component being used
  35. */
  36. source?: string;
  37. }
  38. /**
  39. * Renders a button that will kick off the sandbox around children
  40. * which should include be a button. If the sandbox is hidden,
  41. * don't render the children
  42. */
  43. function DemoSandboxButton({
  44. scenario,
  45. projectSlug,
  46. errorType,
  47. clientData,
  48. source,
  49. ...buttonProps
  50. }: DemoSandboxButtonProps): React.ReactElement {
  51. const organization: Organization = useOrganization();
  52. const url = new URL('https://try.sentry-demo.com/demo/start/');
  53. if (scenario) {
  54. url.searchParams.append('scenario', scenario);
  55. }
  56. if (projectSlug) {
  57. url.searchParams.append('projectSlug', projectSlug);
  58. }
  59. if (errorType) {
  60. url.searchParams.append('errorType', errorType);
  61. }
  62. // always skip adding email when coming from in-product
  63. const clientOptions: SandboxData = {
  64. skipEmail: true,
  65. acceptedTracking: true,
  66. ...clientData,
  67. };
  68. url.searchParams.append('client', JSON.stringify(clientOptions));
  69. return (
  70. <Button
  71. external
  72. href={url.toString()}
  73. onClick={() =>
  74. trackAdvancedAnalyticsEvent('growth.clicked_enter_sandbox', {
  75. scenario,
  76. organization,
  77. source,
  78. })
  79. }
  80. {...buttonProps}
  81. />
  82. );
  83. }
  84. export default DemoSandboxButton;