settingsNavigationGroup.tsx 2.2 KB

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