screensTable.tsx 4.8 KB

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