interactionTable.tsx 3.4 KB

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