resourceSummaryTable.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import {Fragment} from 'react';
  2. import {Link} from 'react-router';
  3. import FileSize from 'sentry/components/fileSize';
  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 {t} from 'sentry/locale';
  11. import {RateUnits} from 'sentry/utils/discover/fields';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import {useParams} from 'sentry/utils/useParams';
  14. import {useResourcePagesQuery} from 'sentry/views/performance/browser/resources/utils/useResourcePageQuery';
  15. import {useResourceSummarySort} from 'sentry/views/performance/browser/resources/utils/useResourceSummarySort';
  16. import {DurationCell} from 'sentry/views/starfish/components/tableCells/durationCell';
  17. import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
  18. import {ThroughputCell} from 'sentry/views/starfish/components/tableCells/throughputCell';
  19. import {DataTitles, getThroughputTitle} from 'sentry/views/starfish/views/spans/types';
  20. type Row = {
  21. 'avg(http.response_content_length)': number;
  22. 'avg(span.self_time)': number;
  23. 'spm()': number;
  24. transaction: string;
  25. };
  26. type Column = GridColumnHeader<keyof Row>;
  27. function ResourceSummaryTable() {
  28. const location = useLocation();
  29. const {groupId} = useParams();
  30. const sort = useResourceSummarySort();
  31. const {data, isLoading, pageLinks} = useResourcePagesQuery(groupId, {sort});
  32. const columnOrder: GridColumnOrder<keyof Row>[] = [
  33. {key: 'transaction', width: COL_WIDTH_UNDEFINED, name: 'Found on page'},
  34. {
  35. key: 'spm()',
  36. width: COL_WIDTH_UNDEFINED,
  37. name: getThroughputTitle('http'),
  38. },
  39. {
  40. key: 'avg(span.self_time)',
  41. width: COL_WIDTH_UNDEFINED,
  42. name: t('Avg Duration'),
  43. },
  44. {
  45. key: 'avg(http.response_content_length)',
  46. width: COL_WIDTH_UNDEFINED,
  47. name: DataTitles['avg(http.response_content_length)'],
  48. },
  49. ];
  50. const renderBodyCell = (col: Column, row: Row) => {
  51. const {key} = col;
  52. if (key === 'spm()') {
  53. return <ThroughputCell rate={row[key] * 60} unit={RateUnits.PER_SECOND} />;
  54. }
  55. if (key === 'avg(span.self_time)') {
  56. return <DurationCell milliseconds={row[key]} />;
  57. }
  58. if (key === 'avg(http.response_content_length)') {
  59. return <FileSize bytes={row[key]} />;
  60. }
  61. if (key === 'transaction') {
  62. return (
  63. <Link
  64. to={{
  65. pathname: location.pathname,
  66. query: {
  67. ...location.query,
  68. transaction: row[key],
  69. },
  70. }}
  71. >
  72. {row[key]}
  73. </Link>
  74. );
  75. }
  76. return <span>{row[key]}</span>;
  77. };
  78. return (
  79. <Fragment>
  80. <GridEditable
  81. data={data || []}
  82. isLoading={isLoading}
  83. columnOrder={columnOrder}
  84. columnSortBy={[
  85. {
  86. key: sort.field,
  87. order: sort.kind,
  88. },
  89. ]}
  90. grid={{
  91. renderHeadCell: column =>
  92. renderHeadCell({
  93. column,
  94. location,
  95. sort,
  96. }),
  97. renderBodyCell,
  98. }}
  99. location={location}
  100. />
  101. <Pagination pageLinks={pageLinks} />
  102. </Fragment>
  103. );
  104. }
  105. export const getActionName = (transactionOp: string) => {
  106. switch (transactionOp) {
  107. case 'ui.action.click':
  108. return 'Click';
  109. default:
  110. return transactionOp;
  111. }
  112. };
  113. export default ResourceSummaryTable;