displayOptions.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import GuideAnchor from 'app/components/assistant/guideAnchor';
  4. import DropdownControl, {DropdownItem} from 'app/components/dropdownControl';
  5. import FeatureBadge from 'app/components/featureBadge';
  6. import Tooltip from 'app/components/tooltip';
  7. import {t} from 'app/locale';
  8. import {getDisplayLabel, IssueDisplayOptions} from 'app/views/issueList/utils';
  9. type Props = {
  10. onDisplayChange: (display: string) => void;
  11. display: IssueDisplayOptions;
  12. hasSessions: boolean;
  13. hasMultipleProjectsSelected: boolean;
  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. <DropdownControl
  63. buttonProps={{prefix: t('Display')}}
  64. buttonTooltipTitle={
  65. display === IssueDisplayOptions.SESSIONS
  66. ? t(
  67. 'This shows the event count as a percent of sessions in the same time period.'
  68. )
  69. : null
  70. }
  71. label={
  72. !hasSessions || hasMultipleProjectsSelected
  73. ? getDisplayLabel(IssueDisplayOptions.EVENTS)
  74. : getDisplayLabel(display)
  75. }
  76. >
  77. <React.Fragment>
  78. {getMenuItem(IssueDisplayOptions.EVENTS)}
  79. {getMenuItem(IssueDisplayOptions.SESSIONS)}
  80. </React.Fragment>
  81. </DropdownControl>
  82. </GuideAnchor>
  83. );
  84. };
  85. const StyledTooltip = styled(Tooltip)`
  86. width: 100%;
  87. `;
  88. export default IssueListDisplayOptions;