trendsHeader.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  2. import * as Layout from 'sentry/components/layouts/thirds';
  3. import {t} from 'sentry/locale';
  4. import {decodeScalar} from 'sentry/utils/queryString';
  5. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. import {AiHeader} from 'sentry/views/insights/pages/ai/aiPageHeader';
  9. import {BackendHeader} from 'sentry/views/insights/pages/backend/backendPageHeader';
  10. import {FrontendHeader} from 'sentry/views/insights/pages/frontend/frontendPageHeader';
  11. import {MobileHeader} from 'sentry/views/insights/pages/mobile/mobilePageHeader';
  12. import {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';
  13. import {getPerformanceLandingUrl} from 'sentry/views/performance/utils';
  14. export function TrendsHeader() {
  15. const location = useLocation();
  16. const organization = useOrganization();
  17. const {view, isInDomainView} = useDomainViewFilters();
  18. const headerTitle = t('Trends');
  19. const getPerformanceLink = () => {
  20. const newQuery = {
  21. ...location.query,
  22. };
  23. const query = decodeScalar(location.query.query, '');
  24. const conditions = new MutableSearch(query);
  25. // This stops errors from occurring when navigating to other views since we are appending aggregates to the trends view
  26. conditions.removeFilter('tpm()');
  27. conditions.removeFilter('confidence()');
  28. conditions.removeFilter('transaction.duration');
  29. newQuery.query = conditions.formatString();
  30. return {
  31. pathname: getPerformanceLandingUrl(organization),
  32. query: newQuery,
  33. };
  34. };
  35. if (!isInDomainView) {
  36. return (
  37. <Layout.Header>
  38. <Layout.HeaderContent>
  39. <Breadcrumbs
  40. crumbs={[
  41. {
  42. label: t('Performance'),
  43. to: getPerformanceLink(),
  44. },
  45. {
  46. label: headerTitle,
  47. },
  48. ]}
  49. />
  50. <Layout.Title>{headerTitle}</Layout.Title>
  51. </Layout.HeaderContent>
  52. </Layout.Header>
  53. );
  54. }
  55. const headerProps = {
  56. headerTitle,
  57. breadcrumbs: [{label: headerTitle, to: undefined}],
  58. };
  59. if (view === 'ai') {
  60. return <AiHeader {...headerProps} />;
  61. }
  62. if (view === 'frontend') {
  63. return <FrontendHeader {...headerProps} />;
  64. }
  65. if (view === 'mobile') {
  66. return <MobileHeader {...headerProps} />;
  67. }
  68. return <BackendHeader {...headerProps} />;
  69. }