resourceSummaryTable.tsx 6.4 KB

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