resourceSummaryTable.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 {RateUnits} from 'sentry/utils/discover/fields';
  9. import {useLocation} from 'sentry/utils/useLocation';
  10. import {useParams} from 'sentry/utils/useParams';
  11. import {useResourcePagesQuery} from 'sentry/views/performance/browser/resources/utils/useResourcePageQuery';
  12. import {useResourceSummarySort} from 'sentry/views/performance/browser/resources/utils/useResourceSummarySort';
  13. import {DurationCell} from 'sentry/views/starfish/components/tableCells/durationCell';
  14. import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
  15. import {ThroughputCell} from 'sentry/views/starfish/components/tableCells/throughputCell';
  16. type Row = {
  17. 'avg(http.response_content_length)': number;
  18. 'avg(span.self_time)': number;
  19. 'spm()': number;
  20. transaction: string;
  21. };
  22. type Column = GridColumnHeader<keyof Row>;
  23. function ResourceSummaryTable() {
  24. const location = useLocation();
  25. const {groupId} = useParams();
  26. const sort = useResourceSummarySort();
  27. const {data, isLoading} = useResourcePagesQuery(groupId, {sort});
  28. const columnOrder: GridColumnOrder<keyof Row>[] = [
  29. {key: 'transaction', width: COL_WIDTH_UNDEFINED, name: 'Found on page'},
  30. {
  31. key: 'spm()',
  32. width: COL_WIDTH_UNDEFINED,
  33. name: 'Throughput',
  34. },
  35. {
  36. key: 'avg(span.self_time)',
  37. width: COL_WIDTH_UNDEFINED,
  38. name: 'Avg Duration',
  39. },
  40. {
  41. key: 'avg(http.response_content_length)',
  42. width: COL_WIDTH_UNDEFINED,
  43. name: 'Avg Resource Size',
  44. },
  45. ];
  46. const renderBodyCell = (col: Column, row: Row) => {
  47. const {key} = col;
  48. if (key === 'spm()') {
  49. return <ThroughputCell rate={row[key] * 60} unit={RateUnits.PER_SECOND} />;
  50. }
  51. if (key === 'avg(span.self_time)') {
  52. return <DurationCell milliseconds={row[key]} />;
  53. }
  54. if (key === 'transaction') {
  55. return (
  56. <Link
  57. to={{
  58. pathname: location.pathname,
  59. query: {
  60. ...location.query,
  61. transaction: row[key],
  62. },
  63. }}
  64. >
  65. {row[key]}
  66. </Link>
  67. );
  68. }
  69. return <span>{row[key]}</span>;
  70. };
  71. return (
  72. <Fragment>
  73. <GridEditable
  74. data={data || []}
  75. isLoading={isLoading}
  76. columnOrder={columnOrder}
  77. columnSortBy={[
  78. {
  79. key: sort.field,
  80. order: sort.kind,
  81. },
  82. ]}
  83. grid={{
  84. renderHeadCell: column =>
  85. renderHeadCell({
  86. column,
  87. location,
  88. sort,
  89. }),
  90. renderBodyCell,
  91. }}
  92. location={location}
  93. />
  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 ResourceSummaryTable;