index.tsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. import {Fragment, useCallback, useContext, useEffect} from 'react';
  2. import {css} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import {hideSidebar, showSidebar} from 'sentry/actionCreators/preferences';
  5. import Feature from 'sentry/components/acl/feature';
  6. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  7. import {Chevron} from 'sentry/components/chevron';
  8. import FeedbackOnboardingSidebar from 'sentry/components/feedback/feedbackOnboarding/sidebar';
  9. import Hook from 'sentry/components/hook';
  10. import {OnboardingContext} from 'sentry/components/onboarding/onboardingContext';
  11. import {getMergedTasks} from 'sentry/components/onboardingWizard/taskConfig';
  12. import PerformanceOnboardingSidebar from 'sentry/components/performanceOnboarding/sidebar';
  13. import ReplaysOnboardingSidebar from 'sentry/components/replaysOnboarding/sidebar';
  14. import {
  15. ExpandedContext,
  16. ExpandedContextProvider,
  17. } from 'sentry/components/sidebar/expandedContextProvider';
  18. import {isDone} from 'sentry/components/sidebar/utils';
  19. import {
  20. IconDashboard,
  21. IconGraph,
  22. IconIssues,
  23. IconLightning,
  24. IconMegaphone,
  25. IconPlay,
  26. IconProfiling,
  27. IconProject,
  28. IconReleases,
  29. IconSettings,
  30. IconSiren,
  31. IconStats,
  32. IconSupport,
  33. IconTelescope,
  34. IconTimer,
  35. } from 'sentry/icons';
  36. import {IconRobot} from 'sentry/icons/iconRobot';
  37. import {t} from 'sentry/locale';
  38. import ConfigStore from 'sentry/stores/configStore';
  39. import DemoWalkthroughStore from 'sentry/stores/demoWalkthroughStore';
  40. import HookStore from 'sentry/stores/hookStore';
  41. import PreferencesStore from 'sentry/stores/preferencesStore';
  42. import SidebarPanelStore from 'sentry/stores/sidebarPanelStore';
  43. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  44. import {space} from 'sentry/styles/space';
  45. import type {Organization} from 'sentry/types/organization';
  46. import {isDemoWalkthrough} from 'sentry/utils/demoMode';
  47. import {getDiscoverLandingUrl} from 'sentry/utils/discover/urls';
  48. import {isActiveSuperuser} from 'sentry/utils/isActiveSuperuser';
  49. import {hasMetricsSidebarItem} from 'sentry/utils/metrics/features';
  50. import theme from 'sentry/utils/theme';
  51. import {useLocation} from 'sentry/utils/useLocation';
  52. import useMedia from 'sentry/utils/useMedia';
  53. import useOrganization from 'sentry/utils/useOrganization';
  54. import useProjects from 'sentry/utils/useProjects';
  55. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  56. import MetricsOnboardingSidebar from 'sentry/views/metrics/ddmOnboarding/sidebar';
  57. import {
  58. MODULE_TITLE as CACHE_MODULE_TITLE,
  59. releaseLevelAsBadgeProps as CacheModuleBadgeProps,
  60. } from 'sentry/views/performance/cache/settings';
  61. import {
  62. MODULE_TITLE as HTTP_MODULE_TITLE,
  63. releaseLevelAsBadgeProps as HTTPModuleBadgeProps,
  64. } from 'sentry/views/performance/http/settings';
  65. import {ProfilingOnboardingSidebar} from '../profiling/ProfilingOnboarding/profilingOnboardingSidebar';
  66. import Broadcasts from './broadcasts';
  67. import SidebarHelp from './help';
  68. import OnboardingStatus from './onboardingStatus';
  69. import ServiceIncidents from './serviceIncidents';
  70. import {SidebarAccordion} from './sidebarAccordion';
  71. import SidebarDropdown from './sidebarDropdown';
  72. import SidebarItem from './sidebarItem';
  73. import type {SidebarOrientation} from './types';
  74. import {SidebarPanelKey} from './types';
  75. function activatePanel(panel: SidebarPanelKey) {
  76. SidebarPanelStore.activatePanel(panel);
  77. }
  78. function togglePanel(panel: SidebarPanelKey) {
  79. SidebarPanelStore.togglePanel(panel);
  80. }
  81. function hidePanel(hash?: string) {
  82. SidebarPanelStore.hidePanel(hash);
  83. }
  84. function useOpenOnboardingSidebar(organization?: Organization) {
  85. const onboardingContext = useContext(OnboardingContext);
  86. const {projects: project} = useProjects();
  87. const location = useLocation();
  88. const openOnboardingSidebar = (() => {
  89. if (location?.hash === '#welcome') {
  90. if (organization && !ConfigStore.get('demoMode')) {
  91. const tasks = getMergedTasks({
  92. organization,
  93. projects: project,
  94. onboardingContext,
  95. });
  96. const allDisplayedTasks = tasks
  97. .filter(task => task.display)
  98. .filter(task => !task.renderCard);
  99. const doneTasks = allDisplayedTasks.filter(isDone);
  100. return !(doneTasks.length >= allDisplayedTasks.length);
  101. }
  102. return true;
  103. }
  104. return false;
  105. })();
  106. useEffect(() => {
  107. if (openOnboardingSidebar) {
  108. activatePanel(SidebarPanelKey.ONBOARDING_WIZARD);
  109. }
  110. }, [openOnboardingSidebar]);
  111. }
  112. function Sidebar() {
  113. const location = useLocation();
  114. const preferences = useLegacyStore(PreferencesStore);
  115. const activePanel = useLegacyStore(SidebarPanelStore);
  116. const organization = useOrganization({allowNull: true});
  117. const {shouldAccordionFloat} = useContext(ExpandedContext);
  118. const collapsed = !!preferences.collapsed;
  119. const horizontal = useMedia(`(max-width: ${theme.breakpoints.medium})`);
  120. // Avoid showing superuser UI on self-hosted instances
  121. const showSuperuserWarning = () => {
  122. return isActiveSuperuser() && !ConfigStore.get('isSelfHosted');
  123. };
  124. // Avoid showing superuser UI on certain organizations
  125. const isExcludedOrg = () => {
  126. return HookStore.get('component:superuser-warning-excluded')[0]?.(organization);
  127. };
  128. useOpenOnboardingSidebar();
  129. const toggleCollapse = useCallback(() => {
  130. if (collapsed) {
  131. showSidebar();
  132. } else {
  133. hideSidebar();
  134. }
  135. }, [collapsed]);
  136. // Close panel on any navigation
  137. useEffect(() => void hidePanel(), [location?.pathname]);
  138. // Add classname to body
  139. useEffect(() => {
  140. const bcl = document.body.classList;
  141. bcl.add('body-sidebar');
  142. return () => bcl.remove('body-sidebar');
  143. }, []);
  144. useEffect(() => {
  145. Object.values(SidebarPanelKey).forEach(key => {
  146. if (location?.hash === `#sidebar-${key}`) {
  147. togglePanel(key);
  148. }
  149. });
  150. }, [location?.hash]);
  151. // Add sidebar collapse classname to body
  152. useEffect(() => {
  153. const bcl = document.body.classList;
  154. if (collapsed) {
  155. bcl.add('collapsed');
  156. } else {
  157. bcl.remove('collapsed');
  158. }
  159. return () => bcl.remove('collapsed');
  160. }, [collapsed]);
  161. const hasPanel = !!activePanel;
  162. const hasOrganization = !!organization;
  163. const orientation: SidebarOrientation = horizontal ? 'top' : 'left';
  164. const sidebarItemProps = {
  165. orientation,
  166. collapsed,
  167. hasPanel,
  168. organization,
  169. };
  170. const sidebarAnchor = isDemoWalkthrough() ? (
  171. <GuideAnchor target="projects" disabled={!DemoWalkthroughStore.get('sidebar')}>
  172. {t('Projects')}
  173. </GuideAnchor>
  174. ) : (
  175. <GuideAnchor target="projects">{t('Projects')}</GuideAnchor>
  176. );
  177. const projects = hasOrganization && (
  178. <SidebarItem
  179. {...sidebarItemProps}
  180. index
  181. icon={<IconProject />}
  182. label={sidebarAnchor}
  183. to={`/organizations/${organization.slug}/projects/`}
  184. id="projects"
  185. />
  186. );
  187. const issues = hasOrganization && (
  188. <SidebarItem
  189. {...sidebarItemProps}
  190. icon={<IconIssues />}
  191. label={<GuideAnchor target="issues">{t('Issues')}</GuideAnchor>}
  192. to={`/organizations/${organization.slug}/issues/`}
  193. search="?referrer=sidebar"
  194. id="issues"
  195. />
  196. );
  197. const discover2 = hasOrganization && (
  198. <Feature
  199. hookName="feature-disabled:discover2-sidebar-item"
  200. features="discover-basic"
  201. organization={organization}
  202. >
  203. <SidebarItem
  204. {...sidebarItemProps}
  205. icon={<IconTelescope />}
  206. label={<GuideAnchor target="discover">{t('Discover')}</GuideAnchor>}
  207. to={getDiscoverLandingUrl(organization)}
  208. id="discover-v2"
  209. />
  210. </Feature>
  211. );
  212. const performance = hasOrganization && (
  213. <Feature
  214. hookName="feature-disabled:performance-sidebar-item"
  215. features="performance-view"
  216. organization={organization}
  217. >
  218. {(() => {
  219. // If Database View or Web Vitals View is enabled, show a Performance accordion with a Database and/or Web Vitals sub-item
  220. if (
  221. organization.features.includes('spans-first-ui') ||
  222. organization.features.includes('performance-http-view') ||
  223. organization.features.includes('performance-cache-view') ||
  224. organization.features.includes('performance-queues-view')
  225. ) {
  226. return (
  227. <SidebarAccordion
  228. {...sidebarItemProps}
  229. icon={<IconLightning />}
  230. label={<GuideAnchor target="performance">{t('Performance')}</GuideAnchor>}
  231. to={`/organizations/${organization.slug}/performance/`}
  232. id="performance"
  233. exact={!shouldAccordionFloat}
  234. >
  235. <Feature features="spans-first-ui" organization={organization}>
  236. <SidebarItem
  237. {...sidebarItemProps}
  238. label={
  239. <GuideAnchor target="performance-database">
  240. {t('Queries')}
  241. </GuideAnchor>
  242. }
  243. to={`/organizations/${organization.slug}/performance/database/`}
  244. id="performance-database"
  245. // collapsed controls whether the dot is visible or not.
  246. // We always want it visible for these sidebar items so force it to true.
  247. icon={<SubitemDot collapsed />}
  248. />
  249. </Feature>
  250. <Feature features="performance-http-view" organization={organization}>
  251. <SidebarItem
  252. {...sidebarItemProps}
  253. label={
  254. <GuideAnchor target="performance-http">
  255. {HTTP_MODULE_TITLE}
  256. </GuideAnchor>
  257. }
  258. to={`/organizations/${organization.slug}/performance/http/`}
  259. id="performance-http"
  260. icon={<SubitemDot collapsed />}
  261. {...HTTPModuleBadgeProps}
  262. />
  263. </Feature>
  264. <Feature features="performance-cache-view" organization={organization}>
  265. <SidebarItem
  266. {...sidebarItemProps}
  267. label={
  268. <GuideAnchor target="performance-cache">
  269. {CACHE_MODULE_TITLE}
  270. </GuideAnchor>
  271. }
  272. to={`/organizations/${organization.slug}/performance/cache/`}
  273. id="performance-cache"
  274. icon={<SubitemDot collapsed />}
  275. {...CacheModuleBadgeProps}
  276. />
  277. </Feature>
  278. <Feature features="spans-first-ui" organization={organization}>
  279. <SidebarItem
  280. {...sidebarItemProps}
  281. label={
  282. <GuideAnchor target="performance-webvitals">
  283. {t('Web Vitals')}
  284. </GuideAnchor>
  285. }
  286. to={`/organizations/${organization.slug}/performance/browser/pageloads/`}
  287. id="performance-webvitals"
  288. icon={<SubitemDot collapsed />}
  289. />
  290. </Feature>
  291. <Feature features="performance-queues-view" organization={organization}>
  292. <SidebarItem
  293. {...sidebarItemProps}
  294. label={
  295. <GuideAnchor target="performance-queues">{t('Queues')}</GuideAnchor>
  296. }
  297. to={`/organizations/${organization.slug}/performance/queues/`}
  298. id="performance-queues"
  299. icon={<SubitemDot collapsed />}
  300. />
  301. </Feature>
  302. <Feature features="spans-first-ui" organization={organization}>
  303. <SidebarItem
  304. {...sidebarItemProps}
  305. label={t('Screen Loads')}
  306. to={`/organizations/${organization.slug}/performance/mobile/screens/`}
  307. id="performance-mobile-screens"
  308. icon={<SubitemDot collapsed />}
  309. />
  310. </Feature>
  311. <Feature features="spans-first-ui" organization={organization}>
  312. <SidebarItem
  313. {...sidebarItemProps}
  314. label={t('App Starts')}
  315. to={`/organizations/${organization.slug}/performance/mobile/app-startup/`}
  316. id="performance-mobile-app-startup"
  317. icon={<SubitemDot collapsed />}
  318. />
  319. </Feature>
  320. <Feature features="spans-first-ui">
  321. <SidebarItem
  322. {...sidebarItemProps}
  323. label={<GuideAnchor target="starfish">{t('Resources')}</GuideAnchor>}
  324. to={`/organizations/${organization.slug}/performance/browser/resources/`}
  325. id="performance-browser-resources"
  326. icon={<SubitemDot collapsed />}
  327. />
  328. </Feature>
  329. <Feature features="performance-trace-explorer">
  330. <SidebarItem
  331. {...sidebarItemProps}
  332. label={<GuideAnchor target="traces">{t('Traces')}</GuideAnchor>}
  333. to={`/organizations/${organization.slug}/performance/traces/`}
  334. id="performance-trace-explorer"
  335. icon={<SubitemDot collapsed />}
  336. />
  337. </Feature>
  338. </SidebarAccordion>
  339. );
  340. }
  341. // Otherwise, show a regular sidebar link to the Performance landing page
  342. return (
  343. <SidebarItem
  344. {...sidebarItemProps}
  345. icon={<IconLightning />}
  346. label={<GuideAnchor target="performance">{t('Performance')}</GuideAnchor>}
  347. to={`/organizations/${organization.slug}/performance/`}
  348. id="performance"
  349. />
  350. );
  351. })()}
  352. </Feature>
  353. );
  354. const releases = hasOrganization && (
  355. <SidebarItem
  356. {...sidebarItemProps}
  357. icon={<IconReleases />}
  358. label={<GuideAnchor target="releases">{t('Releases')}</GuideAnchor>}
  359. to={`/organizations/${organization.slug}/releases/`}
  360. id="releases"
  361. />
  362. );
  363. const aiMonitoring = hasOrganization && (
  364. <Feature features="ai-analytics" organization={organization}>
  365. <SidebarItem
  366. {...sidebarItemProps}
  367. icon={<IconRobot />}
  368. label={t('AI Monitoring')}
  369. isAlpha
  370. variant="short"
  371. to={`/organizations/${organization.slug}/ai-monitoring/`}
  372. id="ai-monitoring"
  373. />
  374. </Feature>
  375. );
  376. const userFeedback = hasOrganization && (
  377. <Feature features="old-user-feedback" organization={organization}>
  378. <SidebarItem
  379. {...sidebarItemProps}
  380. icon={<IconSupport />}
  381. label={t('User Feedback')}
  382. to={`/organizations/${organization.slug}/user-feedback/`}
  383. id="user-feedback"
  384. />
  385. </Feature>
  386. );
  387. const feedback = hasOrganization && (
  388. <Feature features="user-feedback-ui" organization={organization}>
  389. <SidebarItem
  390. {...sidebarItemProps}
  391. icon={<IconMegaphone />}
  392. label={t('User Feedback')}
  393. isBeta
  394. variant="short"
  395. to={`/organizations/${organization.slug}/feedback/`}
  396. id="feedback"
  397. />
  398. </Feature>
  399. );
  400. const alerts = hasOrganization && (
  401. <SidebarItem
  402. {...sidebarItemProps}
  403. icon={<IconSiren />}
  404. label={t('Alerts')}
  405. to={`/organizations/${organization.slug}/alerts/rules/`}
  406. id="alerts"
  407. />
  408. );
  409. const monitors = hasOrganization && (
  410. <SidebarItem
  411. {...sidebarItemProps}
  412. icon={<IconTimer />}
  413. label={t('Crons')}
  414. to={`/organizations/${organization.slug}/crons/`}
  415. id="crons"
  416. />
  417. );
  418. const replays = hasOrganization && (
  419. <Feature
  420. hookName="feature-disabled:replay-sidebar-item"
  421. features="session-replay-ui"
  422. organization={organization}
  423. requireAll={false}
  424. >
  425. <SidebarItem
  426. {...sidebarItemProps}
  427. icon={<IconPlay />}
  428. label={t('Replays')}
  429. to={`/organizations/${organization.slug}/replays/`}
  430. id="replays"
  431. />
  432. </Feature>
  433. );
  434. const metricsPath = `/organizations/${organization?.slug}/metrics/`;
  435. const metrics = hasOrganization && hasMetricsSidebarItem(organization) && (
  436. <Feature
  437. features={['ddm-ui', 'custom-metrics']}
  438. organization={organization}
  439. requireAll
  440. >
  441. <SidebarItem
  442. {...sidebarItemProps}
  443. icon={<IconGraph />}
  444. label={t('Metrics')}
  445. to={metricsPath}
  446. search={location.pathname === normalizeUrl(metricsPath) ? location.search : ''}
  447. id="metrics"
  448. isBeta
  449. />
  450. </Feature>
  451. );
  452. const dashboards = hasOrganization && (
  453. <Feature
  454. hookName="feature-disabled:dashboards-sidebar-item"
  455. features={['discover', 'discover-query', 'dashboards-basic', 'dashboards-edit']}
  456. organization={organization}
  457. requireAll={false}
  458. >
  459. <SidebarItem
  460. {...sidebarItemProps}
  461. index
  462. icon={<IconDashboard />}
  463. label={t('Dashboards')}
  464. to={`/organizations/${organization.slug}/dashboards/`}
  465. id="customizable-dashboards"
  466. />
  467. </Feature>
  468. );
  469. const profiling = hasOrganization && (
  470. <Feature
  471. hookName="feature-disabled:profiling-sidebar-item"
  472. features="profiling"
  473. organization={organization}
  474. requireAll={false}
  475. >
  476. <SidebarItem
  477. {...sidebarItemProps}
  478. index
  479. icon={<IconProfiling />}
  480. label={t('Profiling')}
  481. to={`/organizations/${organization.slug}/profiling/`}
  482. id="profiling"
  483. />
  484. </Feature>
  485. );
  486. const stats = hasOrganization && (
  487. <SidebarItem
  488. {...sidebarItemProps}
  489. icon={<IconStats />}
  490. label={t('Stats')}
  491. to={`/organizations/${organization.slug}/stats/`}
  492. id="stats"
  493. />
  494. );
  495. const settings = hasOrganization && (
  496. <SidebarItem
  497. {...sidebarItemProps}
  498. icon={<IconSettings />}
  499. label={t('Settings')}
  500. to={`/settings/${organization.slug}/`}
  501. id="settings"
  502. />
  503. );
  504. return (
  505. <SidebarWrapper aria-label={t('Primary Navigation')} collapsed={collapsed}>
  506. <ExpandedContextProvider>
  507. <SidebarSectionGroupPrimary>
  508. <DropdownSidebarSection
  509. isSuperuser={showSuperuserWarning() && !isExcludedOrg()}
  510. >
  511. <SidebarDropdown orientation={orientation} collapsed={collapsed} />
  512. {showSuperuserWarning() && !isExcludedOrg() && (
  513. <Hook name="component:superuser-warning" organization={organization} />
  514. )}
  515. </DropdownSidebarSection>
  516. <PrimaryItems>
  517. {hasOrganization && (
  518. <Fragment>
  519. <SidebarSection>
  520. {issues}
  521. {projects}
  522. </SidebarSection>
  523. <SidebarSection>
  524. {performance}
  525. {profiling}
  526. {metrics}
  527. {replays}
  528. {aiMonitoring}
  529. {feedback}
  530. {monitors}
  531. {alerts}
  532. </SidebarSection>
  533. <SidebarSection>
  534. {discover2}
  535. {dashboards}
  536. {releases}
  537. {userFeedback}
  538. </SidebarSection>
  539. <SidebarSection>
  540. {stats}
  541. {settings}
  542. </SidebarSection>
  543. </Fragment>
  544. )}
  545. </PrimaryItems>
  546. </SidebarSectionGroupPrimary>
  547. {hasOrganization && (
  548. <SidebarSectionGroup>
  549. <PerformanceOnboardingSidebar
  550. currentPanel={activePanel}
  551. onShowPanel={() => togglePanel(SidebarPanelKey.PERFORMANCE_ONBOARDING)}
  552. hidePanel={() => hidePanel('performance-sidequest')}
  553. {...sidebarItemProps}
  554. />
  555. <FeedbackOnboardingSidebar
  556. currentPanel={activePanel}
  557. onShowPanel={() => togglePanel(SidebarPanelKey.FEEDBACK_ONBOARDING)}
  558. hidePanel={hidePanel}
  559. {...sidebarItemProps}
  560. />
  561. <ReplaysOnboardingSidebar
  562. currentPanel={activePanel}
  563. onShowPanel={() => togglePanel(SidebarPanelKey.REPLAYS_ONBOARDING)}
  564. hidePanel={hidePanel}
  565. {...sidebarItemProps}
  566. />
  567. <ProfilingOnboardingSidebar
  568. currentPanel={activePanel}
  569. onShowPanel={() => togglePanel(SidebarPanelKey.PROFILING_ONBOARDING)}
  570. hidePanel={hidePanel}
  571. {...sidebarItemProps}
  572. />
  573. <MetricsOnboardingSidebar
  574. currentPanel={activePanel}
  575. onShowPanel={() => togglePanel(SidebarPanelKey.METRICS_ONBOARDING)}
  576. hidePanel={hidePanel}
  577. {...sidebarItemProps}
  578. />
  579. <SidebarSection noMargin noPadding>
  580. <OnboardingStatus
  581. org={organization}
  582. currentPanel={activePanel}
  583. onShowPanel={() => togglePanel(SidebarPanelKey.ONBOARDING_WIZARD)}
  584. hidePanel={hidePanel}
  585. {...sidebarItemProps}
  586. />
  587. </SidebarSection>
  588. <SidebarSection>
  589. {HookStore.get('sidebar:bottom-items').length > 0 &&
  590. HookStore.get('sidebar:bottom-items')[0]({
  591. orientation,
  592. collapsed,
  593. hasPanel,
  594. organization,
  595. })}
  596. <SidebarHelp
  597. orientation={orientation}
  598. collapsed={collapsed}
  599. hidePanel={hidePanel}
  600. organization={organization}
  601. />
  602. <Broadcasts
  603. orientation={orientation}
  604. collapsed={collapsed}
  605. currentPanel={activePanel}
  606. onShowPanel={() => togglePanel(SidebarPanelKey.BROADCASTS)}
  607. hidePanel={hidePanel}
  608. organization={organization}
  609. />
  610. <ServiceIncidents
  611. orientation={orientation}
  612. collapsed={collapsed}
  613. currentPanel={activePanel}
  614. onShowPanel={() => togglePanel(SidebarPanelKey.SERVICE_INCIDENTS)}
  615. hidePanel={hidePanel}
  616. />
  617. </SidebarSection>
  618. {!horizontal && (
  619. <SidebarSection>
  620. <SidebarCollapseItem
  621. id="collapse"
  622. data-test-id="sidebar-collapse"
  623. {...sidebarItemProps}
  624. icon={<Chevron direction={collapsed ? 'right' : 'left'} />}
  625. label={collapsed ? t('Expand') : t('Collapse')}
  626. onClick={toggleCollapse}
  627. />
  628. </SidebarSection>
  629. )}
  630. </SidebarSectionGroup>
  631. )}
  632. </ExpandedContextProvider>
  633. </SidebarWrapper>
  634. );
  635. }
  636. export default Sidebar;
  637. const responsiveFlex = css`
  638. display: flex;
  639. flex-direction: column;
  640. @media (max-width: ${theme.breakpoints.medium}) {
  641. flex-direction: row;
  642. }
  643. `;
  644. export const SidebarWrapper = styled('nav')<{collapsed: boolean}>`
  645. background: ${p => p.theme.sidebarGradient};
  646. color: ${p => p.theme.sidebar.color};
  647. line-height: 1;
  648. padding: 12px 0 2px; /* Allows for 32px avatars */
  649. width: ${p => p.theme.sidebar[p.collapsed ? 'collapsedWidth' : 'expandedWidth']};
  650. position: fixed;
  651. top: ${p => (ConfigStore.get('demoMode') ? p.theme.demo.headerSize : 0)};
  652. left: 0;
  653. bottom: 0;
  654. justify-content: space-between;
  655. z-index: ${p => p.theme.zIndex.sidebar};
  656. border-right: solid 1px ${p => p.theme.sidebarBorder};
  657. ${responsiveFlex};
  658. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  659. top: 0;
  660. left: 0;
  661. right: 0;
  662. height: ${p => p.theme.sidebar.mobileHeight};
  663. bottom: auto;
  664. width: auto;
  665. padding: 0 ${space(1)};
  666. align-items: center;
  667. border-right: none;
  668. border-bottom: solid 1px ${p => p.theme.sidebarBorder};
  669. }
  670. `;
  671. const SidebarSectionGroup = styled('div')`
  672. ${responsiveFlex};
  673. flex-shrink: 0; /* prevents shrinking on Safari */
  674. gap: 1px;
  675. `;
  676. const SidebarSectionGroupPrimary = styled('div')`
  677. ${responsiveFlex};
  678. /* necessary for child flexing on msedge and ff */
  679. min-height: 0;
  680. min-width: 0;
  681. flex: 1;
  682. /* expand to fill the entire height on mobile */
  683. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  684. height: 100%;
  685. align-items: center;
  686. }
  687. `;
  688. const PrimaryItems = styled('div')`
  689. overflow: auto;
  690. flex: 1;
  691. display: flex;
  692. flex-direction: column;
  693. gap: 1px;
  694. -ms-overflow-style: -ms-autohiding-scrollbar;
  695. @media (max-height: 675px) and (min-width: ${p => p.theme.breakpoints.medium}) {
  696. border-bottom: 1px solid ${p => p.theme.sidebarBorder};
  697. padding-bottom: ${space(1)};
  698. box-shadow: rgba(0, 0, 0, 0.15) 0px -10px 10px inset;
  699. }
  700. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  701. overflow-y: visible;
  702. flex-direction: row;
  703. height: 100%;
  704. align-items: center;
  705. border-right: 1px solid ${p => p.theme.sidebarBorder};
  706. padding-right: ${space(1)};
  707. margin-right: ${space(0.5)};
  708. box-shadow: rgba(0, 0, 0, 0.15) -10px 0px 10px inset;
  709. ::-webkit-scrollbar {
  710. display: none;
  711. }
  712. }
  713. `;
  714. const SubitemDot = styled('div')<{collapsed: boolean}>`
  715. width: 3px;
  716. height: 3px;
  717. background: currentcolor;
  718. border-radius: 50%;
  719. opacity: ${p => (p.collapsed ? 1 : 0)};
  720. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  721. opacity: 1;
  722. }
  723. `;
  724. const SidebarSection = styled(SidebarSectionGroup)<{
  725. noMargin?: boolean;
  726. noPadding?: boolean;
  727. }>`
  728. ${p => !p.noMargin && `margin: ${space(1)} 0`};
  729. ${p => !p.noPadding && `padding: 0 ${space(2)}`};
  730. @media (max-width: ${p => p.theme.breakpoints.small}) {
  731. margin: 0;
  732. padding: 0;
  733. }
  734. &:empty {
  735. display: none;
  736. }
  737. `;
  738. const DropdownSidebarSection = styled(SidebarSection)<{
  739. isSuperuser?: boolean;
  740. }>`
  741. position: relative;
  742. margin: 0;
  743. padding: ${space(1)} ${space(2)};
  744. ${p =>
  745. p.isSuperuser &&
  746. css`
  747. &:before {
  748. content: '';
  749. position: absolute;
  750. inset: 0 ${space(1)};
  751. border-radius: ${p.theme.borderRadius};
  752. background: ${p.theme.superuserSidebar};
  753. }
  754. `}
  755. `;
  756. const SidebarCollapseItem = styled(SidebarItem)`
  757. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  758. display: none;
  759. }
  760. `;