123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import styled from '@emotion/styled';
- import {space} from 'sentry/styles/space';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import replaceRouterParams from 'sentry/utils/replaceRouterParams';
- import {normalizeUrl} from 'sentry/utils/withDomainRequired';
- import SettingsNavItem from 'sentry/views/settings/components/settingsNavItem';
- import type {NavigationGroupProps} from 'sentry/views/settings/types';
- function SettingsNavigationGroup(props: NavigationGroupProps) {
- const {organization, project, name, items} = props;
- const navLinks = items.map(({path, title, index, show, badge, id, recordAnalytics}) => {
- if (typeof show === 'function' && !show(props)) {
- return null;
- }
- if (typeof show !== 'undefined' && !show) {
- return null;
- }
- const badgeResult = typeof badge === 'function' ? badge(props) : null;
- const to = replaceRouterParams(path, {
- ...(organization ? {orgId: organization.slug} : {}),
- ...(project ? {projectId: project.slug} : {}),
- });
- const handleClick = () => {
- // only call the analytics event if the URL is changing
- if (recordAnalytics && to !== window.location.pathname && organization) {
- trackAnalytics('sidebar.item_clicked', {
- organization,
- project_id: project && project.id,
- sidebar_item_id: id,
- dest: path,
- });
- }
- };
- return (
- <SettingsNavItem
- key={title}
- to={normalizeUrl(to)}
- label={title}
- index={index}
- badge={badgeResult}
- id={id}
- onClick={handleClick}
- />
- );
- });
- if (!navLinks.some(link => link !== null)) {
- return null;
- }
- return (
- <NavSection data-test-id={name}>
- <SettingsHeading role="heading">{name}</SettingsHeading>
- {navLinks}
- </NavSection>
- );
- }
- const NavSection = styled('div')`
- margin-bottom: 20px;
- `;
- const SettingsHeading = styled('div')`
- color: ${p => p.theme.text};
- font-size: ${p => p.theme.fontSizeSmall};
- font-weight: 600;
- text-transform: uppercase;
- margin-bottom: ${space(0.5)};
- `;
- export default SettingsNavigationGroup;
|