1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import {Fragment, ReactNode} from 'react';
- import queryString from 'query-string';
- import FeatureBadge from 'sentry/components/featureBadge';
- import ListLink from 'sentry/components/links/listLink';
- import ScrollableTabs from 'sentry/components/replays/scrollableTabs';
- import {t} from 'sentry/locale';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import useActiveReplayTab, {TabKey} from 'sentry/utils/replays/hooks/useActiveReplayTab';
- import {useLocation} from 'sentry/utils/useLocation';
- import useOrganization from 'sentry/utils/useOrganization';
- function getReplayTabs(): Record<TabKey, ReactNode> {
- return {
- [TabKey.CONSOLE]: t('Console'),
- [TabKey.NETWORK]: t('Network'),
- [TabKey.DOM]: t('DOM Events'),
- [TabKey.ERRORS]: (
- <Fragment>
- {t('Errors')} <FeatureBadge type="new" />
- </Fragment>
- ),
- [TabKey.MEMORY]: t('Memory'),
- [TabKey.TRACE]: t('Trace'),
- };
- }
- type Props = {
- className?: string;
- };
- function FocusTabs({className}: Props) {
- const organization = useOrganization();
- const {pathname, query} = useLocation();
- const {getActiveTab, setActiveTab} = useActiveReplayTab();
- const activeTab = getActiveTab();
- return (
- <ScrollableTabs className={className} underlined>
- {Object.entries(getReplayTabs()).map(([tab, label]) =>
- label ? (
- <ListLink
- data-test-id={`replay-details-${tab}-btn`}
- key={tab}
- isActive={() => tab === activeTab}
- to={`${pathname}?${queryString.stringify({...query, t_main: tab})}`}
- onClick={e => {
- e.preventDefault();
- setActiveTab(tab);
- trackAnalytics('replay.details-tab-changed', {
- tab,
- organization,
- });
- }}
- >
- {label}
- </ListLink>
- ) : null
- )}
- </ScrollableTabs>
- );
- }
- export default FocusTabs;
|