utils.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {Event} from 'sentry/types/event';
  2. import {defined} from 'sentry/utils';
  3. import {Context} from './types';
  4. /**
  5. * Generates a predicate to filter a list of contexts for an event.
  6. *
  7. * This is highly domain logic.
  8. */
  9. export const makeContextFilter = (event: Event) =>
  10. function (context: Context) {
  11. // if the operating system is macOS, we want to hide devices called "Mac"
  12. // which don't have any additional info
  13. if (context.keys.includes('device')) {
  14. const {model, arch} = event.contexts?.device ?? {};
  15. const {name: os} = event.contexts?.os ?? event.contexts?.client_os ?? {};
  16. if (model === 'Mac' && !arch && os?.toLowerCase().includes('mac')) {
  17. return false;
  18. }
  19. }
  20. // do not show the context summary if only runtime raw_description is defined
  21. // (without name or version)
  22. if (
  23. context.keys.includes('runtime') &&
  24. event.contexts.runtime?.raw_description &&
  25. !(event.contexts.runtime?.name || event.contexts.runtime?.version)
  26. ) {
  27. return false;
  28. }
  29. return true;
  30. };
  31. /**
  32. * Generates the class name used for contexts
  33. */
  34. export function generateIconName(
  35. name?: string | boolean | null,
  36. version?: string
  37. ): string {
  38. if (!defined(name) || typeof name === 'boolean') {
  39. return '';
  40. }
  41. const lowerCaseName = name.toLowerCase();
  42. // amazon fire tv device id changes with version: AFTT, AFTN, AFTS, AFTA, AFTVA (alexa), ...
  43. if (lowerCaseName.startsWith('aft')) {
  44. return 'amazon';
  45. }
  46. if (lowerCaseName.startsWith('sm-') || lowerCaseName.startsWith('st-')) {
  47. return 'samsung';
  48. }
  49. if (lowerCaseName.startsWith('moto')) {
  50. return 'motorola';
  51. }
  52. if (lowerCaseName.startsWith('pixel')) {
  53. return 'google';
  54. }
  55. const formattedName = name
  56. .split(/\d/)[0]
  57. .toLowerCase()
  58. .replace(/[^a-z0-9\-]+/g, '-')
  59. .replace(/\-+$/, '')
  60. .replace(/^\-+/, '');
  61. if (formattedName === 'edge' && version) {
  62. const majorVersion = version.split('.')[0];
  63. const isLegacyEdge = majorVersion >= '12' && majorVersion <= '18';
  64. return isLegacyEdge ? 'legacy-edge' : 'edge';
  65. }
  66. return formattedName;
  67. }