sampleTable.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {Fragment} from 'react';
  2. import {Link} from 'react-router';
  3. import GridEditable, {
  4. COL_WIDTH_UNDEFINED,
  5. GridColumnHeader,
  6. GridColumnOrder,
  7. } from 'sentry/components/gridEditable';
  8. import Pagination from 'sentry/components/pagination';
  9. import {useLocation} from 'sentry/utils/useLocation';
  10. import {useInteractionQuery} from 'sentry/views/performance/browser/interactionSummary/useInteractionQuery';
  11. import {DurationCell} from 'sentry/views/starfish/components/tableCells/durationCell';
  12. import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
  13. type Row = {
  14. eventId: string;
  15. project: string;
  16. 'transaction.duration': number;
  17. };
  18. type Column = GridColumnHeader<keyof Row>;
  19. function InteractionSampleTable() {
  20. const location = useLocation();
  21. const columnOrder: GridColumnOrder<keyof Row>[] = [
  22. {key: 'eventId', width: COL_WIDTH_UNDEFINED, name: 'event'},
  23. {key: 'transaction.duration', width: COL_WIDTH_UNDEFINED, name: 'duration'},
  24. ];
  25. const {data, isLoading, pageLinks} = useInteractionQuery();
  26. const tableData: Row[] = data.length ? data : [];
  27. const renderBodyCell = (col: Column, row: Row) => {
  28. const {key} = col;
  29. if (key === 'transaction.duration') {
  30. return <DurationCell milliseconds={row[key]} />;
  31. }
  32. if (key === 'eventId') {
  33. return (
  34. <Link to={`/performance/${row.project}:${row.eventId}`}>
  35. {row.eventId.slice(0, 8)}
  36. </Link>
  37. );
  38. }
  39. return <span>{row[key]}</span>;
  40. };
  41. return (
  42. <Fragment>
  43. <GridEditable
  44. data={tableData}
  45. isLoading={isLoading}
  46. columnOrder={columnOrder}
  47. columnSortBy={[]}
  48. grid={{
  49. renderHeadCell: column =>
  50. renderHeadCell({
  51. column,
  52. location,
  53. }),
  54. renderBodyCell,
  55. }}
  56. location={location}
  57. />
  58. <Pagination pageLinks={pageLinks} />
  59. </Fragment>
  60. );
  61. }
  62. export default InteractionSampleTable;