focusTabs.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. key={tab}
  39. isActive={() => tab === activeTab}
  40. to={`${pathname}?${queryString.stringify({...query, t_main: tab})}`}
  41. onClick={e => {
  42. e.preventDefault();
  43. setActiveTab(tab);
  44. trackAnalytics('replay.details-tab-changed', {
  45. tab,
  46. organization,
  47. });
  48. }}
  49. >
  50. {label}
  51. </ListLink>
  52. ) : null
  53. )}
  54. </ScrollableTabs>
  55. );
  56. }
  57. export default FocusTabs;