retryCount.tsx 753 B

1234567891011121314151617181920212223
  1. import {decodeScalar} from 'sentry/utils/queryString';
  2. import {RETRY_COUNT_OPTIONS} from 'sentry/views/insights/queues/settings';
  3. // Include default value of '' that represents all options
  4. const OPTIONS = ['', ...RETRY_COUNT_OPTIONS] as const;
  5. const DEFAULT = '';
  6. type RetryCount = (typeof OPTIONS)[number];
  7. export default function decode(value: string | string[] | undefined | null): RetryCount {
  8. const decodedValue = decodeScalar(value, DEFAULT);
  9. if (isAValidOption(decodedValue)) {
  10. return decodedValue;
  11. }
  12. return DEFAULT;
  13. }
  14. function isAValidOption(maybeOption: string): maybeOption is RetryCount {
  15. // Manually widen to allow the comparison to string
  16. return (OPTIONS as unknown as string[]).includes(maybeOption as RetryCount);
  17. }