traceStatus.tsx 759 B

1234567891011121314151617181920212223
  1. import {decodeScalar} from 'sentry/utils/queryString';
  2. import {TRACE_STATUS_OPTIONS} from 'sentry/views/insights/queues/settings';
  3. // Include default value of '' that represents all options
  4. const OPTIONS = ['', ...TRACE_STATUS_OPTIONS] as const;
  5. const DEFAULT = '';
  6. type TraceStatus = (typeof OPTIONS)[number];
  7. export default function decode(value: string | string[] | undefined | null): TraceStatus {
  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 TraceStatus {
  15. // Manually widen to allow the comparison to string
  16. return (OPTIONS as unknown as string[]).includes(maybeOption as TraceStatus);
  17. }