screensTable.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import {Fragment} from 'react';
  2. import * as qs from 'query-string';
  3. import Link from 'sentry/components/links/link';
  4. import {t} from 'sentry/locale';
  5. import type {TableData} from 'sentry/utils/discover/discoverQuery';
  6. import type EventView from 'sentry/utils/discover/eventView';
  7. import {decodeScalar} from 'sentry/utils/queryString';
  8. import {useLocation} from 'sentry/utils/useLocation';
  9. import TopResultsIndicator from 'sentry/views/discover/table/topResultsIndicator';
  10. import {COLD_START_COLOR, WARM_START_COLOR} from 'sentry/views/insights/colors';
  11. import {
  12. PRIMARY_RELEASE_ALIAS,
  13. SECONDARY_RELEASE_ALIAS,
  14. } from 'sentry/views/insights/common/components/releaseSelector';
  15. import {OverflowEllipsisTextContainer} from 'sentry/views/insights/common/components/textAlign';
  16. import {useReleaseSelection} from 'sentry/views/insights/common/queries/useReleases';
  17. import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
  18. import Breakdown from 'sentry/views/insights/mobile/appStarts/components/breakdown';
  19. import {COLD_START_TYPE} from 'sentry/views/insights/mobile/appStarts/components/startTypeSelector';
  20. import {ScreensTable} from 'sentry/views/insights/mobile/common/components/tables/screensTable';
  21. import {TOP_SCREENS} from 'sentry/views/insights/mobile/constants';
  22. import {ModuleName, SpanMetricsField} from 'sentry/views/insights/types';
  23. type Props = {
  24. data: TableData | undefined;
  25. eventView: EventView;
  26. isLoading: boolean;
  27. pageLinks: string | undefined;
  28. };
  29. export function AppStartScreens({data, eventView, isLoading, pageLinks}: Props) {
  30. const moduleURL = useModuleURL('app_start');
  31. const location = useLocation();
  32. const {primaryRelease, secondaryRelease} = useReleaseSelection();
  33. const startType =
  34. decodeScalar(location.query[SpanMetricsField.APP_START_TYPE]) ?? COLD_START_TYPE;
  35. const columnNameMap = {
  36. transaction: t('Screen'),
  37. [`avg_if(measurements.app_start_cold,release,${primaryRelease})`]: t(
  38. 'Avg Cold Start (%s)',
  39. PRIMARY_RELEASE_ALIAS
  40. ),
  41. [`avg_if(measurements.app_start_cold,release,${secondaryRelease})`]: t(
  42. 'Avg Cold Start (%s)',
  43. SECONDARY_RELEASE_ALIAS
  44. ),
  45. [`avg_if(measurements.app_start_warm,release,${primaryRelease})`]: t(
  46. 'Avg Warm Start (%s)',
  47. PRIMARY_RELEASE_ALIAS
  48. ),
  49. [`avg_if(measurements.app_start_warm,release,${secondaryRelease})`]: t(
  50. 'Avg Warm Start (%s)',
  51. SECONDARY_RELEASE_ALIAS
  52. ),
  53. [`avg_compare(measurements.app_start_cold,release,${primaryRelease},${secondaryRelease})`]:
  54. t('Change'),
  55. [`avg_compare(measurements.app_start_warm,release,${primaryRelease},${secondaryRelease})`]:
  56. t('Change'),
  57. app_start_breakdown: t('Type Breakdown'),
  58. 'count_starts(measurements.app_start_cold)': t('Cold Start Count'),
  59. 'count_starts(measurements.app_start_warm)': t('Warm Start Count'),
  60. };
  61. const columnTooltipMap = {
  62. [`avg_compare(measurements.app_start_cold,release,${primaryRelease},${secondaryRelease})`]:
  63. t('Average Cold Start difference'),
  64. [`avg_compare(measurements.app_start_warm,release,${primaryRelease},${secondaryRelease})`]:
  65. t('Average Warm Start difference'),
  66. };
  67. function renderBodyCell(column, row): React.ReactNode {
  68. if (!data) {
  69. return null;
  70. }
  71. const index = data.data.indexOf(row);
  72. const field = String(column.key);
  73. if (field === 'transaction') {
  74. return (
  75. <Fragment>
  76. <TopResultsIndicator count={TOP_SCREENS} index={index} />
  77. <OverflowEllipsisTextContainer>
  78. <Link
  79. to={`${moduleURL}/spans/?${qs.stringify({
  80. ...location.query,
  81. project: row['project.id'],
  82. transaction: row.transaction,
  83. primaryRelease,
  84. secondaryRelease,
  85. })}`}
  86. >
  87. {row.transaction}
  88. </Link>
  89. </OverflowEllipsisTextContainer>
  90. </Fragment>
  91. );
  92. }
  93. if (field === 'app_start_breakdown') {
  94. return (
  95. <Breakdown
  96. data-test-id="app-start-breakdown"
  97. row={row}
  98. breakdownGroups={[
  99. {
  100. key: 'count_starts(measurements.app_start_cold)',
  101. color: COLD_START_COLOR,
  102. name: t('Cold Start'),
  103. },
  104. {
  105. key: 'count_starts(measurements.app_start_warm)',
  106. color: WARM_START_COLOR,
  107. name: t('Warm Start'),
  108. },
  109. ]}
  110. />
  111. );
  112. }
  113. return null;
  114. }
  115. return (
  116. <ScreensTable
  117. columnNameMap={columnNameMap}
  118. columnTooltipMap={columnTooltipMap}
  119. data={data}
  120. eventView={eventView}
  121. isLoading={isLoading}
  122. pageLinks={pageLinks}
  123. columnOrder={[
  124. 'transaction',
  125. `avg_if(measurements.app_start_${startType},release,${primaryRelease})`,
  126. `avg_if(measurements.app_start_${startType},release,${secondaryRelease})`,
  127. `avg_compare(measurements.app_start_${startType},release,${primaryRelease},${secondaryRelease})`,
  128. 'app_start_breakdown',
  129. `count_starts(measurements.app_start_${startType})`,
  130. ]}
  131. defaultSort={[
  132. {
  133. key: `count_starts_measurements_app_start_${startType}`,
  134. order: 'desc',
  135. },
  136. ]}
  137. customBodyCellRenderer={renderBodyCell}
  138. moduleName={ModuleName.APP_START}
  139. />
  140. );
  141. }