utils.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. | 'version' // this will use a concatenation of `app_version_name` and `app_version`
  8. | 'device_manufacturer'
  9. | 'device_model'
  10. | 'device_os_version'
  11. | 'transaction_name';
  12. const COLOR_ENCODING_LABELS: Record<ColorEncoding, string> = {
  13. version: t('App Version'),
  14. device_manufacturer: t('Device Manufacturer'),
  15. device_model: t('Device Model'),
  16. device_os_version: t('Device Os Version'),
  17. transaction_name: t('Transaction Name'),
  18. };
  19. export const COLOR_ENCODINGS: SelectValue<ColorEncoding>[] = Object.entries(
  20. COLOR_ENCODING_LABELS
  21. ).map(([value, label]) => ({label, value: value as ColorEncoding}));
  22. export function getColorEncodingFromLocation(location: Location): ColorEncoding {
  23. const colorCoding = decodeScalar(location.query.colorEncoding);
  24. if (defined(colorCoding) && COLOR_ENCODING_LABELS.hasOwnProperty(colorCoding)) {
  25. return colorCoding as ColorEncoding;
  26. }
  27. return 'transaction_name';
  28. }