focusTabs.tsx 1.4 KB

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