utils.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {Fragment} from 'react';
  2. import {formatAddress, getImageRange} from 'sentry/components/events/interfaces/utils';
  3. import {Image, ImageStatus} from 'sentry/types/debugImage';
  4. import {defined} from 'sentry/utils';
  5. const IMAGE_ADDR_LEN = 12;
  6. export const IMAGE_AND_CANDIDATE_LIST_MAX_HEIGHT = 400;
  7. export function getStatusWeight(status?: ImageStatus | null) {
  8. switch (status) {
  9. case null:
  10. case undefined:
  11. case ImageStatus.UNUSED:
  12. return 0;
  13. case ImageStatus.FOUND:
  14. return 1;
  15. default:
  16. return 2;
  17. }
  18. }
  19. export function combineStatus(
  20. debugStatus?: ImageStatus | null,
  21. unwindStatus?: ImageStatus | null
  22. ): ImageStatus {
  23. const debugWeight = getStatusWeight(debugStatus);
  24. const unwindWeight = getStatusWeight(unwindStatus);
  25. const combined = debugWeight >= unwindWeight ? debugStatus : unwindStatus;
  26. return combined || ImageStatus.UNUSED;
  27. }
  28. export function getFileName(path?: string | null) {
  29. if (!path) {
  30. return undefined;
  31. }
  32. const directorySeparator = /^([a-z]:\\|\\\\)/i.test(path) ? '\\' : '/';
  33. return path.split(directorySeparator).pop();
  34. }
  35. export function normalizeId(id?: string) {
  36. return id?.trim().toLowerCase().replace(/[- ]/g, '') ?? '';
  37. }
  38. export function shouldSkipSection(
  39. filteredImages: Array<Image>,
  40. images: Array<Image | null>
  41. ) {
  42. if (filteredImages.length) {
  43. return false;
  44. }
  45. const definedImages = images.filter(image => defined(image));
  46. if (!definedImages.length) {
  47. return true;
  48. }
  49. if ((definedImages as Array<Image>).every(image => image.type === 'proguard')) {
  50. return true;
  51. }
  52. return false;
  53. }
  54. export function getImageAddress(image: Image) {
  55. const [startAddress, endAddress] = getImageRange(image);
  56. if (startAddress && endAddress) {
  57. return (
  58. <Fragment>
  59. <span>{formatAddress(startAddress, IMAGE_ADDR_LEN)}</span>
  60. {' \u2013 '}
  61. <span>{formatAddress(endAddress, IMAGE_ADDR_LEN)}</span>
  62. </Fragment>
  63. );
  64. }
  65. return undefined;
  66. }