sampleEvents.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import DateTime from 'sentry/components/dateTime';
  2. import Duration from 'sentry/components/duration';
  3. import GridEditable, {GridColumnHeader} from 'sentry/components/gridEditable';
  4. import Link from 'sentry/components/links/link';
  5. import EventView from 'sentry/utils/discover/eventView';
  6. import {
  7. DiscoverQueryProps,
  8. useGenericDiscoverQuery,
  9. } from 'sentry/utils/discover/genericDiscoverQuery';
  10. import {useLocation} from 'sentry/utils/useLocation';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import {TextAlignLeft} from 'sentry/views/starfish/components/textAlign';
  13. type Props = {
  14. eventView: EventView;
  15. };
  16. type DataRow = {
  17. id: string;
  18. profile_id: string;
  19. timestamp: string;
  20. 'transaction.duration': number;
  21. };
  22. type Keys = 'id' | 'profile_id' | 'transaction.duration' | 'timestamp';
  23. type TableColumnHeader = GridColumnHeader<Keys>;
  24. const COLUMN_ORDER: TableColumnHeader[] = [
  25. {
  26. key: 'id',
  27. name: 'Event ID',
  28. width: 300,
  29. },
  30. {
  31. key: 'profile_id',
  32. name: 'Profile ID',
  33. width: 300,
  34. },
  35. {
  36. key: 'transaction.duration',
  37. name: 'Duration',
  38. width: -1,
  39. },
  40. {
  41. key: 'timestamp',
  42. name: 'Timestamp',
  43. width: -1,
  44. },
  45. ];
  46. export function SampleEvents({eventView}: Props) {
  47. const location = useLocation();
  48. const organization = useOrganization();
  49. const sampleEventsEventView = eventView
  50. .clone()
  51. .withColumns([
  52. {
  53. field: 'transaction.duration',
  54. kind: 'field',
  55. },
  56. {
  57. field: 'profile_id',
  58. kind: 'field',
  59. },
  60. {
  61. field: 'timestamp',
  62. kind: 'field',
  63. },
  64. ])
  65. .withSorts([
  66. {
  67. field: 'transaction.duration',
  68. kind: 'desc',
  69. },
  70. ]);
  71. function renderBodyCell(column: TableColumnHeader, row: DataRow): React.ReactNode {
  72. if (column.key === 'id') {
  73. return (
  74. <Link to={`/performance/${row['project.name']}:${row.id}`}>
  75. {row.id.slice(0, 8)}
  76. </Link>
  77. );
  78. }
  79. if (column.key === 'profile_id') {
  80. return row.profile_id ? (
  81. <Link
  82. to={`/profiling/profile/${row['project.name']}/${row.profile_id}/flamechart/`}
  83. >
  84. {row.profile_id.slice(0, 8)}
  85. </Link>
  86. ) : (
  87. '(no value)'
  88. );
  89. }
  90. if (column.key === 'timestamp') {
  91. return <DateTime date={row.timestamp} year timeZone seconds />;
  92. }
  93. if (column.key === 'transaction.duration') {
  94. return (
  95. <Duration
  96. seconds={row['transaction.duration'] / 1000}
  97. fixedDigits={2}
  98. abbreviation
  99. />
  100. );
  101. }
  102. return <TextAlignLeft>{row[column.key]}</TextAlignLeft>;
  103. }
  104. const {isLoading, data} = useGenericDiscoverQuery<any, DiscoverQueryProps>({
  105. route: 'events',
  106. eventView: sampleEventsEventView,
  107. referrer: 'starfish-transaction-summary-sample-events',
  108. limit: 5,
  109. location,
  110. orgSlug: organization.slug,
  111. getRequestPayload: () => ({
  112. ...sampleEventsEventView.getEventsAPIPayload(location),
  113. }),
  114. });
  115. return (
  116. <GridEditable
  117. isLoading={isLoading}
  118. data={data?.data}
  119. columnOrder={COLUMN_ORDER}
  120. columnSortBy={[]}
  121. location={location}
  122. grid={{
  123. renderBodyCell,
  124. }}
  125. />
  126. );
  127. }