focusTabs.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {MouseEvent} from 'react';
  2. import queryString from 'query-string';
  3. import NavTabs from 'sentry/components/navTabs';
  4. import {t} from 'sentry/locale';
  5. import useActiveReplayTab, {TabKey} from 'sentry/utils/replays/hooks/useActiveReplayTab';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. const ReplayTabs: Record<TabKey, string> = {
  8. console: t('Console'),
  9. dom: t('DOM Events'),
  10. network: t('Network'),
  11. trace: t('Trace'),
  12. issues: t('Issues'),
  13. memory: t('Memory'),
  14. };
  15. type Props = {};
  16. function FocusTabs({}: Props) {
  17. const {pathname, query} = useLocation();
  18. const {getActiveTab, setActiveTab} = useActiveReplayTab();
  19. const activeTab = getActiveTab();
  20. return (
  21. <NavTabs underlined>
  22. {Object.entries(ReplayTabs).map(([tab, label]) => (
  23. <li key={tab} className={activeTab === tab ? 'active' : ''}>
  24. <a
  25. href={`${pathname}?${queryString.stringify({...query, t_main: tab})}`}
  26. onClick={(e: MouseEvent) => {
  27. setActiveTab(tab);
  28. e.preventDefault();
  29. }}
  30. >
  31. <span>{label}</span>
  32. </a>
  33. </li>
  34. ))}
  35. </NavTabs>
  36. );
  37. }
  38. export default FocusTabs;