tabs.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import queryString from 'query-string';
  2. import ListLink from 'sentry/components/links/listLink';
  3. import ScrollableTabs from 'sentry/components/replays/scrollableTabs';
  4. import {t} from 'sentry/locale';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import useUrlParams from 'sentry/utils/useUrlParams';
  7. type Props = {
  8. className?: string;
  9. underlined?: boolean;
  10. };
  11. const TABS = {
  12. details: t('Details'),
  13. request: t('Request'),
  14. response: t('Response'),
  15. };
  16. export type TabKey = keyof typeof TABS;
  17. function NetworkRequestTabs({className, underlined = true}: Props) {
  18. const {pathname, query} = useLocation();
  19. const {getParamValue, setParamValue} = useUrlParams('n_detail_tab', 'details');
  20. const activeTab = getParamValue();
  21. return (
  22. <ScrollableTabs className={className} underlined={underlined}>
  23. {Object.entries(TABS).map(([tab, label]) => (
  24. <ListLink
  25. key={tab}
  26. isActive={() => tab === activeTab}
  27. to={`${pathname}?${queryString.stringify({...query, t_main: tab})}`}
  28. onClick={e => {
  29. e.preventDefault();
  30. setParamValue(tab);
  31. }}
  32. >
  33. {label}
  34. </ListLink>
  35. ))}
  36. </ScrollableTabs>
  37. );
  38. }
  39. export default NetworkRequestTabs;