spanSamplesTable.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import type {ComponentProps} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import GridEditable, {
  5. COL_WIDTH_UNDEFINED,
  6. type GridColumnHeader,
  7. } from 'sentry/components/gridEditable';
  8. import {t} from 'sentry/locale';
  9. import type {Organization} from 'sentry/types';
  10. import type {EventsMetaType} from 'sentry/utils/discover/eventView';
  11. import {getFieldRenderer} from 'sentry/utils/discover/fieldRenderers';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import useOrganization from 'sentry/utils/useOrganization';
  14. import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
  15. import {TransactionIdCell} from 'sentry/views/starfish/components/tableCells/transactionIdCell';
  16. import type {IndexedResponse} from 'sentry/views/starfish/types';
  17. import {SpanIndexedField} from 'sentry/views/starfish/types';
  18. type ColumnKeys =
  19. | SpanIndexedField.PROJECT
  20. | SpanIndexedField.TRANSACTION_ID
  21. | SpanIndexedField.ID
  22. | SpanIndexedField.SPAN_DESCRIPTION
  23. | SpanIndexedField.RESPONSE_CODE;
  24. type Row = Pick<IndexedResponse, ColumnKeys>;
  25. type Column = GridColumnHeader<ColumnKeys>;
  26. const COLUMN_ORDER: Column[] = [
  27. {
  28. key: SpanIndexedField.TRANSACTION_ID,
  29. name: t('Event ID'),
  30. width: COL_WIDTH_UNDEFINED,
  31. },
  32. {
  33. key: SpanIndexedField.RESPONSE_CODE,
  34. name: t('Status'),
  35. width: COL_WIDTH_UNDEFINED,
  36. },
  37. {
  38. key: SpanIndexedField.SPAN_DESCRIPTION,
  39. name: t('URL'),
  40. width: COL_WIDTH_UNDEFINED,
  41. },
  42. ];
  43. interface Props {
  44. data: Row[];
  45. isLoading: boolean;
  46. error?: Error | null;
  47. highlightedSpanId?: string;
  48. meta?: EventsMetaType;
  49. onSampleMouseOut?: ComponentProps<typeof GridEditable>['onRowMouseOut'];
  50. onSampleMouseOver?: ComponentProps<typeof GridEditable>['onRowMouseOver'];
  51. }
  52. export function SpanSamplesTable({
  53. data,
  54. isLoading,
  55. error,
  56. meta,
  57. onSampleMouseOver,
  58. onSampleMouseOut,
  59. highlightedSpanId,
  60. }: Props) {
  61. const location = useLocation();
  62. const organization = useOrganization();
  63. return (
  64. <GridEditable
  65. aria-label={t('Span Samples')}
  66. isLoading={isLoading}
  67. error={error}
  68. data={data}
  69. columnOrder={COLUMN_ORDER}
  70. columnSortBy={[]}
  71. grid={{
  72. renderHeadCell: col =>
  73. renderHeadCell({
  74. column: col,
  75. location,
  76. }),
  77. renderBodyCell: (column, row) =>
  78. renderBodyCell(column, row, meta, location, organization),
  79. }}
  80. highlightedRowKey={data.findIndex(row => row.span_id === highlightedSpanId)}
  81. onRowMouseOver={onSampleMouseOver}
  82. onRowMouseOut={onSampleMouseOut}
  83. location={location}
  84. />
  85. );
  86. }
  87. function renderBodyCell(
  88. column: Column,
  89. row: Row,
  90. meta: EventsMetaType | undefined,
  91. location: Location,
  92. organization: Organization
  93. ) {
  94. if (column.key === SpanIndexedField.TRANSACTION_ID) {
  95. return (
  96. <TransactionIdCell
  97. orgSlug={organization.slug}
  98. projectSlug={row.project}
  99. transactionId={row[SpanIndexedField.TRANSACTION_ID]}
  100. spanId={row[SpanIndexedField.ID]}
  101. />
  102. );
  103. }
  104. if (column.key === SpanIndexedField.SPAN_DESCRIPTION) {
  105. return <SpanDescriptionCell>{row[column.key]}</SpanDescriptionCell>;
  106. }
  107. if (!meta?.fields) {
  108. return row[column.key];
  109. }
  110. const renderer = getFieldRenderer(column.key, meta.fields, false);
  111. return renderer(row, {
  112. location,
  113. organization,
  114. unit: meta.units?.[column.key],
  115. });
  116. }
  117. const SpanDescriptionCell = styled('span')`
  118. word-break: break-word;
  119. `;