resourceSummaryTable.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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(span.self_time)': number;
  18. 'spm()': number;
  19. transaction: string;
  20. };
  21. type Column = GridColumnHeader<keyof Row>;
  22. function ResourceSummaryTable() {
  23. const location = useLocation();
  24. const {groupId} = useParams();
  25. const sort = useResourceSummarySort();
  26. const {data, isLoading} = useResourcePagesQuery(groupId, {sort});
  27. const columnOrder: GridColumnOrder<keyof Row>[] = [
  28. {key: 'transaction', width: COL_WIDTH_UNDEFINED, name: 'Found on page'},
  29. {
  30. key: 'spm()',
  31. width: COL_WIDTH_UNDEFINED,
  32. name: 'Throughput',
  33. },
  34. {
  35. key: 'avg(span.self_time)',
  36. width: COL_WIDTH_UNDEFINED,
  37. name: 'Avg Duration',
  38. },
  39. ];
  40. const renderBodyCell = (col: Column, row: Row) => {
  41. const {key} = col;
  42. if (key === 'spm()') {
  43. return <ThroughputCell rate={row[key] * 60} unit={RateUnits.PER_SECOND} />;
  44. }
  45. if (key === 'avg(span.self_time)') {
  46. return <DurationCell milliseconds={row[key]} />;
  47. }
  48. if (key === 'transaction') {
  49. return (
  50. <Link
  51. to={{
  52. pathname: location.pathname,
  53. query: {
  54. ...location.query,
  55. transaction: row[key],
  56. },
  57. }}
  58. >
  59. {row[key]}
  60. </Link>
  61. );
  62. }
  63. return <span>{row[key]}</span>;
  64. };
  65. return (
  66. <Fragment>
  67. <GridEditable
  68. data={data || []}
  69. isLoading={isLoading}
  70. columnOrder={columnOrder}
  71. columnSortBy={[
  72. {
  73. key: sort.field,
  74. order: sort.kind,
  75. },
  76. ]}
  77. grid={{
  78. renderHeadCell: column =>
  79. renderHeadCell({
  80. column,
  81. location,
  82. sort,
  83. }),
  84. renderBodyCell,
  85. }}
  86. location={location}
  87. />
  88. </Fragment>
  89. );
  90. }
  91. export const getActionName = (transactionOp: string) => {
  92. switch (transactionOp) {
  93. case 'ui.action.click':
  94. return 'Click';
  95. default:
  96. return transactionOp;
  97. }
  98. };
  99. export default ResourceSummaryTable;