uiScreensTable.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. [`avg_if(mobile.slow_frames,release,${primaryRelease})`]: t(
  33. 'Slow (%s)',
  34. PRIMARY_RELEASE_ALIAS
  35. ),
  36. [`avg_if(mobile.slow_frames,release,${secondaryRelease})`]: t(
  37. 'Slow (%s)',
  38. SECONDARY_RELEASE_ALIAS
  39. ),
  40. [`avg_if(mobile.frozen_frames,release,${primaryRelease})`]: t(
  41. 'Frozen (%s)',
  42. PRIMARY_RELEASE_ALIAS
  43. ),
  44. [`avg_if(mobile.frozen_frames,release,${secondaryRelease})`]: t(
  45. 'Frozen (%s)',
  46. SECONDARY_RELEASE_ALIAS
  47. ),
  48. [`avg_if(mobile.frames_delay,release,${primaryRelease})`]: t(
  49. 'Delay (%s)',
  50. PRIMARY_RELEASE_ALIAS
  51. ),
  52. [`avg_if(mobile.frames_delay,release,${secondaryRelease})`]: t(
  53. 'Delay (%s)',
  54. SECONDARY_RELEASE_ALIAS
  55. ),
  56. [`avg_compare(mobile.slow_frames,release,${primaryRelease},${secondaryRelease})`]:
  57. t('Change'),
  58. [`avg_compare(mobile.frozen_frames,release,${primaryRelease},${secondaryRelease})`]:
  59. t('Change'),
  60. [`avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`]:
  61. t('Change'),
  62. // TODO: Counts
  63. };
  64. function renderBodyCell(column, row): React.ReactNode | null {
  65. if (!data) {
  66. return null;
  67. }
  68. const index = data.data.indexOf(row);
  69. const field = String(column.key);
  70. if (field === 'transaction') {
  71. return (
  72. <Fragment>
  73. <TopResultsIndicator count={TOP_SCREENS} index={index} />
  74. <Link
  75. to={`${moduleURL}/spans/?${qs.stringify({
  76. ...location.query,
  77. project: row['project.id'],
  78. transaction: row.transaction,
  79. primaryRelease,
  80. secondaryRelease,
  81. })}`}
  82. style={{display: `block`, width: `100%`}}
  83. >
  84. {row.transaction}
  85. </Link>
  86. </Fragment>
  87. );
  88. }
  89. if (field.startsWith('avg_if(mobile.frames_delay')) {
  90. return (
  91. <NumberContainer>
  92. {row[field] ? (
  93. <Duration seconds={row[field]} fixedDigits={2} abbreviation />
  94. ) : (
  95. '-'
  96. )}
  97. </NumberContainer>
  98. );
  99. }
  100. return null;
  101. }
  102. return (
  103. <ScreensTable
  104. columnNameMap={columnNameMap}
  105. data={data}
  106. eventView={eventView}
  107. isLoading={isLoading}
  108. pageLinks={pageLinks}
  109. columnOrder={[
  110. 'transaction',
  111. `avg_if(mobile.slow_frames,release,${primaryRelease})`,
  112. `avg_if(mobile.slow_frames,release,${secondaryRelease})`,
  113. `avg_if(mobile.frozen_frames,release,${primaryRelease})`,
  114. `avg_if(mobile.frozen_frames,release,${secondaryRelease})`,
  115. `avg_if(mobile.frames_delay,release,${primaryRelease})`,
  116. `avg_if(mobile.frames_delay,release,${secondaryRelease})`,
  117. `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  118. ]}
  119. // TODO: Add default sort on count column
  120. defaultSort={[
  121. {
  122. key: `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  123. order: 'desc',
  124. },
  125. ]}
  126. customBodyCellRenderer={renderBodyCell}
  127. moduleName={ModuleName.MOBILE_UI}
  128. />
  129. );
  130. }