displayOptions.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import DropdownControl, {DropdownItem} from 'app/components/dropdownControl';
  4. import Tooltip from 'app/components/tooltip';
  5. import {t} from 'app/locale';
  6. import {getDisplayLabel, IssueDisplayOptions} from 'app/views/issueList/utils';
  7. type Props = {
  8. onDisplayChange: (display: string) => void;
  9. display: IssueDisplayOptions;
  10. hasSessions: boolean;
  11. hasMultipleProjectsSelected: boolean;
  12. };
  13. const IssueListDisplayOptions = ({
  14. onDisplayChange,
  15. display,
  16. hasSessions,
  17. hasMultipleProjectsSelected,
  18. }: Props) => {
  19. const getMenuItem = (key: IssueDisplayOptions): React.ReactNode => {
  20. let tooltipText: string | undefined;
  21. let disabled = false;
  22. if (key === IssueDisplayOptions.SESSIONS) {
  23. if (hasMultipleProjectsSelected) {
  24. tooltipText = t(
  25. 'This option is not available when multiple projects are selected.'
  26. );
  27. disabled = true;
  28. } else if (!hasSessions) {
  29. tooltipText = t(
  30. 'This option is not available because there is no session data in the selected time period.'
  31. );
  32. disabled = true;
  33. }
  34. }
  35. return (
  36. <DropdownItem
  37. onSelect={onDisplayChange}
  38. eventKey={key}
  39. isActive={key === display}
  40. disabled={disabled}
  41. >
  42. <StyledTooltip
  43. containerDisplayMode="block"
  44. position="top"
  45. title={tooltipText}
  46. disabled={!tooltipText}
  47. >
  48. {getDisplayLabel(key)}
  49. </StyledTooltip>
  50. </DropdownItem>
  51. );
  52. };
  53. return (
  54. <DropdownControl
  55. buttonProps={{prefix: t('Display')}}
  56. buttonTooltipTitle={
  57. display === IssueDisplayOptions.SESSIONS
  58. ? t(
  59. 'This shows the event count as a percent of sessions in the same time period.'
  60. )
  61. : null
  62. }
  63. label={getDisplayLabel(display)}
  64. >
  65. <React.Fragment>
  66. {getMenuItem(IssueDisplayOptions.EVENTS)}
  67. {getMenuItem(IssueDisplayOptions.SESSIONS)}
  68. </React.Fragment>
  69. </DropdownControl>
  70. );
  71. };
  72. const StyledTooltip = styled(Tooltip)`
  73. width: 100%;
  74. `;
  75. export default IssueListDisplayOptions;