uiScreensTable.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import {Fragment} from 'react';
  2. import * as qs from 'query-string';
  3. import Duration from 'sentry/components/duration';
  4. import Link from 'sentry/components/links/link';
  5. import {t} from 'sentry/locale';
  6. import type {TableData} from 'sentry/utils/discover/discoverQuery';
  7. import type EventView from 'sentry/utils/discover/eventView';
  8. import {NumberContainer} from 'sentry/utils/discover/styles';
  9. import {useLocation} from 'sentry/utils/useLocation';
  10. import TopResultsIndicator from 'sentry/views/discover/table/topResultsIndicator';
  11. import {
  12. PRIMARY_RELEASE_ALIAS,
  13. SECONDARY_RELEASE_ALIAS,
  14. } from 'sentry/views/insights/common/components/releaseSelector';
  15. import {useReleaseSelection} from 'sentry/views/insights/common/queries/useReleases';
  16. import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
  17. import {ScreensTable} from 'sentry/views/insights/mobile/common/components/tables/screensTable';
  18. import {TOP_SCREENS} from 'sentry/views/insights/mobile/constants';
  19. import {ModuleName} from 'sentry/views/insights/types';
  20. type Props = {
  21. data: TableData | undefined;
  22. eventView: EventView;
  23. isLoading: boolean;
  24. pageLinks: string | undefined;
  25. };
  26. export function UIScreensTable({data, eventView, isLoading, pageLinks}: Props) {
  27. const moduleURL = useModuleURL('mobile-ui');
  28. const location = useLocation();
  29. const {primaryRelease, secondaryRelease} = useReleaseSelection();
  30. const columnNameMap = {
  31. transaction: t('Screen'),
  32. [`division_if(mobile.slow_frames,mobile.total_frames,release,${primaryRelease})`]: t(
  33. 'Slow (%s)',
  34. PRIMARY_RELEASE_ALIAS
  35. ),
  36. [`division_if(mobile.slow_frames,mobile.total_frames,release,${secondaryRelease})`]:
  37. t('Slow (%s)', SECONDARY_RELEASE_ALIAS),
  38. [`division_if(mobile.frozen_frames,mobile.total_frames,release,${primaryRelease})`]:
  39. t('Frozen (%s)', PRIMARY_RELEASE_ALIAS),
  40. [`division_if(mobile.frozen_frames,mobile.total_frames,release,${secondaryRelease})`]:
  41. t('Frozen (%s)', SECONDARY_RELEASE_ALIAS),
  42. [`avg_if(mobile.frames_delay,release,${primaryRelease})`]: t(
  43. 'Delay (%s)',
  44. PRIMARY_RELEASE_ALIAS
  45. ),
  46. [`avg_if(mobile.frames_delay,release,${secondaryRelease})`]: t(
  47. 'Delay (%s)',
  48. SECONDARY_RELEASE_ALIAS
  49. ),
  50. [`avg_compare(mobile.slow_frames,release,${primaryRelease},${secondaryRelease})`]:
  51. t('Change'),
  52. [`avg_compare(mobile.frozen_frames,release,${primaryRelease},${secondaryRelease})`]:
  53. t('Change'),
  54. [`avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`]:
  55. t('Change'),
  56. // TODO: Counts
  57. };
  58. const columnTooltipMap = {
  59. [`division_if(mobile.slow_frames,mobile.total_frames,release,${primaryRelease})`]: t(
  60. 'The number of slow frames divided by total frames (%s)',
  61. PRIMARY_RELEASE_ALIAS
  62. ),
  63. [`division_if(mobile.slow_frames,mobile.total_frames,release,${secondaryRelease})`]:
  64. t(
  65. 'The number of slow frames divided by total frames (%s)',
  66. SECONDARY_RELEASE_ALIAS
  67. ),
  68. [`division_if(mobile.frozen_frames,mobile.total_frames,release,${primaryRelease})`]:
  69. t(
  70. 'The number of frozen frames divided by total frames (%s)',
  71. PRIMARY_RELEASE_ALIAS
  72. ),
  73. [`division_if(mobile.frozen_frames,mobile.total_frames,release,${secondaryRelease})`]:
  74. t(
  75. 'The number of frozen frames divided by total frames (%s)',
  76. SECONDARY_RELEASE_ALIAS
  77. ),
  78. [`avg_if(mobile.frames_delay,release,${primaryRelease})`]: t(
  79. 'The average frame delay (%s)',
  80. PRIMARY_RELEASE_ALIAS
  81. ),
  82. [`avg_if(mobile.frames_delay,release,${secondaryRelease})`]: t(
  83. 'The average frame delay (%s)',
  84. SECONDARY_RELEASE_ALIAS
  85. ),
  86. };
  87. function renderBodyCell(column, row): React.ReactNode | null {
  88. if (!data) {
  89. return null;
  90. }
  91. const index = data.data.indexOf(row);
  92. const field = String(column.key);
  93. if (field === 'transaction') {
  94. return (
  95. <Fragment>
  96. <TopResultsIndicator count={TOP_SCREENS} index={index} />
  97. <Link
  98. to={`${moduleURL}/spans/?${qs.stringify({
  99. ...location.query,
  100. project: row['project.id'],
  101. transaction: row.transaction,
  102. primaryRelease,
  103. secondaryRelease,
  104. })}`}
  105. style={{display: `block`, width: `100%`}}
  106. >
  107. {row.transaction}
  108. </Link>
  109. </Fragment>
  110. );
  111. }
  112. if (field.startsWith('avg_if(mobile.frames_delay')) {
  113. return (
  114. <NumberContainer>
  115. {row[field] ? (
  116. <Duration seconds={row[field]} fixedDigits={2} abbreviation />
  117. ) : (
  118. '-'
  119. )}
  120. </NumberContainer>
  121. );
  122. }
  123. return null;
  124. }
  125. return (
  126. <ScreensTable
  127. columnNameMap={columnNameMap}
  128. columnTooltipMap={columnTooltipMap}
  129. data={data}
  130. eventView={eventView}
  131. isLoading={isLoading}
  132. pageLinks={pageLinks}
  133. columnOrder={[
  134. 'transaction',
  135. `division_if(mobile.slow_frames,mobile.total_frames,release,${primaryRelease})`,
  136. `division_if(mobile.slow_frames,mobile.total_frames,release,${secondaryRelease})`,
  137. `division_if(mobile.frozen_frames,mobile.total_frames,release,${primaryRelease})`,
  138. `division_if(mobile.frozen_frames,mobile.total_frames,release,${secondaryRelease})`,
  139. `avg_if(mobile.frames_delay,release,${primaryRelease})`,
  140. `avg_if(mobile.frames_delay,release,${secondaryRelease})`,
  141. `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  142. ]}
  143. // TODO: Add default sort on count column
  144. defaultSort={[
  145. {
  146. key: `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  147. order: 'desc',
  148. },
  149. ]}
  150. customBodyCellRenderer={renderBodyCell}
  151. moduleName={ModuleName.MOBILE_UI}
  152. />
  153. );
  154. }