sentryDocumentTitle.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import DocumentTitle from 'react-document-title';
  2. type Props = {
  3. children?: React.ReactChild;
  4. /**
  5. * Should the ` - Sentry` suffix be excluded?
  6. */
  7. noSuffix?: boolean;
  8. /**
  9. * The organization slug to show in the title
  10. */
  11. orgSlug?: string;
  12. /**
  13. * The project slug to show in the title.
  14. */
  15. projectSlug?: string;
  16. /**
  17. * This string will be shown at the very front of the title
  18. */
  19. title?: string;
  20. };
  21. /**
  22. * Assigns the document title. The deepest nested version of this title will be
  23. * the one which is assigned.
  24. */
  25. function SentryDocumentTitle({
  26. title = '',
  27. orgSlug,
  28. projectSlug,
  29. noSuffix,
  30. children,
  31. }: Props) {
  32. function getPageTitle() {
  33. if (orgSlug && projectSlug) {
  34. return `${title} - ${orgSlug} - ${projectSlug}`;
  35. }
  36. if (orgSlug) {
  37. return `${title} - ${orgSlug}`;
  38. }
  39. if (projectSlug) {
  40. return `${title} - ${projectSlug}`;
  41. }
  42. return title;
  43. }
  44. const pageTitle = getPageTitle();
  45. const documentTitle = noSuffix
  46. ? pageTitle
  47. : pageTitle !== ''
  48. ? `${pageTitle} - Sentry`
  49. : 'Sentry';
  50. return <DocumentTitle title={documentTitle}>{children}</DocumentTitle>;
  51. }
  52. export default SentryDocumentTitle;