tabs.tsx 1.5 KB

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