interactionTable.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import {Fragment} from 'react';
  2. import {Link} from 'react-router';
  3. import * as qs from 'query-string';
  4. import type {GridColumnHeader, GridColumnOrder} from 'sentry/components/gridEditable';
  5. import GridEditable, {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  6. import Pagination from 'sentry/components/pagination';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import {BrowserStarfishFields} from 'sentry/views/performance/browser/useBrowserFilters';
  9. import type {ValidSort} from 'sentry/views/performance/browser/useBrowserSort';
  10. import {useInteractionsQuery} from 'sentry/views/performance/browser/useInteractionsQuery';
  11. import {DurationCell} from 'sentry/views/starfish/components/tableCells/durationCell';
  12. import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
  13. import {TextAlignRight} from 'sentry/views/starfish/components/textAlign';
  14. type Row = {
  15. 'count()': number;
  16. interactionElement: string;
  17. 'p75(transaction.duration)': number;
  18. 'span.group': string;
  19. transaction: string;
  20. 'transaction.op': string;
  21. };
  22. type Column = GridColumnHeader<keyof Row>;
  23. type Props = {
  24. sort: ValidSort;
  25. };
  26. function InteractionsTable({sort}: Props) {
  27. const location = useLocation();
  28. const columnOrder: GridColumnOrder<keyof Row>[] = [
  29. {key: 'span.group', width: COL_WIDTH_UNDEFINED, name: 'Interaction'},
  30. {key: 'transaction', width: COL_WIDTH_UNDEFINED, name: 'Page'},
  31. {key: 'count()', width: COL_WIDTH_UNDEFINED, name: 'Count'},
  32. {
  33. key: 'p75(transaction.duration)',
  34. width: COL_WIDTH_UNDEFINED,
  35. name: 'Duration (p75)',
  36. },
  37. ];
  38. const {data, isLoading, pageLinks} = useInteractionsQuery({sort});
  39. const tableData: Row[] =
  40. !isLoading && data.length
  41. ? data.map(row => ({
  42. 'span.group': 'NOT IMPLEMENTED',
  43. ...row,
  44. }))
  45. : [];
  46. const renderBodyCell = (col: Column, row: Row) => {
  47. const {key} = col;
  48. if (key === 'span.group') {
  49. return (
  50. <Link
  51. to={`/performance/browser/interactions/summary/?${qs.stringify({
  52. [BrowserStarfishFields.COMPONENT]: row.interactionElement,
  53. [BrowserStarfishFields.PAGE]: row.transaction,
  54. [BrowserStarfishFields.TRANSACTION_OP]: row['transaction.op'],
  55. })}`}
  56. >
  57. {getActionName(row['transaction.op'])}
  58. <span style={{fontWeight: 'bold'}}> {row.interactionElement}</span>
  59. </Link>
  60. );
  61. }
  62. if (key === 'p75(transaction.duration)') {
  63. return <DurationCell milliseconds={row[key]} />;
  64. }
  65. if (key === 'count()') {
  66. return <TextAlignRight>{row[key]}</TextAlignRight>;
  67. }
  68. return <span>{row[key]}</span>;
  69. };
  70. return (
  71. <Fragment>
  72. <GridEditable
  73. data={tableData}
  74. isLoading={isLoading}
  75. columnOrder={columnOrder}
  76. columnSortBy={[
  77. {
  78. key: sort.field,
  79. order: sort.kind,
  80. },
  81. ]}
  82. grid={{
  83. renderHeadCell: column =>
  84. renderHeadCell({
  85. column,
  86. location,
  87. sort,
  88. }),
  89. renderBodyCell,
  90. }}
  91. location={location}
  92. />
  93. <Pagination pageLinks={pageLinks} />
  94. </Fragment>
  95. );
  96. }
  97. export const getActionName = (transactionOp: string) => {
  98. switch (transactionOp) {
  99. case 'ui.action.click':
  100. return 'Click';
  101. default:
  102. return transactionOp;
  103. }
  104. };
  105. export default InteractionsTable;