tabs.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {useMemo} from 'react';
  2. import {TabList, Tabs} from 'sentry/components/tabs';
  3. import {t} from 'sentry/locale';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  7. interface Props {
  8. selected: 'replays' | 'selectors';
  9. }
  10. export default function ReplayTabs({selected}: Props) {
  11. const organization = useOrganization();
  12. const location = useLocation();
  13. const tabs = useMemo(
  14. () => [
  15. {
  16. key: 'replays',
  17. label: t('Replays'),
  18. pathname: normalizeUrl(`/organizations/${organization.slug}/replays/`),
  19. query: {...location.query, sort: undefined},
  20. },
  21. {
  22. key: 'selectors',
  23. label: t('Selectors'),
  24. pathname: normalizeUrl(`/organizations/${organization.slug}/replays/selectors/`),
  25. query: {...location.query, sort: '-count_dead_clicks'},
  26. },
  27. ],
  28. [organization.slug, location.query]
  29. );
  30. return (
  31. <Tabs value={selected}>
  32. <TabList hideBorder>
  33. {tabs.map(tab => (
  34. <TabList.Item
  35. key={tab.key}
  36. to={{
  37. ...location,
  38. pathname: tab.pathname,
  39. query: tab.query,
  40. }}
  41. >
  42. {tab.label}
  43. </TabList.Item>
  44. ))}
  45. </TabList>
  46. </Tabs>
  47. );
  48. }