spanSamplesTable.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import {Link} from 'react-router';
  2. import DateTime from 'sentry/components/dateTime';
  3. import GridEditable, {GridColumnHeader} from 'sentry/components/gridEditable';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import {SpanDurationBar} from 'sentry/views/performance/transactionSummary/transactionSpans/spanDetails/spanDetailsTable';
  6. import {DurationComparisonCell} from 'sentry/views/starfish/components/samplesTable/common';
  7. import {
  8. OverflowEllipsisTextContainer,
  9. TextAlignRight,
  10. } from 'sentry/views/starfish/components/textAlign';
  11. type Keys = 'transaction_id' | 'timestamp' | 'duration' | 'p95_comparison';
  12. type TableColumnHeader = GridColumnHeader<Keys>;
  13. const COLUMN_ORDER: TableColumnHeader[] = [
  14. {
  15. key: 'transaction_id',
  16. name: 'Event ID',
  17. width: 200,
  18. },
  19. {
  20. key: 'duration',
  21. name: 'Span Duration',
  22. width: 200,
  23. },
  24. {
  25. key: 'p95_comparison',
  26. name: 'Compared to P95',
  27. width: 200,
  28. },
  29. ];
  30. type SpanTableRow = {
  31. exclusive_time: number;
  32. p95Comparison: number;
  33. 'project.name': string;
  34. spanDuration: number;
  35. spanOp: string;
  36. span_id: string;
  37. timestamp: string;
  38. transaction: string;
  39. transactionDuration: number;
  40. transaction_id: string;
  41. user: string;
  42. };
  43. type Props = {
  44. data: SpanTableRow[];
  45. isLoading: boolean;
  46. p95: number;
  47. };
  48. export function SpanSamplesTable({isLoading, data, p95}: Props) {
  49. const location = useLocation();
  50. function renderHeadCell(column: GridColumnHeader): React.ReactNode {
  51. if (column.key === 'p95_comparison') {
  52. return (
  53. <TextAlignRight>
  54. <OverflowEllipsisTextContainer>{column.name}</OverflowEllipsisTextContainer>
  55. </TextAlignRight>
  56. );
  57. }
  58. return <OverflowEllipsisTextContainer>{column.name}</OverflowEllipsisTextContainer>;
  59. }
  60. function renderBodyCell(column: GridColumnHeader, row: SpanTableRow): React.ReactNode {
  61. if (column.key === 'transaction_id') {
  62. return (
  63. <Link
  64. to={`/performance/${row['project.name']}:${
  65. row.transaction_id
  66. }#span-${row.span_id.slice(19).replace('-', '')}`}
  67. >
  68. {row.transaction_id.slice(0, 8)}
  69. </Link>
  70. );
  71. }
  72. if (column.key === 'duration') {
  73. return (
  74. <SpanDurationBar
  75. spanOp={row.spanOp}
  76. spanDuration={row.spanDuration}
  77. transactionDuration={row.transactionDuration}
  78. />
  79. );
  80. }
  81. if (column.key === 'p95_comparison') {
  82. return <DurationComparisonCell duration={row.spanDuration} p95={p95} />;
  83. }
  84. if (column.key === 'timestamp') {
  85. return <DateTime date={row.timestamp} year timeZone seconds />;
  86. }
  87. return <span>{row[column.key]}</span>;
  88. }
  89. return (
  90. <GridEditable
  91. isLoading={isLoading}
  92. data={data}
  93. columnOrder={COLUMN_ORDER}
  94. columnSortBy={[]}
  95. grid={{
  96. renderHeadCell,
  97. renderBodyCell,
  98. }}
  99. location={location}
  100. />
  101. );
  102. }