focusTabs.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {Fragment, ReactNode} from 'react';
  2. import queryString from 'query-string';
  3. import FeatureBadge from 'sentry/components/featureBadge';
  4. import ListLink from 'sentry/components/links/listLink';
  5. import ScrollableTabs from 'sentry/components/replays/scrollableTabs';
  6. import {t} from 'sentry/locale';
  7. import type {Organization} from 'sentry/types';
  8. import {trackAnalytics} from 'sentry/utils/analytics';
  9. import useActiveReplayTab, {TabKey} from 'sentry/utils/replays/hooks/useActiveReplayTab';
  10. import {useLocation} from 'sentry/utils/useLocation';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. function getReplayTabs(organization: Organization): Record<TabKey, ReactNode> {
  13. const hasPerfTab = organization.features.includes('session-replay-trace-table');
  14. return {
  15. [TabKey.CONSOLE]: t('Console'),
  16. [TabKey.NETWORK]: t('Network'),
  17. [TabKey.ERRORS]: (
  18. <Fragment>
  19. {t('Errors')} <FeatureBadge type="new" />
  20. </Fragment>
  21. ),
  22. [TabKey.TRACE]: t('Trace'),
  23. [TabKey.PERF]: hasPerfTab ? (
  24. <Fragment>
  25. {t('Perf')} <FeatureBadge type="alpha" />
  26. </Fragment>
  27. ) : null,
  28. [TabKey.DOM]: t('DOM Events'),
  29. [TabKey.MEMORY]: t('Memory'),
  30. };
  31. }
  32. type Props = {
  33. className?: string;
  34. };
  35. function FocusTabs({className}: Props) {
  36. const organization = useOrganization();
  37. const {pathname, query} = useLocation();
  38. const {getActiveTab, setActiveTab} = useActiveReplayTab();
  39. const activeTab = getActiveTab();
  40. return (
  41. <ScrollableTabs className={className} underlined>
  42. {Object.entries(getReplayTabs(organization)).map(([tab, label]) =>
  43. label ? (
  44. <ListLink
  45. data-test-id={`replay-details-${tab}-btn`}
  46. key={tab}
  47. isActive={() => tab === activeTab}
  48. to={`${pathname}?${queryString.stringify({...query, t_main: tab})}`}
  49. onClick={e => {
  50. e.preventDefault();
  51. setActiveTab(tab);
  52. trackAnalytics('replay.details-tab-changed', {
  53. tab,
  54. organization,
  55. });
  56. }}
  57. >
  58. {label}
  59. </ListLink>
  60. ) : null
  61. )}
  62. </ScrollableTabs>
  63. );
  64. }
  65. export default FocusTabs;