settingsNavigation.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {cloneElement, Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as Sentry from '@sentry/react';
  4. import {space} from 'sentry/styles/space';
  5. import SettingsNavigationGroup from 'sentry/views/settings/components/settingsNavigationGroup';
  6. import {NavigationProps, NavigationSection} from 'sentry/views/settings/types';
  7. type DefaultProps = {
  8. /**
  9. * Additional navigation configuration driven by hooks
  10. */
  11. hookConfigs: NavigationSection[];
  12. /**
  13. * Additional navigation elements driven from hooks
  14. */
  15. hooks: React.ReactElement[];
  16. /**
  17. * How far from the top of the page should the navigation be when stickied.
  18. */
  19. stickyTop: string;
  20. };
  21. type Props = DefaultProps &
  22. NavigationProps & {
  23. /**
  24. * The configuration for this navigation panel
  25. */
  26. navigationObjects: NavigationSection[];
  27. };
  28. class SettingsNavigation extends Component<Props> {
  29. static defaultProps: DefaultProps = {
  30. hooks: [],
  31. hookConfigs: [],
  32. stickyTop: '69px',
  33. };
  34. componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
  35. Sentry.withScope(scope => {
  36. Object.keys(errorInfo).forEach(key => {
  37. scope.setExtra(key, errorInfo[key]);
  38. });
  39. scope.setExtra('url', window.location.href);
  40. Sentry.captureException(error);
  41. });
  42. }
  43. render() {
  44. const {navigationObjects, hooks, hookConfigs, stickyTop, ...otherProps} = this.props;
  45. const navWithHooks = navigationObjects.concat(hookConfigs);
  46. return (
  47. <PositionStickyWrapper stickyTop={stickyTop}>
  48. {navWithHooks.map(config => (
  49. <SettingsNavigationGroup key={config.name} {...otherProps} {...config} />
  50. ))}
  51. {hooks.map((Hook, i) => cloneElement(Hook, {key: `hook-${i}`}))}
  52. </PositionStickyWrapper>
  53. );
  54. }
  55. }
  56. const PositionStickyWrapper = styled('div')<{stickyTop: string}>`
  57. padding: ${space(4)};
  58. padding-right: ${space(2)};
  59. @media (min-width: ${p => p.theme.breakpoints.small}) {
  60. position: sticky;
  61. top: ${p => p.stickyTop};
  62. overflow: scroll;
  63. -ms-overflow-style: none;
  64. scrollbar-width: none;
  65. &::-webkit-scrollbar {
  66. display: none;
  67. }
  68. }
  69. `;
  70. export default SettingsNavigation;