sampleTable.tsx 2.0 KB

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