settingsNavigationGroup.tsx 2.1 KB

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