mailboxPicker.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import Badge from 'sentry/components/badge/badge';
  2. import {Flex} from 'sentry/components/container/flex';
  3. import type decodeMailbox from 'sentry/components/feedback/decodeMailbox';
  4. import useMailboxCounts from 'sentry/components/feedback/list/useMailboxCounts';
  5. import {SegmentedControl} from 'sentry/components/segmentedControl';
  6. import {Tooltip} from 'sentry/components/tooltip';
  7. import {t} from 'sentry/locale';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. type Mailbox = ReturnType<typeof decodeMailbox>;
  10. interface Props {
  11. onChange: (next: Mailbox) => void;
  12. value: Mailbox;
  13. }
  14. const MAILBOXES = [
  15. {key: 'unresolved', label: t('Inbox')},
  16. {key: 'resolved', label: t('Resolved')},
  17. {key: 'ignored', label: t('Spam')},
  18. ];
  19. export default function MailboxPicker({onChange, value}: Props) {
  20. const organization = useOrganization();
  21. const {data} = useMailboxCounts({organization});
  22. const filteredMailboxes = MAILBOXES;
  23. return (
  24. <Flex justify="flex-end" flex="1 0 auto">
  25. <SegmentedControl
  26. size="xs"
  27. aria-label={t('Filter feedbacks')}
  28. value={value}
  29. onChange={onChange}
  30. >
  31. {filteredMailboxes.map(c => {
  32. const count = data?.[c.key];
  33. const display = count && count >= 100 ? '99+' : count;
  34. const title =
  35. count === 1 ? t('1 unassigned item') : t('%s unassigned items', display);
  36. return (
  37. <SegmentedControl.Item key={c.key} aria-label={c.label}>
  38. <Tooltip disabled={!count} title={title}>
  39. <Flex align="center">
  40. {c.label}
  41. {display ? <Badge type="gray" text={display} /> : null}
  42. </Flex>
  43. </Tooltip>
  44. </SegmentedControl.Item>
  45. );
  46. })}
  47. </SegmentedControl>
  48. </Flex>
  49. );
  50. }