parseIssuePrioritySearch.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import type {TokenResult} from 'sentry/components/searchSyntax/parser';
  2. import {parseSearch, Token} from 'sentry/components/searchSyntax/parser';
  3. import {PriorityLevel} from 'sentry/types/group';
  4. const VALID_PRIORITIES = new Set([
  5. PriorityLevel.HIGH,
  6. PriorityLevel.MEDIUM,
  7. PriorityLevel.LOW,
  8. ]);
  9. export function parseIssuePrioritySearch(query: string) {
  10. const parsed = parseSearch(query);
  11. const issuePriorityToken = parsed?.find(
  12. token => token.type === Token.FILTER && token.key.text === 'issue.priority'
  13. ) as TokenResult<Token.FILTER> | undefined;
  14. if (!issuePriorityToken) {
  15. return VALID_PRIORITIES;
  16. }
  17. const values =
  18. issuePriorityToken.value.type === Token.VALUE_TEXT_LIST
  19. ? issuePriorityToken.value.items.map(item => item.value?.text)
  20. : [issuePriorityToken.value.text];
  21. const validValues = values
  22. .map(value => value?.toLowerCase())
  23. .filter(value => VALID_PRIORITIES.has(value as PriorityLevel));
  24. if (issuePriorityToken.negated) {
  25. const priorities = new Set(VALID_PRIORITIES);
  26. for (const value of validValues) {
  27. priorities.delete(value as PriorityLevel);
  28. }
  29. return priorities;
  30. }
  31. return new Set(validValues);
  32. }