settingsNavigationGroup.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import styled from '@emotion/styled';
  2. import space from 'sentry/styles/space';
  3. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  4. import replaceRouterParams from 'sentry/utils/replaceRouterParams';
  5. import SettingsNavItem from 'sentry/views/settings/components/settingsNavItem';
  6. import {NavigationGroupProps} from 'sentry/views/settings/types';
  7. const SettingsNavigationGroup = (props: NavigationGroupProps) => {
  8. const {organization, project, name, items} = props;
  9. const navLinks = items.map(({path, title, index, show, badge, id, recordAnalytics}) => {
  10. if (typeof show === 'function' && !show(props)) {
  11. return null;
  12. }
  13. if (typeof show !== 'undefined' && !show) {
  14. return null;
  15. }
  16. const badgeResult = typeof badge === 'function' ? badge(props) : null;
  17. const to = replaceRouterParams(path, {
  18. ...(organization ? {orgId: organization.slug} : {}),
  19. ...(project ? {projectId: project.slug} : {}),
  20. });
  21. const handleClick = () => {
  22. // only call the analytics event if the URL is changing
  23. if (recordAnalytics && to !== window.location.pathname) {
  24. trackAnalyticsEvent({
  25. organization_id: organization ? organization.id : null,
  26. project_id: project && project.id,
  27. eventName: 'Sidebar Item Clicked',
  28. eventKey: 'sidebar.item_clicked',
  29. sidebar_item_id: id,
  30. dest: path,
  31. });
  32. }
  33. };
  34. return (
  35. <SettingsNavItem
  36. key={title}
  37. to={to}
  38. label={title}
  39. index={index}
  40. badge={badgeResult}
  41. id={id}
  42. onClick={handleClick}
  43. />
  44. );
  45. });
  46. if (!navLinks.some(link => link !== null)) {
  47. return null;
  48. }
  49. return (
  50. <NavSection data-test-id={name}>
  51. <SettingsHeading role="heading">{name}</SettingsHeading>
  52. {navLinks}
  53. </NavSection>
  54. );
  55. };
  56. const NavSection = styled('div')`
  57. margin-bottom: 20px;
  58. `;
  59. const SettingsHeading = styled('div')`
  60. color: ${p => p.theme.text};
  61. font-size: ${p => p.theme.fontSizeSmall};
  62. font-weight: 600;
  63. text-transform: uppercase;
  64. margin-bottom: ${space(0.5)};
  65. `;
  66. export default SettingsNavigationGroup;