sentryDocumentTitle.tsx 1.2 KB

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