focusTabs.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import type {ReactNode} from 'react';
  2. import ListLink from 'sentry/components/links/listLink';
  3. import ScrollableTabs from 'sentry/components/replays/scrollableTabs';
  4. import {t} from 'sentry/locale';
  5. import {trackAnalytics} from 'sentry/utils/analytics';
  6. import useActiveReplayTab, {TabKey} from 'sentry/utils/replays/hooks/useActiveReplayTab';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. function getReplayTabs({
  10. isVideoReplay,
  11. }: {
  12. isVideoReplay: boolean;
  13. }): Record<TabKey, ReactNode> {
  14. // For video replays, we hide the memory tab (not applicable for mobile)
  15. return {
  16. [TabKey.BREADCRUMBS]: t('Breadcrumbs'),
  17. [TabKey.CONSOLE]: t('Console'),
  18. [TabKey.NETWORK]: t('Network'),
  19. [TabKey.ERRORS]: t('Errors'),
  20. [TabKey.TRACE]: t('Trace'),
  21. [TabKey.MEMORY]: isVideoReplay ? null : t('Memory'),
  22. [TabKey.TAGS]: t('Tags'),
  23. };
  24. }
  25. type Props = {
  26. isVideoReplay: boolean;
  27. className?: string;
  28. };
  29. function FocusTabs({className, isVideoReplay}: Props) {
  30. const organization = useOrganization();
  31. const {pathname, query} = useLocation();
  32. const {getActiveTab, setActiveTab} = useActiveReplayTab({isVideoReplay});
  33. const activeTab = getActiveTab();
  34. return (
  35. <ScrollableTabs className={className} underlined>
  36. {Object.entries(getReplayTabs({isVideoReplay})).map(([tab, label]) =>
  37. label ? (
  38. <ListLink
  39. data-test-id={`replay-details-${tab}-btn`}
  40. key={tab}
  41. isActive={() => tab === activeTab}
  42. to={{pathname, query: {...query, t_main: tab}}}
  43. onClick={e => {
  44. e.preventDefault();
  45. setActiveTab(tab);
  46. trackAnalytics('replay.details-tab-changed', {
  47. tab,
  48. organization,
  49. mobile: isVideoReplay,
  50. });
  51. }}
  52. >
  53. {label}
  54. </ListLink>
  55. ) : null
  56. )}
  57. </ScrollableTabs>
  58. );
  59. }
  60. export default FocusTabs;