utils.tsx 2.2 KB

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