table.tsx 4.6 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 {ScreensTable} from 'sentry/views/performance/mobile/components/screensTable';
  12. import {TOP_SCREENS} from 'sentry/views/performance/mobile/constants';
  13. import {useModuleURL} from 'sentry/views/performance/utils/useModuleURL';
  14. import {
  15. PRIMARY_RELEASE_ALIAS,
  16. SECONDARY_RELEASE_ALIAS,
  17. } from 'sentry/views/starfish/components/releaseSelector';
  18. import {useReleaseSelection} from 'sentry/views/starfish/queries/useReleases';
  19. type Props = {
  20. data: TableData | undefined;
  21. eventView: EventView;
  22. isLoading: boolean;
  23. pageLinks: string | undefined;
  24. };
  25. export function UIScreensTable({data, eventView, isLoading, pageLinks}: Props) {
  26. const moduleURL = useModuleURL('mobile-ui');
  27. const location = useLocation();
  28. const {primaryRelease, secondaryRelease} = useReleaseSelection();
  29. const columnNameMap = {
  30. transaction: t('Screen'),
  31. [`avg_if(mobile.slow_frames,release,${primaryRelease})`]: t(
  32. 'Slow (%s)',
  33. PRIMARY_RELEASE_ALIAS
  34. ),
  35. [`avg_if(mobile.slow_frames,release,${secondaryRelease})`]: t(
  36. 'Slow (%s)',
  37. SECONDARY_RELEASE_ALIAS
  38. ),
  39. [`avg_if(mobile.frozen_frames,release,${primaryRelease})`]: t(
  40. 'Frozen (%s)',
  41. PRIMARY_RELEASE_ALIAS
  42. ),
  43. [`avg_if(mobile.frozen_frames,release,${secondaryRelease})`]: t(
  44. 'Frozen (%s)',
  45. SECONDARY_RELEASE_ALIAS
  46. ),
  47. [`avg_if(mobile.frames_delay,release,${primaryRelease})`]: t(
  48. 'Delay (%s)',
  49. PRIMARY_RELEASE_ALIAS
  50. ),
  51. [`avg_if(mobile.frames_delay,release,${secondaryRelease})`]: t(
  52. 'Delay (%s)',
  53. SECONDARY_RELEASE_ALIAS
  54. ),
  55. [`avg_compare(mobile.slow_frames,release,${primaryRelease},${secondaryRelease})`]:
  56. t('Change'),
  57. [`avg_compare(mobile.frozen_frames,release,${primaryRelease},${secondaryRelease})`]:
  58. t('Change'),
  59. [`avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`]:
  60. t('Change'),
  61. // TODO: Counts
  62. };
  63. function renderBodyCell(column, row): React.ReactNode | null {
  64. if (!data) {
  65. return null;
  66. }
  67. const index = data.data.indexOf(row);
  68. const field = String(column.key);
  69. if (field === 'transaction') {
  70. return (
  71. <Fragment>
  72. <TopResultsIndicator count={TOP_SCREENS} index={index} />
  73. <Link
  74. to={`${moduleURL}/spans/?${qs.stringify({
  75. ...location.query,
  76. project: row['project.id'],
  77. transaction: row.transaction,
  78. primaryRelease,
  79. secondaryRelease,
  80. })}`}
  81. style={{display: `block`, width: `100%`}}
  82. >
  83. {row.transaction}
  84. </Link>
  85. </Fragment>
  86. );
  87. }
  88. if (field.startsWith('avg_if(mobile.frames_delay')) {
  89. return (
  90. <NumberContainer>
  91. {row[field] ? (
  92. <Duration seconds={row[field]} fixedDigits={2} abbreviation />
  93. ) : (
  94. '-'
  95. )}
  96. </NumberContainer>
  97. );
  98. }
  99. return null;
  100. }
  101. return (
  102. <ScreensTable
  103. columnNameMap={columnNameMap}
  104. data={data}
  105. eventView={eventView}
  106. isLoading={isLoading}
  107. pageLinks={pageLinks}
  108. columnOrder={[
  109. 'transaction',
  110. `avg_if(mobile.slow_frames,release,${primaryRelease})`,
  111. `avg_if(mobile.slow_frames,release,${secondaryRelease})`,
  112. `avg_compare(mobile.slow_frames,release,${primaryRelease},${secondaryRelease})`,
  113. `avg_if(mobile.frozen_frames,release,${primaryRelease})`,
  114. `avg_if(mobile.frozen_frames,release,${secondaryRelease})`,
  115. `avg_compare(mobile.frozen_frames,release,${primaryRelease},${secondaryRelease})`,
  116. `avg_if(mobile.frames_delay,release,${primaryRelease})`,
  117. `avg_if(mobile.frames_delay,release,${secondaryRelease})`,
  118. `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  119. ]}
  120. // TODO: Add default sort on count column
  121. defaultSort={[
  122. {
  123. key: `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  124. order: 'desc',
  125. },
  126. ]}
  127. customBodyCellRenderer={renderBodyCell}
  128. />
  129. );
  130. }