tabs.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {useMemo} from 'react';
  2. import * as Layout from 'sentry/components/layouts/thirds';
  3. import {TabList} from 'sentry/components/tabs';
  4. import {t} from 'sentry/locale';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. import useAllMobileProj from 'sentry/views/replays/detail/useAllMobileProj';
  8. import {makeReplaysPathname} from 'sentry/views/replays/pathnames';
  9. interface Props {
  10. selected: 'replays' | 'selectors';
  11. }
  12. export default function ReplayTabs({selected}: Props) {
  13. const organization = useOrganization();
  14. const location = useLocation();
  15. const {allMobileProj} = useAllMobileProj({});
  16. const replaysPathname = makeReplaysPathname({
  17. path: '/',
  18. organization,
  19. });
  20. const selectorsPathname = makeReplaysPathname({
  21. path: '/selectors/',
  22. organization,
  23. });
  24. const tabs = useMemo(
  25. () => [
  26. {
  27. key: 'replays',
  28. label: t('Replays'),
  29. pathname: replaysPathname,
  30. query: {...location.query, sort: undefined},
  31. },
  32. {
  33. key: 'selectors',
  34. label: t('Selectors'),
  35. pathname: selectorsPathname,
  36. query: {...location.query, sort: '-count_dead_clicks'},
  37. },
  38. ],
  39. [location.query, replaysPathname, selectorsPathname]
  40. );
  41. return (
  42. <Layout.HeaderTabs value={selected}>
  43. <TabList hideBorder>
  44. {tabs.map(tab => (
  45. <TabList.Item
  46. key={tab.key}
  47. to={{
  48. ...location,
  49. pathname: tab.pathname,
  50. query: tab.query,
  51. }}
  52. disabled={tab.key === 'selectors' && allMobileProj}
  53. >
  54. {tab.label}
  55. </TabList.Item>
  56. ))}
  57. </TabList>
  58. </Layout.HeaderTabs>
  59. );
  60. }