settingsNavigationGroup.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import styled from '@emotion/styled';
  2. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  3. import replaceRouterParams from 'sentry/utils/replaceRouterParams';
  4. import SettingsNavItem from 'sentry/views/settings/components/settingsNavItem';
  5. import {NavigationGroupProps} from 'sentry/views/settings/types';
  6. const 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) {
  23. trackAnalyticsEvent({
  24. organization_id: organization ? organization.id : null,
  25. project_id: project && project.id,
  26. eventName: 'Sidebar Item Clicked',
  27. eventKey: 'sidebar.item_clicked',
  28. sidebar_item_id: id,
  29. dest: path,
  30. });
  31. }
  32. };
  33. return (
  34. <SettingsNavItem
  35. key={title}
  36. to={to}
  37. label={title}
  38. index={index}
  39. badge={badgeResult}
  40. id={id}
  41. onClick={handleClick}
  42. />
  43. );
  44. });
  45. if (!navLinks.some(link => link !== null)) {
  46. return null;
  47. }
  48. return (
  49. <NavSection data-test-id={name}>
  50. <SettingsHeading>{name}</SettingsHeading>
  51. {navLinks}
  52. </NavSection>
  53. );
  54. };
  55. const NavSection = styled('div')`
  56. margin-bottom: 20px;
  57. `;
  58. const SettingsHeading = styled('div')`
  59. color: ${p => p.theme.subText};
  60. font-size: 12px;
  61. font-weight: 600;
  62. text-transform: uppercase;
  63. margin-bottom: 20px;
  64. `;
  65. export default SettingsNavigationGroup;