spanSamplesTable.tsx 3.0 KB

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