utils.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import {Location} from 'history';
  2. import {t} from 'sentry/locale';
  3. import {SelectValue} from 'sentry/types';
  4. import {defined} from 'sentry/utils';
  5. import {decodeScalar} from 'sentry/utils/queryString';
  6. type ColorEncoding =
  7. | 'app_version'
  8. | 'device_manufacturer'
  9. | 'device_model'
  10. | 'device_os_version'
  11. | 'interaction_name'
  12. | 'android_api_level';
  13. const COLOR_ENCODING_LABELS: Record<ColorEncoding, string> = {
  14. app_version: t('App Version'),
  15. device_manufacturer: t('Device Manufacturer'),
  16. device_model: t('Device Model'),
  17. device_os_version: t('Device Os Version'),
  18. interaction_name: t('Interaction Name'),
  19. android_api_level: t('Android Api Level'),
  20. };
  21. export const COLOR_ENCODINGS: SelectValue<ColorEncoding>[] = Object.entries(
  22. COLOR_ENCODING_LABELS
  23. ).map(([value, label]) => ({label, value: value as ColorEncoding}));
  24. export function getColorEncodingFromLocation(location: Location): ColorEncoding {
  25. const colorCoding = decodeScalar(location.query.colorEncoding);
  26. if (defined(colorCoding) && COLOR_ENCODING_LABELS.hasOwnProperty(colorCoding)) {
  27. return colorCoding as ColorEncoding;
  28. }
  29. return 'interaction_name';
  30. }