interactionTable.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {Link} from 'react-router';
  2. import GridEditable, {
  3. COL_WIDTH_UNDEFINED,
  4. GridColumnHeader,
  5. GridColumnOrder,
  6. GridColumnSortBy,
  7. } from 'sentry/components/gridEditable';
  8. import {useLocation} from 'sentry/utils/useLocation';
  9. import {useInteractionsQuery} from 'sentry/views/performance/browser/useInteractionsQuery';
  10. type Row = {
  11. component: string;
  12. p75: number;
  13. page: string;
  14. 'span.action': string;
  15. 'span.group': string;
  16. };
  17. type Column = GridColumnHeader<keyof Row>;
  18. function InteractionsTable() {
  19. const location = useLocation();
  20. const columnOrder: GridColumnOrder<keyof Row>[] = [
  21. {key: 'span.group', width: COL_WIDTH_UNDEFINED, name: 'Interaction'},
  22. {key: 'page', width: COL_WIDTH_UNDEFINED, name: 'Page'},
  23. {key: 'p75', width: COL_WIDTH_UNDEFINED, name: 'Duration (p75)'},
  24. ];
  25. const {data, isLoading} = useInteractionsQuery();
  26. const tableData: Row[] =
  27. !isLoading && data.length
  28. ? data.map(row => ({
  29. 'span.group': 'NOT IMPLEMENTED',
  30. component: row.interactionElement,
  31. p75: row['p75(transaction.duration)'],
  32. page: row.transaction,
  33. 'span.action': getFriendlyActionName(row['transaction.op']),
  34. }))
  35. : [];
  36. const sort: GridColumnSortBy<keyof Row> = {key: 'p75', order: 'desc'};
  37. const renderHeadCell = (col: Column) => {
  38. return <span>{col.name}</span>;
  39. };
  40. const renderBodyCell = (col: Column, row: Row) => {
  41. const {key} = col;
  42. if (key === 'span.group') {
  43. const spanGroup = row['span.group'];
  44. return (
  45. <Link to={`/performance/browser/interactions/${spanGroup}`}>
  46. {row['span.action']} on {row.component}
  47. </Link>
  48. );
  49. }
  50. return <span>{row[key]}</span>;
  51. };
  52. return (
  53. <GridEditable
  54. data={tableData}
  55. isLoading={isLoading}
  56. columnOrder={columnOrder}
  57. columnSortBy={[sort]}
  58. grid={{renderHeadCell, renderBodyCell}}
  59. location={location}
  60. />
  61. );
  62. }
  63. const getFriendlyActionName = (action: string) => {
  64. switch (action) {
  65. case 'ui.action.click':
  66. return 'Click';
  67. default:
  68. return action;
  69. }
  70. };
  71. export default InteractionsTable;