help.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import styled from '@emotion/styled';
  2. import {openHelpSearchModal} from 'sentry/actionCreators/modal';
  3. import DropdownMenu from 'sentry/components/dropdownMenu';
  4. import Hook from 'sentry/components/hook';
  5. import SidebarItem from 'sentry/components/sidebar/sidebarItem';
  6. import {IconQuestion} from 'sentry/icons';
  7. import {t} from 'sentry/locale';
  8. import space from 'sentry/styles/space';
  9. import {Organization} from 'sentry/types';
  10. import SidebarDropdownMenu from './sidebarDropdownMenu.styled';
  11. import SidebarMenuItem from './sidebarMenuItem';
  12. import {CommonSidebarProps} from './types';
  13. type Props = Pick<CommonSidebarProps, 'collapsed' | 'hidePanel' | 'orientation'> & {
  14. organization: Organization;
  15. };
  16. const SidebarHelp = ({orientation, collapsed, hidePanel, organization}: Props) => (
  17. <DropdownMenu>
  18. {({isOpen, getActorProps, getMenuProps}) => (
  19. <HelpRoot>
  20. <HelpActor {...getActorProps({onClick: hidePanel})}>
  21. <SidebarItem
  22. data-test-id="help-sidebar"
  23. orientation={orientation}
  24. collapsed={collapsed}
  25. hasPanel={false}
  26. icon={<IconQuestion size="md" />}
  27. label={t('Help')}
  28. id="help"
  29. />
  30. </HelpActor>
  31. {isOpen && (
  32. <HelpMenu {...getMenuProps({})} orientation={orientation}>
  33. <SidebarMenuItem
  34. data-test-id="search-docs-and-faqs"
  35. onClick={() => openHelpSearchModal({organization})}
  36. >
  37. {t('Search Support, Docs and More')}
  38. </SidebarMenuItem>
  39. <SidebarMenuItem href="https://help.sentry.io/">
  40. {t('Visit Help Center')}
  41. </SidebarMenuItem>
  42. <Hook name="sidebar:help-menu" organization={organization} />
  43. </HelpMenu>
  44. )}
  45. </HelpRoot>
  46. )}
  47. </DropdownMenu>
  48. );
  49. export default SidebarHelp;
  50. const HelpRoot = styled('div')`
  51. position: relative;
  52. `;
  53. // This exists to provide a styled actor for the dropdown. Making the actor a regular,
  54. // non-styled react component causes some issues with toggling correctly because of
  55. // how refs are handled.
  56. const HelpActor = styled('div')``;
  57. const HelpMenu = styled('div', {shouldForwardProp: p => p !== 'orientation'})<{
  58. orientation: Props['orientation'];
  59. }>`
  60. ${SidebarDropdownMenu};
  61. ${p => (p.orientation === 'left' ? 'bottom: 100%' : `top: ${space(4)}; right: 0px;`)}
  62. `;