resourceSummaryTable.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import {Fragment} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import type {GridColumnHeader, GridColumnOrder} from 'sentry/components/gridEditable';
  5. import GridEditable, {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  6. import Link from 'sentry/components/links/link';
  7. import type {CursorHandler} from 'sentry/components/pagination';
  8. import Pagination from 'sentry/components/pagination';
  9. import {t} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import {decodeScalar} from 'sentry/utils/queryString';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import {useParams} from 'sentry/utils/useParams';
  14. import {useResourcePagesQuery} from 'sentry/views/insights/browser/resources/queries/useResourcePageQuery';
  15. import {RESOURCE_THROUGHPUT_UNIT} from 'sentry/views/insights/browser/resources/settings';
  16. import {useResourceModuleFilters} from 'sentry/views/insights/browser/resources/utils/useResourceFilters';
  17. import {useResourceSummarySort} from 'sentry/views/insights/browser/resources/utils/useResourceSummarySort';
  18. import {FullSpanDescription} from 'sentry/views/insights/common/components/fullSpanDescription';
  19. import {DurationCell} from 'sentry/views/insights/common/components/tableCells/durationCell';
  20. import {renderHeadCell} from 'sentry/views/insights/common/components/tableCells/renderHeadCell';
  21. import ResourceSizeCell from 'sentry/views/insights/common/components/tableCells/resourceSizeCell';
  22. import {WiderHovercard} from 'sentry/views/insights/common/components/tableCells/spanDescriptionCell';
  23. import {ThroughputCell} from 'sentry/views/insights/common/components/tableCells/throughputCell';
  24. import {QueryParameterNames} from 'sentry/views/insights/common/views/queryParameters';
  25. import {
  26. DataTitles,
  27. getThroughputTitle,
  28. } from 'sentry/views/insights/common/views/spans/types';
  29. import {SpanIndexedField, SpanMetricsField} from 'sentry/views/insights/types';
  30. const {
  31. RESOURCE_RENDER_BLOCKING_STATUS,
  32. SPAN_SELF_TIME,
  33. HTTP_RESPONSE_CONTENT_LENGTH,
  34. TRANSACTION,
  35. } = SpanMetricsField;
  36. type Row = {
  37. 'avg(http.response_content_length)': number;
  38. 'avg(span.self_time)': number;
  39. 'resource.render_blocking_status': '' | 'non-blocking' | 'blocking';
  40. 'spm()': number;
  41. transaction: string;
  42. };
  43. type Column = GridColumnHeader<keyof Row>;
  44. function ResourceSummaryTable() {
  45. const location = useLocation();
  46. const {groupId} = useParams();
  47. const sort = useResourceSummarySort();
  48. const filters = useResourceModuleFilters();
  49. const cursor = decodeScalar(location.query?.[QueryParameterNames.PAGES_CURSOR]);
  50. const {data, isLoading, pageLinks} = useResourcePagesQuery(groupId, {
  51. sort,
  52. cursor,
  53. renderBlockingStatus: filters[RESOURCE_RENDER_BLOCKING_STATUS],
  54. });
  55. const columnOrder: GridColumnOrder<keyof Row>[] = [
  56. {key: 'transaction', width: COL_WIDTH_UNDEFINED, name: 'Found on page'},
  57. {
  58. key: 'spm()',
  59. width: COL_WIDTH_UNDEFINED,
  60. name: getThroughputTitle('http'),
  61. },
  62. {
  63. key: `avg(${SPAN_SELF_TIME})`,
  64. width: COL_WIDTH_UNDEFINED,
  65. name: t('Avg Duration'),
  66. },
  67. {
  68. key: `avg(${HTTP_RESPONSE_CONTENT_LENGTH})`,
  69. width: COL_WIDTH_UNDEFINED,
  70. name: DataTitles[`avg(${HTTP_RESPONSE_CONTENT_LENGTH})`],
  71. },
  72. {
  73. key: RESOURCE_RENDER_BLOCKING_STATUS,
  74. width: COL_WIDTH_UNDEFINED,
  75. name: t('Render Blocking'),
  76. },
  77. ];
  78. const renderBodyCell = (col: Column, row: Row) => {
  79. const {key} = col;
  80. if (key === 'spm()') {
  81. return <ThroughputCell rate={row[key]} unit={RESOURCE_THROUGHPUT_UNIT} />;
  82. }
  83. if (key === 'avg(span.self_time)') {
  84. return <DurationCell milliseconds={row[key]} />;
  85. }
  86. if (key === 'avg(http.response_content_length)') {
  87. return <ResourceSizeCell bytes={row[key]} />;
  88. }
  89. if (key === 'transaction') {
  90. const blockingStatus = row['resource.render_blocking_status'];
  91. let query = `!has:${RESOURCE_RENDER_BLOCKING_STATUS}`;
  92. if (blockingStatus) {
  93. query = `${RESOURCE_RENDER_BLOCKING_STATUS}:${blockingStatus}`;
  94. }
  95. const link = (
  96. <Link
  97. to={{
  98. pathname: location.pathname,
  99. query: {
  100. ...location.query,
  101. transaction: row[key],
  102. query: [query],
  103. },
  104. }}
  105. >
  106. {row[key]}
  107. </Link>
  108. );
  109. return (
  110. <DescriptionWrapper>
  111. <WiderHovercard
  112. position="right"
  113. body={
  114. <Fragment>
  115. <TitleWrapper>{t('Example')}</TitleWrapper>
  116. <FullSpanDescription
  117. group={groupId}
  118. language="http"
  119. filters={{
  120. [SpanIndexedField.RESOURCE_RENDER_BLOCKING_STATUS]:
  121. row[RESOURCE_RENDER_BLOCKING_STATUS],
  122. [SpanIndexedField.TRANSACTION]: row[TRANSACTION],
  123. }}
  124. />
  125. </Fragment>
  126. }
  127. >
  128. {link}
  129. </WiderHovercard>
  130. </DescriptionWrapper>
  131. );
  132. }
  133. if (key === RESOURCE_RENDER_BLOCKING_STATUS) {
  134. const value = row[key];
  135. if (value === 'blocking') {
  136. return <span>{t('Yes')}</span>;
  137. }
  138. if (value === 'non-blocking') {
  139. return <span>{t('No')}</span>;
  140. }
  141. return <span>{'-'}</span>;
  142. }
  143. return <span>{row[key]}</span>;
  144. };
  145. const handleCursor: CursorHandler = (newCursor, pathname, query) => {
  146. browserHistory.push({
  147. pathname,
  148. query: {...query, [QueryParameterNames.PAGES_CURSOR]: newCursor},
  149. });
  150. };
  151. return (
  152. <Fragment>
  153. <GridEditable
  154. data={data || []}
  155. isLoading={isLoading}
  156. columnOrder={columnOrder}
  157. columnSortBy={[
  158. {
  159. key: sort.field,
  160. order: sort.kind,
  161. },
  162. ]}
  163. grid={{
  164. renderHeadCell: column =>
  165. renderHeadCell({
  166. column,
  167. location,
  168. sort,
  169. }),
  170. renderBodyCell,
  171. }}
  172. />
  173. <Pagination pageLinks={pageLinks} onCursor={handleCursor} />
  174. </Fragment>
  175. );
  176. }
  177. export const getActionName = (transactionOp: string) => {
  178. switch (transactionOp) {
  179. case 'ui.action.click':
  180. return 'Click';
  181. default:
  182. return transactionOp;
  183. }
  184. };
  185. const TitleWrapper = styled('div')`
  186. margin-bottom: ${space(1)};
  187. `;
  188. const DescriptionWrapper = styled('div')`
  189. .inline-flex {
  190. display: inline-flex;
  191. }
  192. `;
  193. export default ResourceSummaryTable;