focusTabs.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  7. import useActiveReplayTab, {TabKey} from 'sentry/utils/replays/hooks/useActiveReplayTab';
  8. import {useLocation} from 'sentry/utils/useLocation';
  9. import useOrganization from 'sentry/utils/useOrganization';
  10. const ReplayTabs: Record<TabKey, string> = {
  11. console: t('Console'),
  12. dom: t('DOM Events'),
  13. network: t('Network'),
  14. trace: t('Trace'),
  15. issues: t('Issues'),
  16. memory: t('Memory'),
  17. };
  18. type Props = {className?: string};
  19. function FocusTabs({className}: Props) {
  20. const organization = useOrganization();
  21. const {pathname, query} = useLocation();
  22. const {getActiveTab, setActiveTab} = useActiveReplayTab();
  23. const activeTab = getActiveTab();
  24. const createTabChangeHandler = (tab: string) => (e: MouseEvent) => {
  25. e.preventDefault();
  26. setActiveTab(tab);
  27. trackAdvancedAnalyticsEvent('replay.details-tab-changed', {
  28. tab,
  29. organization,
  30. });
  31. };
  32. return (
  33. <ScrollableNavTabs underlined className={className}>
  34. {Object.entries(ReplayTabs).map(([tab, label]) => (
  35. <li key={tab} className={activeTab === tab ? 'active' : ''}>
  36. <a
  37. href={`${pathname}?${queryString.stringify({...query, t_main: tab})}`}
  38. onClick={createTabChangeHandler(tab)}
  39. >
  40. <span>{label}</span>
  41. </a>
  42. </li>
  43. ))}
  44. </ScrollableNavTabs>
  45. );
  46. }
  47. const ScrollableNavTabs = styled(NavTabs)`
  48. display: flex;
  49. flex-wrap: nowrap;
  50. overflow-y: hidden;
  51. overflow-x: auto;
  52. white-space: nowrap;
  53. `;
  54. export default FocusTabs;