fieldRenderers.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  2. import Link from 'sentry/components/links/link';
  3. import type {DateString} from 'sentry/types';
  4. import {Container} from 'sentry/utils/discover/styles';
  5. import {getShortEventId} from 'sentry/utils/events';
  6. import {getTransactionDetailsUrl} from 'sentry/utils/performance/urls';
  7. import Projects from 'sentry/utils/projects';
  8. import {useLocation} from 'sentry/utils/useLocation';
  9. import useOrganization from 'sentry/utils/useOrganization';
  10. import usePageFilters from 'sentry/utils/usePageFilters';
  11. import useProjects from 'sentry/utils/useProjects';
  12. import {getTraceDetailsUrl} from 'sentry/views/performance/traceDetails/utils';
  13. import {transactionSummaryRouteWithQuery} from 'sentry/views/performance/transactionSummary/utils';
  14. interface ProjectRendererProps {
  15. projectSlug: string;
  16. }
  17. export function ProjectRenderer({projectSlug}: ProjectRendererProps) {
  18. const organization = useOrganization();
  19. return (
  20. <Container>
  21. <Projects orgId={organization.slug} slugs={[projectSlug]}>
  22. {({projects}) => {
  23. const project = projects.find(p => p.slug === projectSlug);
  24. return (
  25. <ProjectBadge
  26. project={project ? project : {slug: projectSlug}}
  27. avatarSize={16}
  28. />
  29. );
  30. }}
  31. </Projects>
  32. </Container>
  33. );
  34. }
  35. interface SpanIdRendererProps {
  36. projectSlug: string;
  37. spanId: string;
  38. transactionId: string;
  39. }
  40. export function SpanIdRenderer({
  41. projectSlug,
  42. spanId,
  43. transactionId,
  44. }: SpanIdRendererProps) {
  45. const organization = useOrganization();
  46. const target = getTransactionDetailsUrl(
  47. organization.slug,
  48. `${projectSlug}:${transactionId}`,
  49. undefined,
  50. undefined,
  51. spanId
  52. );
  53. return <Link to={target}>{getShortEventId(spanId)}</Link>;
  54. }
  55. interface TraceIdRendererProps {
  56. traceId: string;
  57. timestamp?: DateString;
  58. transactionId?: string;
  59. }
  60. export function TraceIdRenderer({
  61. traceId,
  62. timestamp,
  63. transactionId,
  64. }: TraceIdRendererProps) {
  65. const organization = useOrganization();
  66. const {selection} = usePageFilters();
  67. const stringOrNumberTimestamp =
  68. timestamp instanceof Date ? timestamp.toISOString() : timestamp ?? '';
  69. const target = getTraceDetailsUrl(
  70. organization,
  71. traceId,
  72. {
  73. start: selection.datetime.start,
  74. end: selection.datetime.end,
  75. statsPeriod: selection.datetime.period,
  76. },
  77. {},
  78. stringOrNumberTimestamp,
  79. transactionId
  80. );
  81. return (
  82. <Container>
  83. <Link to={target}>{getShortEventId(traceId)}</Link>
  84. </Container>
  85. );
  86. }
  87. interface TransactionIdRendererProps {
  88. projectSlug: string;
  89. transactionId: string;
  90. }
  91. export function TransactionIdRenderer({
  92. projectSlug,
  93. transactionId,
  94. }: TransactionIdRendererProps) {
  95. const organization = useOrganization();
  96. const target = getTransactionDetailsUrl(
  97. organization.slug,
  98. `${projectSlug}:${transactionId}`,
  99. undefined,
  100. undefined
  101. );
  102. return <Link to={target}>{getShortEventId(transactionId)}</Link>;
  103. }
  104. interface TransactionRendererProps {
  105. projectSlug: string;
  106. transaction: string;
  107. }
  108. export function TransactionRenderer({
  109. projectSlug,
  110. transaction,
  111. }: TransactionRendererProps) {
  112. const location = useLocation();
  113. const organization = useOrganization();
  114. const {projects} = useProjects({slugs: [projectSlug]});
  115. const target = transactionSummaryRouteWithQuery({
  116. orgSlug: organization.slug,
  117. transaction,
  118. query: {
  119. ...location.query,
  120. query: undefined,
  121. },
  122. projectID: String(projects[0]?.id ?? ''),
  123. });
  124. return (
  125. <Container>
  126. <Link to={target}>{transaction}</Link>
  127. </Container>
  128. );
  129. }