focusTabs.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 {trackAnalytics} from 'sentry/utils/analytics';
  8. import useActiveReplayTab, {TabKey} from 'sentry/utils/replays/hooks/useActiveReplayTab';
  9. import {useLocation} from 'sentry/utils/useLocation';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. function getReplayTabs(): Record<TabKey, ReactNode> {
  12. return {
  13. [TabKey.CONSOLE]: t('Console'),
  14. [TabKey.NETWORK]: t('Network'),
  15. [TabKey.DOM]: t('DOM Events'),
  16. [TabKey.ERRORS]: (
  17. <Fragment>
  18. {t('Errors')} <FeatureBadge type="new" />
  19. </Fragment>
  20. ),
  21. [TabKey.MEMORY]: t('Memory'),
  22. [TabKey.TRACE]: t('Trace'),
  23. };
  24. }
  25. type Props = {
  26. className?: string;
  27. };
  28. function FocusTabs({className}: Props) {
  29. const organization = useOrganization();
  30. const {pathname, query} = useLocation();
  31. const {getActiveTab, setActiveTab} = useActiveReplayTab();
  32. const activeTab = getActiveTab();
  33. return (
  34. <ScrollableTabs className={className} underlined>
  35. {Object.entries(getReplayTabs()).map(([tab, label]) =>
  36. label ? (
  37. <ListLink
  38. data-test-id={`replay-details-${tab}-btn`}
  39. key={tab}
  40. isActive={() => tab === activeTab}
  41. to={`${pathname}?${queryString.stringify({...query, t_main: tab})}`}
  42. onClick={e => {
  43. e.preventDefault();
  44. setActiveTab(tab);
  45. trackAnalytics('replay.details-tab-changed', {
  46. tab,
  47. organization,
  48. });
  49. }}
  50. >
  51. {label}
  52. </ListLink>
  53. ) : null
  54. )}
  55. </ScrollableTabs>
  56. );
  57. }
  58. export default FocusTabs;