utils.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {Location} from 'history';
  2. import {GridColumnOrder} from 'sentry/components/gridEditable';
  3. import SortLink from 'sentry/components/gridEditable/sortLink';
  4. import {t} from 'sentry/locale';
  5. import {SelectValue} from 'sentry/types';
  6. import {defined} from 'sentry/utils';
  7. import {decodeScalar} from 'sentry/utils/queryString';
  8. type ColorEncoding =
  9. | 'version' // this will use a concatenation of `app_version_name` and `app_version`
  10. | 'device_manufacturer'
  11. | 'device_model'
  12. | 'device_os_version'
  13. | 'transaction_name';
  14. const COLOR_ENCODING_LABELS: Record<ColorEncoding, string> = {
  15. version: t('App Version'),
  16. device_manufacturer: t('Device Manufacturer'),
  17. device_model: t('Device Model'),
  18. device_os_version: t('Device Os Version'),
  19. transaction_name: t('Transaction Name'),
  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 'transaction_name';
  30. }
  31. export function renderTableHeader<K>(rightAlignedColumns: Set<K>) {
  32. return (column: GridColumnOrder<K>, _columnIndex: number) => {
  33. return (
  34. <SortLink
  35. align={rightAlignedColumns.has(column.key) ? 'right' : 'left'}
  36. title={column.name}
  37. direction={undefined}
  38. canSort={false}
  39. generateSortLink={() => undefined}
  40. />
  41. );
  42. };
  43. }