breadcrumbs.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import type SvgIcon from 'sentry/icons/svgIcon';
  2. import type {Color} from 'sentry/utils/theme';
  3. export type IconProps = React.ComponentProps<typeof SvgIcon>;
  4. export enum BreadcrumbLevelType {
  5. FATAL = 'fatal',
  6. ERROR = 'error',
  7. WARNING = 'warning',
  8. INFO = 'info',
  9. DEBUG = 'debug',
  10. UNDEFINED = 'undefined',
  11. }
  12. export enum BreadcrumbType {
  13. INFO = 'info',
  14. DEBUG = 'debug',
  15. MESSAGE = 'message',
  16. QUERY = 'query',
  17. UI = 'ui',
  18. USER = 'user',
  19. EXCEPTION = 'exception',
  20. WARNING = 'warning',
  21. ERROR = 'error',
  22. DEFAULT = 'default',
  23. HTTP = 'http',
  24. NAVIGATION = 'navigation',
  25. SYSTEM = 'system',
  26. SESSION = 'session',
  27. TRANSACTION = 'transaction',
  28. INIT = 'init',
  29. }
  30. type BreadcrumbTypeBase = {
  31. level: BreadcrumbLevelType;
  32. // it's recommended
  33. category?: string | null;
  34. event_id?: string | null;
  35. message?: string;
  36. timestamp?: string;
  37. };
  38. export type BreadcrumbTypeSystem = {
  39. action: string;
  40. extras: Record<string, any>;
  41. type: BreadcrumbType.SYSTEM;
  42. } & BreadcrumbTypeBase;
  43. export type BreadcrumbTypeSession = {
  44. action: string;
  45. extras: Record<string, any>;
  46. type: BreadcrumbType.SESSION;
  47. } & BreadcrumbTypeBase;
  48. export type BreadcrumbTypeNavigation = {
  49. type: BreadcrumbType.NAVIGATION;
  50. data?: {
  51. from?: string;
  52. to?: string;
  53. };
  54. } & BreadcrumbTypeBase;
  55. export type BreadcrumbTypeHTTP = {
  56. type: BreadcrumbType.HTTP;
  57. data?: {
  58. method?:
  59. | 'POST'
  60. | 'PUT'
  61. | 'GET'
  62. | 'HEAD'
  63. | 'DELETE'
  64. | 'CONNECT'
  65. | 'OPTIONS'
  66. | 'TRACE'
  67. | 'PATCH';
  68. reason?: string;
  69. status_code?: number;
  70. url?: string;
  71. };
  72. } & BreadcrumbTypeBase;
  73. export type BreadcrumbTypeDefault = {
  74. type:
  75. | BreadcrumbType.INFO
  76. | BreadcrumbType.DEBUG
  77. | BreadcrumbType.QUERY
  78. | BreadcrumbType.UI
  79. | BreadcrumbType.USER
  80. | BreadcrumbType.EXCEPTION
  81. | BreadcrumbType.WARNING
  82. | BreadcrumbType.ERROR
  83. | BreadcrumbType.DEFAULT
  84. | BreadcrumbType.INIT
  85. | BreadcrumbType.SESSION
  86. | BreadcrumbType.SYSTEM
  87. | BreadcrumbType.TRANSACTION;
  88. data?: Record<string, any>;
  89. } & BreadcrumbTypeBase;
  90. export type RawCrumb =
  91. | BreadcrumbTypeNavigation
  92. | BreadcrumbTypeHTTP
  93. | BreadcrumbTypeDefault;
  94. export type Crumb = RawCrumb & {
  95. color: Color;
  96. description: string;
  97. id: number;
  98. };
  99. export function isBreadcrumbTypeDefault(
  100. breadcrumb: RawCrumb
  101. ): breadcrumb is BreadcrumbTypeDefault {
  102. return ![BreadcrumbType.HTTP, BreadcrumbType.NAVIGATION].includes(breadcrumb.type);
  103. }