loaderScript.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {Fragment} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import FieldGroup from 'sentry/components/forms/fieldGroup';
  5. import FieldHelp from 'sentry/components/forms/fieldGroup/fieldHelp';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import Link from 'sentry/components/links/link';
  8. import TextCopyInput from 'sentry/components/textCopyInput';
  9. import {t, tct} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import type {ProjectKey} from 'sentry/types/project';
  12. import getDynamicText from 'sentry/utils/getDynamicText';
  13. import recreateRoute from 'sentry/utils/recreateRoute';
  14. type Props = {
  15. projectKey: ProjectKey;
  16. } & Pick<RouteComponentProps<{}, {}>, 'routes' | 'location' | 'params'>;
  17. export function LoaderScript({projectKey, routes, params, location}: Props) {
  18. const loaderLink = getDynamicText({
  19. value: projectKey.dsn.cdn,
  20. fixed: '__JS_SDK_LOADER_URL__',
  21. });
  22. const editUrl = recreateRoute(`${projectKey.id}/`, {routes, params, location});
  23. return (
  24. <Fragment>
  25. <FieldGroup
  26. label={t('Loader Script')}
  27. help={tct(
  28. 'Copy this script into your website to setup your JavaScript SDK without any additional configuration. [link]',
  29. {
  30. link: (
  31. <ExternalLink href="https://docs.sentry.io/platforms/javascript/install/lazy-load-sentry/">
  32. {t(' What does the script provide?')}
  33. </ExternalLink>
  34. ),
  35. }
  36. )}
  37. inline={false}
  38. flexibleControlStateSize
  39. >
  40. <TextCopyInput aria-label={t('Loader Script')}>
  41. {`<script src='${loaderLink}' crossorigin="anonymous"></script>`}
  42. </TextCopyInput>
  43. <HelpFooter>
  44. {tct(
  45. 'You can [configureLink:configure] the Loader Script to enable/disable Performance, Replay, and more.',
  46. {
  47. configureLink: <Link to={editUrl} />,
  48. }
  49. )}
  50. </HelpFooter>
  51. </FieldGroup>
  52. </Fragment>
  53. );
  54. }
  55. const HelpFooter = styled(FieldHelp)`
  56. margin-top: ${space(1)};
  57. `;