screensTable.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. function renderBodyCell(column, row): React.ReactNode {
  62. if (!data) {
  63. return null;
  64. }
  65. const index = data.data.indexOf(row);
  66. const field = String(column.key);
  67. if (field === 'transaction') {
  68. return (
  69. <Fragment>
  70. <TopResultsIndicator count={TOP_SCREENS} index={index} />
  71. <OverflowEllipsisTextContainer>
  72. <Link
  73. to={`${moduleURL}/spans/?${qs.stringify({
  74. ...location.query,
  75. project: row['project.id'],
  76. transaction: row.transaction,
  77. primaryRelease,
  78. secondaryRelease,
  79. })}`}
  80. >
  81. {row.transaction}
  82. </Link>
  83. </OverflowEllipsisTextContainer>
  84. </Fragment>
  85. );
  86. }
  87. if (field === 'app_start_breakdown') {
  88. return (
  89. <Breakdown
  90. data-test-id="app-start-breakdown"
  91. row={row}
  92. breakdownGroups={[
  93. {
  94. key: 'count_starts(measurements.app_start_cold)',
  95. color: COLD_START_COLOR,
  96. name: t('Cold Start'),
  97. },
  98. {
  99. key: 'count_starts(measurements.app_start_warm)',
  100. color: WARM_START_COLOR,
  101. name: t('Warm Start'),
  102. },
  103. ]}
  104. />
  105. );
  106. }
  107. return null;
  108. }
  109. return (
  110. <ScreensTable
  111. columnNameMap={columnNameMap}
  112. data={data}
  113. eventView={eventView}
  114. isLoading={isLoading}
  115. pageLinks={pageLinks}
  116. columnOrder={[
  117. 'transaction',
  118. `avg_if(measurements.app_start_${startType},release,${primaryRelease})`,
  119. `avg_if(measurements.app_start_${startType},release,${secondaryRelease})`,
  120. `avg_compare(measurements.app_start_${startType},release,${primaryRelease},${secondaryRelease})`,
  121. 'app_start_breakdown',
  122. `count_starts(measurements.app_start_${startType})`,
  123. ]}
  124. defaultSort={[
  125. {
  126. key: `count_starts_measurements_app_start_${startType}`,
  127. order: 'desc',
  128. },
  129. ]}
  130. customBodyCellRenderer={renderBodyCell}
  131. moduleName={ModuleName.APP_START}
  132. />
  133. );
  134. }