resourceSummaryTable.tsx 6.3 KB

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