index.tsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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-cache-view') ||
  223. organization.features.includes('performance-queues-view')
  224. ) {
  225. return (
  226. <SidebarAccordion
  227. {...sidebarItemProps}
  228. icon={<IconLightning />}
  229. label={<GuideAnchor target="performance">{t('Performance')}</GuideAnchor>}
  230. to={`/organizations/${organization.slug}/performance/`}
  231. id="performance"
  232. exact={!shouldAccordionFloat}
  233. >
  234. <Feature features="spans-first-ui" organization={organization}>
  235. <SidebarItem
  236. {...sidebarItemProps}
  237. label={
  238. <GuideAnchor target="performance-database">
  239. {t('Queries')}
  240. </GuideAnchor>
  241. }
  242. to={`/organizations/${organization.slug}/performance/database/`}
  243. id="performance-database"
  244. // collapsed controls whether the dot is visible or not.
  245. // We always want it visible for these sidebar items so force it to true.
  246. icon={<SubitemDot collapsed />}
  247. />
  248. </Feature>
  249. <Feature features="spans-first-ui" organization={organization}>
  250. <SidebarItem
  251. {...sidebarItemProps}
  252. label={
  253. <GuideAnchor target="performance-http">
  254. {HTTP_MODULE_TITLE}
  255. </GuideAnchor>
  256. }
  257. to={`/organizations/${organization.slug}/performance/http/`}
  258. id="performance-http"
  259. icon={<SubitemDot collapsed />}
  260. {...HTTPModuleBadgeProps}
  261. />
  262. </Feature>
  263. <Feature features="performance-cache-view" organization={organization}>
  264. <SidebarItem
  265. {...sidebarItemProps}
  266. label={
  267. <GuideAnchor target="performance-cache">
  268. {CACHE_MODULE_TITLE}
  269. </GuideAnchor>
  270. }
  271. to={`/organizations/${organization.slug}/performance/cache/`}
  272. id="performance-cache"
  273. icon={<SubitemDot collapsed />}
  274. {...CacheModuleBadgeProps}
  275. />
  276. </Feature>
  277. <Feature features="spans-first-ui" organization={organization}>
  278. <SidebarItem
  279. {...sidebarItemProps}
  280. label={
  281. <GuideAnchor target="performance-webvitals">
  282. {t('Web Vitals')}
  283. </GuideAnchor>
  284. }
  285. to={`/organizations/${organization.slug}/performance/browser/pageloads/`}
  286. id="performance-webvitals"
  287. icon={<SubitemDot collapsed />}
  288. />
  289. </Feature>
  290. <Feature features="performance-queues-view" organization={organization}>
  291. <SidebarItem
  292. {...sidebarItemProps}
  293. label={
  294. <GuideAnchor target="performance-queues">{t('Queues')}</GuideAnchor>
  295. }
  296. isAlpha
  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
  321. features={['spans-first-ui', 'starfish-mobile-ui-module']}
  322. organization={organization}
  323. >
  324. <SidebarItem
  325. {...sidebarItemProps}
  326. label={t('Mobile UI')}
  327. to={`/organizations/${organization.slug}/performance/mobile/ui/`}
  328. id="performance-mobile-ui"
  329. icon={<SubitemDot collapsed />}
  330. isAlpha
  331. />
  332. </Feature>
  333. <Feature features="spans-first-ui">
  334. <SidebarItem
  335. {...sidebarItemProps}
  336. label={<GuideAnchor target="starfish">{t('Resources')}</GuideAnchor>}
  337. to={`/organizations/${organization.slug}/performance/browser/resources/`}
  338. id="performance-browser-resources"
  339. icon={<SubitemDot collapsed />}
  340. />
  341. </Feature>
  342. <Feature features="performance-trace-explorer">
  343. <SidebarItem
  344. {...sidebarItemProps}
  345. label={<GuideAnchor target="traces">{t('Traces')}</GuideAnchor>}
  346. to={`/organizations/${organization.slug}/performance/traces/`}
  347. id="performance-trace-explorer"
  348. icon={<SubitemDot collapsed />}
  349. />
  350. </Feature>
  351. </SidebarAccordion>
  352. );
  353. }
  354. // Otherwise, show a regular sidebar link to the Performance landing page
  355. return (
  356. <SidebarItem
  357. {...sidebarItemProps}
  358. icon={<IconLightning />}
  359. label={<GuideAnchor target="performance">{t('Performance')}</GuideAnchor>}
  360. to={`/organizations/${organization.slug}/performance/`}
  361. id="performance"
  362. />
  363. );
  364. })()}
  365. </Feature>
  366. );
  367. const releases = hasOrganization && (
  368. <SidebarItem
  369. {...sidebarItemProps}
  370. icon={<IconReleases />}
  371. label={<GuideAnchor target="releases">{t('Releases')}</GuideAnchor>}
  372. to={`/organizations/${organization.slug}/releases/`}
  373. id="releases"
  374. />
  375. );
  376. const aiMonitoring = hasOrganization && (
  377. <Feature features="ai-analytics" organization={organization}>
  378. <SidebarItem
  379. {...sidebarItemProps}
  380. icon={<IconRobot />}
  381. label={t('AI Monitoring')}
  382. isAlpha
  383. variant="short"
  384. to={`/organizations/${organization.slug}/ai-monitoring/`}
  385. id="ai-monitoring"
  386. />
  387. </Feature>
  388. );
  389. const userFeedback = hasOrganization && (
  390. <Feature features="old-user-feedback" organization={organization}>
  391. <SidebarItem
  392. {...sidebarItemProps}
  393. icon={<IconSupport />}
  394. label={t('User Feedback')}
  395. to={`/organizations/${organization.slug}/user-feedback/`}
  396. id="user-feedback"
  397. />
  398. </Feature>
  399. );
  400. const feedback = hasOrganization && (
  401. <Feature features="user-feedback-ui" organization={organization}>
  402. <SidebarItem
  403. {...sidebarItemProps}
  404. icon={<IconMegaphone />}
  405. label={t('User Feedback')}
  406. isBeta
  407. variant="short"
  408. to={`/organizations/${organization.slug}/feedback/`}
  409. id="feedback"
  410. />
  411. </Feature>
  412. );
  413. const alerts = hasOrganization && (
  414. <SidebarItem
  415. {...sidebarItemProps}
  416. icon={<IconSiren />}
  417. label={t('Alerts')}
  418. to={`/organizations/${organization.slug}/alerts/rules/`}
  419. id="alerts"
  420. />
  421. );
  422. const monitors = hasOrganization && (
  423. <SidebarItem
  424. {...sidebarItemProps}
  425. icon={<IconTimer />}
  426. label={t('Crons')}
  427. to={`/organizations/${organization.slug}/crons/`}
  428. id="crons"
  429. />
  430. );
  431. const replays = hasOrganization && (
  432. <Feature
  433. hookName="feature-disabled:replay-sidebar-item"
  434. features="session-replay-ui"
  435. organization={organization}
  436. requireAll={false}
  437. >
  438. <SidebarItem
  439. {...sidebarItemProps}
  440. icon={<IconPlay />}
  441. label={t('Replays')}
  442. to={`/organizations/${organization.slug}/replays/`}
  443. id="replays"
  444. />
  445. </Feature>
  446. );
  447. const metricsPath = `/organizations/${organization?.slug}/metrics/`;
  448. const metrics = hasOrganization && hasMetricsSidebarItem(organization) && (
  449. <Feature features={['custom-metrics']} organization={organization}>
  450. <SidebarItem
  451. {...sidebarItemProps}
  452. icon={<IconGraph />}
  453. label={t('Metrics')}
  454. to={metricsPath}
  455. search={location.pathname === normalizeUrl(metricsPath) ? location.search : ''}
  456. id="metrics"
  457. isBeta
  458. />
  459. </Feature>
  460. );
  461. const dashboards = hasOrganization && (
  462. <Feature
  463. hookName="feature-disabled:dashboards-sidebar-item"
  464. features={['discover', 'discover-query', 'dashboards-basic', 'dashboards-edit']}
  465. organization={organization}
  466. requireAll={false}
  467. >
  468. <SidebarItem
  469. {...sidebarItemProps}
  470. index
  471. icon={<IconDashboard />}
  472. label={t('Dashboards')}
  473. to={`/organizations/${organization.slug}/dashboards/`}
  474. id="customizable-dashboards"
  475. />
  476. </Feature>
  477. );
  478. const profiling = hasOrganization && (
  479. <Feature
  480. hookName="feature-disabled:profiling-sidebar-item"
  481. features="profiling"
  482. organization={organization}
  483. requireAll={false}
  484. >
  485. <SidebarItem
  486. {...sidebarItemProps}
  487. index
  488. icon={<IconProfiling />}
  489. label={t('Profiling')}
  490. to={`/organizations/${organization.slug}/profiling/`}
  491. id="profiling"
  492. />
  493. </Feature>
  494. );
  495. const stats = hasOrganization && (
  496. <SidebarItem
  497. {...sidebarItemProps}
  498. icon={<IconStats />}
  499. label={t('Stats')}
  500. to={`/organizations/${organization.slug}/stats/`}
  501. id="stats"
  502. />
  503. );
  504. const settings = hasOrganization && (
  505. <SidebarItem
  506. {...sidebarItemProps}
  507. icon={<IconSettings />}
  508. label={t('Settings')}
  509. to={`/settings/${organization.slug}/`}
  510. id="settings"
  511. />
  512. );
  513. return (
  514. <SidebarWrapper aria-label={t('Primary Navigation')} collapsed={collapsed}>
  515. <ExpandedContextProvider>
  516. <SidebarSectionGroupPrimary>
  517. <DropdownSidebarSection
  518. isSuperuser={showSuperuserWarning() && !isExcludedOrg()}
  519. >
  520. <SidebarDropdown orientation={orientation} collapsed={collapsed} />
  521. {showSuperuserWarning() && !isExcludedOrg() && (
  522. <Hook name="component:superuser-warning" organization={organization} />
  523. )}
  524. </DropdownSidebarSection>
  525. <PrimaryItems>
  526. {hasOrganization && (
  527. <Fragment>
  528. <SidebarSection>
  529. {issues}
  530. {projects}
  531. </SidebarSection>
  532. <SidebarSection>
  533. {performance}
  534. {profiling}
  535. {metrics}
  536. {replays}
  537. {aiMonitoring}
  538. {feedback}
  539. {monitors}
  540. {alerts}
  541. </SidebarSection>
  542. <SidebarSection>
  543. {discover2}
  544. {dashboards}
  545. {releases}
  546. {userFeedback}
  547. </SidebarSection>
  548. <SidebarSection>
  549. {stats}
  550. {settings}
  551. </SidebarSection>
  552. </Fragment>
  553. )}
  554. </PrimaryItems>
  555. </SidebarSectionGroupPrimary>
  556. {hasOrganization && (
  557. <SidebarSectionGroup>
  558. <PerformanceOnboardingSidebar
  559. currentPanel={activePanel}
  560. onShowPanel={() => togglePanel(SidebarPanelKey.PERFORMANCE_ONBOARDING)}
  561. hidePanel={() => hidePanel('performance-sidequest')}
  562. {...sidebarItemProps}
  563. />
  564. <FeedbackOnboardingSidebar
  565. currentPanel={activePanel}
  566. onShowPanel={() => togglePanel(SidebarPanelKey.FEEDBACK_ONBOARDING)}
  567. hidePanel={hidePanel}
  568. {...sidebarItemProps}
  569. />
  570. <ReplaysOnboardingSidebar
  571. currentPanel={activePanel}
  572. onShowPanel={() => togglePanel(SidebarPanelKey.REPLAYS_ONBOARDING)}
  573. hidePanel={hidePanel}
  574. {...sidebarItemProps}
  575. />
  576. <ProfilingOnboardingSidebar
  577. currentPanel={activePanel}
  578. onShowPanel={() => togglePanel(SidebarPanelKey.PROFILING_ONBOARDING)}
  579. hidePanel={hidePanel}
  580. {...sidebarItemProps}
  581. />
  582. <MetricsOnboardingSidebar
  583. currentPanel={activePanel}
  584. onShowPanel={() => togglePanel(SidebarPanelKey.METRICS_ONBOARDING)}
  585. hidePanel={hidePanel}
  586. {...sidebarItemProps}
  587. />
  588. <SidebarSection noMargin noPadding>
  589. <OnboardingStatus
  590. org={organization}
  591. currentPanel={activePanel}
  592. onShowPanel={() => togglePanel(SidebarPanelKey.ONBOARDING_WIZARD)}
  593. hidePanel={hidePanel}
  594. {...sidebarItemProps}
  595. />
  596. </SidebarSection>
  597. <SidebarSection>
  598. {HookStore.get('sidebar:bottom-items').length > 0 &&
  599. HookStore.get('sidebar:bottom-items')[0]({
  600. orientation,
  601. collapsed,
  602. hasPanel,
  603. organization,
  604. })}
  605. <SidebarHelp
  606. orientation={orientation}
  607. collapsed={collapsed}
  608. hidePanel={hidePanel}
  609. organization={organization}
  610. />
  611. <Broadcasts
  612. orientation={orientation}
  613. collapsed={collapsed}
  614. currentPanel={activePanel}
  615. onShowPanel={() => togglePanel(SidebarPanelKey.BROADCASTS)}
  616. hidePanel={hidePanel}
  617. organization={organization}
  618. />
  619. <ServiceIncidents
  620. orientation={orientation}
  621. collapsed={collapsed}
  622. currentPanel={activePanel}
  623. onShowPanel={() => togglePanel(SidebarPanelKey.SERVICE_INCIDENTS)}
  624. hidePanel={hidePanel}
  625. />
  626. </SidebarSection>
  627. {!horizontal && (
  628. <SidebarSection>
  629. <SidebarCollapseItem
  630. id="collapse"
  631. data-test-id="sidebar-collapse"
  632. {...sidebarItemProps}
  633. icon={<Chevron direction={collapsed ? 'right' : 'left'} />}
  634. label={collapsed ? t('Expand') : t('Collapse')}
  635. onClick={toggleCollapse}
  636. />
  637. </SidebarSection>
  638. )}
  639. </SidebarSectionGroup>
  640. )}
  641. </ExpandedContextProvider>
  642. </SidebarWrapper>
  643. );
  644. }
  645. export default Sidebar;
  646. const responsiveFlex = css`
  647. display: flex;
  648. flex-direction: column;
  649. @media (max-width: ${theme.breakpoints.medium}) {
  650. flex-direction: row;
  651. }
  652. `;
  653. export const SidebarWrapper = styled('nav')<{collapsed: boolean}>`
  654. background: ${p => p.theme.sidebarGradient};
  655. color: ${p => p.theme.sidebar.color};
  656. line-height: 1;
  657. padding: 12px 0 2px; /* Allows for 32px avatars */
  658. width: ${p => p.theme.sidebar[p.collapsed ? 'collapsedWidth' : 'expandedWidth']};
  659. position: fixed;
  660. top: ${p => (ConfigStore.get('demoMode') ? p.theme.demo.headerSize : 0)};
  661. left: 0;
  662. bottom: 0;
  663. justify-content: space-between;
  664. z-index: ${p => p.theme.zIndex.sidebar};
  665. border-right: solid 1px ${p => p.theme.sidebarBorder};
  666. ${responsiveFlex};
  667. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  668. top: 0;
  669. left: 0;
  670. right: 0;
  671. height: ${p => p.theme.sidebar.mobileHeight};
  672. bottom: auto;
  673. width: auto;
  674. padding: 0 ${space(1)};
  675. align-items: center;
  676. border-right: none;
  677. border-bottom: solid 1px ${p => p.theme.sidebarBorder};
  678. }
  679. `;
  680. const SidebarSectionGroup = styled('div')`
  681. ${responsiveFlex};
  682. flex-shrink: 0; /* prevents shrinking on Safari */
  683. gap: 1px;
  684. `;
  685. const SidebarSectionGroupPrimary = styled('div')`
  686. ${responsiveFlex};
  687. /* necessary for child flexing on msedge and ff */
  688. min-height: 0;
  689. min-width: 0;
  690. flex: 1;
  691. /* expand to fill the entire height on mobile */
  692. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  693. height: 100%;
  694. align-items: center;
  695. }
  696. `;
  697. const PrimaryItems = styled('div')`
  698. overflow: auto;
  699. flex: 1;
  700. display: flex;
  701. flex-direction: column;
  702. gap: 1px;
  703. -ms-overflow-style: -ms-autohiding-scrollbar;
  704. @media (max-height: 675px) and (min-width: ${p => p.theme.breakpoints.medium}) {
  705. border-bottom: 1px solid ${p => p.theme.sidebarBorder};
  706. padding-bottom: ${space(1)};
  707. box-shadow: rgba(0, 0, 0, 0.15) 0px -10px 10px inset;
  708. }
  709. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  710. overflow-y: visible;
  711. flex-direction: row;
  712. height: 100%;
  713. align-items: center;
  714. border-right: 1px solid ${p => p.theme.sidebarBorder};
  715. padding-right: ${space(1)};
  716. margin-right: ${space(0.5)};
  717. box-shadow: rgba(0, 0, 0, 0.15) -10px 0px 10px inset;
  718. ::-webkit-scrollbar {
  719. display: none;
  720. }
  721. }
  722. `;
  723. const SubitemDot = styled('div')<{collapsed: boolean}>`
  724. width: 3px;
  725. height: 3px;
  726. background: currentcolor;
  727. border-radius: 50%;
  728. opacity: ${p => (p.collapsed ? 1 : 0)};
  729. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  730. opacity: 1;
  731. }
  732. `;
  733. const SidebarSection = styled(SidebarSectionGroup)<{
  734. noMargin?: boolean;
  735. noPadding?: boolean;
  736. }>`
  737. ${p => !p.noMargin && `margin: ${space(1)} 0`};
  738. ${p => !p.noPadding && `padding: 0 ${space(2)}`};
  739. @media (max-width: ${p => p.theme.breakpoints.small}) {
  740. margin: 0;
  741. padding: 0;
  742. }
  743. &:empty {
  744. display: none;
  745. }
  746. `;
  747. const DropdownSidebarSection = styled(SidebarSection)<{
  748. isSuperuser?: boolean;
  749. }>`
  750. position: relative;
  751. margin: 0;
  752. padding: ${space(1)} ${space(2)};
  753. ${p =>
  754. p.isSuperuser &&
  755. css`
  756. &:before {
  757. content: '';
  758. position: absolute;
  759. inset: 0 ${space(1)};
  760. border-radius: ${p.theme.borderRadius};
  761. background: ${p.theme.superuserSidebar};
  762. }
  763. `}
  764. `;
  765. const SidebarCollapseItem = styled(SidebarItem)`
  766. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  767. display: none;
  768. }
  769. `;