sortOptions.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import * as React from 'react';
  2. import styled from '@emotion/styled';
  3. import Feature from 'sentry/components/acl/feature';
  4. import DropdownControl, {DropdownItem} from 'sentry/components/dropdownControl';
  5. import Tooltip from 'sentry/components/tooltip';
  6. import {t} from 'sentry/locale';
  7. import {getSortLabel, IssueSortOptions, Query} from 'sentry/views/issueList/utils';
  8. type Props = {
  9. onSelect: (sort: string) => void;
  10. query: string;
  11. sort: string;
  12. };
  13. export function getSortTooltip(key: IssueSortOptions) {
  14. switch (key) {
  15. case IssueSortOptions.INBOX:
  16. return t('When the issue was flagged for review.');
  17. case IssueSortOptions.NEW:
  18. return t('When the issue was first seen in the selected time period.');
  19. case IssueSortOptions.PRIORITY:
  20. return t('Issues trending upward recently.');
  21. case IssueSortOptions.FREQ:
  22. return t('Number of events in the time selected.');
  23. case IssueSortOptions.USER:
  24. return t('Number of users affected in the time selected.');
  25. case IssueSortOptions.TREND:
  26. return t('% change in event count over the time selected.');
  27. case IssueSortOptions.DATE:
  28. default:
  29. return t('When the issue was last seen in the selected time period.');
  30. }
  31. }
  32. const IssueListSortOptions = ({onSelect, sort, query}: Props) => {
  33. const sortKey = sort || IssueSortOptions.DATE;
  34. const getMenuItem = (key: IssueSortOptions): React.ReactNode => (
  35. <DropdownItem onSelect={onSelect} eventKey={key} isActive={sortKey === key}>
  36. <StyledTooltip
  37. containerDisplayMode="block"
  38. position="top"
  39. delay={500}
  40. title={getSortTooltip(key)}
  41. >
  42. {getSortLabel(key)}
  43. </StyledTooltip>
  44. </DropdownItem>
  45. );
  46. return (
  47. <StyledDropdownControl
  48. buttonProps={{prefix: t('Sort by')}}
  49. label={getSortLabel(sortKey)}
  50. >
  51. <React.Fragment>
  52. {query === Query.FOR_REVIEW && getMenuItem(IssueSortOptions.INBOX)}
  53. {getMenuItem(IssueSortOptions.DATE)}
  54. {getMenuItem(IssueSortOptions.NEW)}
  55. {getMenuItem(IssueSortOptions.PRIORITY)}
  56. {getMenuItem(IssueSortOptions.FREQ)}
  57. {getMenuItem(IssueSortOptions.USER)}
  58. <Feature features={['issue-list-trend-sort']}>
  59. {getMenuItem(IssueSortOptions.TREND)}
  60. </Feature>
  61. </React.Fragment>
  62. </StyledDropdownControl>
  63. );
  64. };
  65. export default IssueListSortOptions;
  66. const StyledTooltip = styled(Tooltip)`
  67. width: 100%;
  68. `;
  69. const StyledDropdownControl = styled(DropdownControl)`
  70. z-index: ${p => p.theme.zIndex.issuesList.sortOptions};
  71. button {
  72. width: 100%;
  73. }
  74. @media (max-width: ${p => p.theme.breakpoints[2]}) {
  75. order: 2;
  76. }
  77. `;