settingsNavigationGroup.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {SecondaryNav} from 'sentry/components/nav/secondary';
  2. import {trackAnalytics} from 'sentry/utils/analytics';
  3. import replaceRouterParams from 'sentry/utils/replaceRouterParams';
  4. import SettingsNavItem from 'sentry/views/settings/components/settingsNavItem';
  5. import type {NavigationGroupProps} from 'sentry/views/settings/types';
  6. function SettingsNavigationGroup(props: NavigationGroupProps) {
  7. const {organization, project, name, items} = props;
  8. const navLinks = items.map(({path, title, index, show, badge, id, recordAnalytics}) => {
  9. if (typeof show === 'function' && !show(props)) {
  10. return null;
  11. }
  12. if (typeof show !== 'undefined' && !show) {
  13. return null;
  14. }
  15. const badgeResult = typeof badge === 'function' ? badge(props) : null;
  16. const to = replaceRouterParams(path, {
  17. ...(organization ? {orgId: organization.slug} : {}),
  18. ...(project ? {projectId: project.slug} : {}),
  19. });
  20. const handleClick = () => {
  21. // only call the analytics event if the URL is changing
  22. if (recordAnalytics && to !== window.location.pathname && organization) {
  23. trackAnalytics('sidebar.item_clicked', {
  24. organization,
  25. project_id: project?.id,
  26. sidebar_item_id: id,
  27. dest: path,
  28. });
  29. }
  30. };
  31. return (
  32. <SettingsNavItem
  33. key={title}
  34. to={to}
  35. label={title}
  36. index={index}
  37. badge={badgeResult}
  38. id={id}
  39. onClick={handleClick}
  40. />
  41. );
  42. });
  43. if (!navLinks.some(link => link !== null)) {
  44. return null;
  45. }
  46. return <SecondaryNav.Section title={name}>{navLinks}</SecondaryNav.Section>;
  47. }
  48. export default SettingsNavigationGroup;