displayOptions.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  4. import DropdownControl, {DropdownItem} from 'sentry/components/dropdownControl';
  5. import FeatureBadge from 'sentry/components/featureBadge';
  6. import Tooltip from 'sentry/components/tooltip';
  7. import {t} from 'sentry/locale';
  8. import {getDisplayLabel, IssueDisplayOptions} from 'sentry/views/issueList/utils';
  9. type Props = {
  10. display: IssueDisplayOptions;
  11. hasMultipleProjectsSelected: boolean;
  12. hasSessions: boolean;
  13. onDisplayChange: (display: string) => void;
  14. };
  15. const IssueListDisplayOptions = ({
  16. onDisplayChange,
  17. display,
  18. hasSessions,
  19. hasMultipleProjectsSelected,
  20. }: Props) => {
  21. const getMenuItem = (key: IssueDisplayOptions): React.ReactNode => {
  22. let tooltipText: string | undefined;
  23. let disabled = false;
  24. if (key === IssueDisplayOptions.SESSIONS) {
  25. if (hasMultipleProjectsSelected) {
  26. tooltipText = t(
  27. 'This option is not available when multiple projects are selected.'
  28. );
  29. disabled = true;
  30. } else if (!hasSessions) {
  31. tooltipText = t(
  32. 'This option is not available because there is no session data in the selected time period.'
  33. );
  34. disabled = true;
  35. }
  36. }
  37. return (
  38. <DropdownItem
  39. onSelect={onDisplayChange}
  40. eventKey={key}
  41. isActive={key === display}
  42. disabled={disabled}
  43. >
  44. <StyledTooltip
  45. containerDisplayMode="block"
  46. position="top"
  47. title={tooltipText}
  48. disabled={!tooltipText}
  49. >
  50. {getDisplayLabel(key)}
  51. {key === IssueDisplayOptions.SESSIONS && <FeatureBadge type="beta" noTooltip />}
  52. </StyledTooltip>
  53. </DropdownItem>
  54. );
  55. };
  56. return (
  57. <GuideAnchor
  58. target="percentage_based_alerts"
  59. position="bottom"
  60. disabled={!hasSessions || hasMultipleProjectsSelected}
  61. >
  62. <StyledDropdownControl
  63. buttonProps={{
  64. prefix: t('Display'),
  65. }}
  66. buttonTooltipTitle={
  67. display === IssueDisplayOptions.SESSIONS
  68. ? t(
  69. 'This shows the event count as a percent of sessions in the same time period.'
  70. )
  71. : null
  72. }
  73. label={
  74. !hasSessions || hasMultipleProjectsSelected
  75. ? getDisplayLabel(IssueDisplayOptions.EVENTS)
  76. : getDisplayLabel(display)
  77. }
  78. >
  79. <Fragment>
  80. {getMenuItem(IssueDisplayOptions.EVENTS)}
  81. {getMenuItem(IssueDisplayOptions.SESSIONS)}
  82. </Fragment>
  83. </StyledDropdownControl>
  84. </GuideAnchor>
  85. );
  86. };
  87. const StyledTooltip = styled(Tooltip)`
  88. width: 100%;
  89. `;
  90. const StyledDropdownControl = styled(DropdownControl)`
  91. z-index: ${p => p.theme.zIndex.issuesList.displayOptions};
  92. button {
  93. width: 100%;
  94. }
  95. @media (max-width: ${p => p.theme.breakpoints[2]}) {
  96. order: 1;
  97. }
  98. `;
  99. export default IssueListDisplayOptions;