focusTabs.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 {Organization} from 'sentry/types';
  8. import {trackAnalytics} from 'sentry/utils/analytics';
  9. import useActiveReplayTab, {TabKey} from 'sentry/utils/replays/hooks/useActiveReplayTab';
  10. import {useLocation} from 'sentry/utils/useLocation';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. function getReplayTabs(organization: Organization): Record<TabKey, ReactNode> {
  13. const hasReplayNetworkDetails = organization.features.includes(
  14. 'session-replay-network-details'
  15. );
  16. const networkLabel = hasReplayNetworkDetails ? (
  17. <Fragment>
  18. {t('Network')} <FeatureBadge type="new" />
  19. </Fragment>
  20. ) : (
  21. t('Network')
  22. );
  23. return {
  24. [TabKey.console]: t('Console'),
  25. [TabKey.network]: networkLabel,
  26. [TabKey.dom]: t('DOM Events'),
  27. [TabKey.issues]: t('Issues'),
  28. [TabKey.memory]: t('Memory'),
  29. [TabKey.trace]: t('Trace'),
  30. };
  31. }
  32. type Props = {
  33. className?: string;
  34. };
  35. function FocusTabs({className}: Props) {
  36. const organization = useOrganization();
  37. const {pathname, query} = useLocation();
  38. const {getActiveTab, setActiveTab} = useActiveReplayTab();
  39. const activeTab = getActiveTab();
  40. return (
  41. <ScrollableTabs className={className} underlined>
  42. {Object.entries(getReplayTabs(organization)).map(([tab, label]) => (
  43. <ListLink
  44. key={tab}
  45. isActive={() => tab === activeTab}
  46. to={`${pathname}?${queryString.stringify({...query, t_main: tab})}`}
  47. onClick={e => {
  48. e.preventDefault();
  49. setActiveTab(tab);
  50. trackAnalytics('replay.details-tab-changed', {
  51. tab,
  52. organization,
  53. });
  54. }}
  55. >
  56. {label}
  57. </ListLink>
  58. ))}
  59. </ScrollableTabs>
  60. );
  61. }
  62. export default FocusTabs;