screensOverviewTable.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 normalizeUrl from 'sentry/utils/url/normalizeUrl';
  10. import {useLocation} from 'sentry/utils/useLocation';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import {OverflowEllipsisTextContainer} from 'sentry/views/insights/common/components/textAlign';
  13. import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
  14. import {ScreensTable} from 'sentry/views/insights/mobile/common/components/tables/screensTable';
  15. import {SUMMARY_PAGE_BASE_URL} from 'sentry/views/insights/mobile/screenRendering/settings';
  16. import {isModuleEnabled} from 'sentry/views/insights/pages/utils';
  17. import {ModuleName} from 'sentry/views/insights/types';
  18. type Props = {
  19. data: TableData | undefined;
  20. eventView: EventView;
  21. isLoading: boolean;
  22. pageLinks: string | undefined;
  23. };
  24. function ScreensOverviewTable({data, eventView, isLoading, pageLinks}: Props) {
  25. const moduleURL = useModuleURL('mobile-screens');
  26. const screenRenderingModuleUrl = useModuleURL(ModuleName.SCREEN_RENDERING);
  27. const organization = useOrganization();
  28. const location = useLocation();
  29. const isMobileScreensEnabled = isModuleEnabled(ModuleName.MOBILE_SCREENS, organization);
  30. const columnNameMap = {
  31. transaction: t('Screen'),
  32. [`count()`]: t('Screen Loads'),
  33. [`avg(mobile.slow_frames)`]: t('Slow Frames'),
  34. [`avg(mobile.frozen_frames)`]: t('Frozen Frames'),
  35. [`avg(measurements.time_to_initial_display)`]: t('TTID'),
  36. [`avg(measurements.time_to_full_display)`]: t('TTFD'),
  37. ['avg(measurements.app_start_warm)']: t('Warm Start'),
  38. ['avg(measurements.app_start_cold)']: t('Cold Start'),
  39. };
  40. function renderBodyCell(column, row): React.ReactNode | null {
  41. if (!data) {
  42. return null;
  43. }
  44. const field = String(column.key);
  45. if (field === 'transaction') {
  46. const queryString = qs.stringify({
  47. ...location.query,
  48. project: row['project.id'],
  49. transaction: row.transaction,
  50. });
  51. const link = isMobileScreensEnabled
  52. ? normalizeUrl(`${moduleURL}/details/?${queryString}`)
  53. : normalizeUrl(
  54. `${screenRenderingModuleUrl}/${SUMMARY_PAGE_BASE_URL}/?${queryString}`
  55. );
  56. return (
  57. <Fragment>
  58. <OverflowEllipsisTextContainer>
  59. <Link to={link} style={{display: `block`, width: `100%`}}>
  60. {row.transaction}
  61. </Link>
  62. </OverflowEllipsisTextContainer>
  63. </Fragment>
  64. );
  65. }
  66. // backend doesn't provide unit for frames_delay, manually format it right now
  67. if (field === `avg(mobile.frames_delay)`) {
  68. return (
  69. <NumberContainer>
  70. {row[field] ? (
  71. <Duration seconds={row[field]} fixedDigits={2} abbreviation />
  72. ) : (
  73. '-'
  74. )}
  75. </NumberContainer>
  76. );
  77. }
  78. return null;
  79. }
  80. return (
  81. <ScreensTable
  82. columnNameMap={columnNameMap}
  83. columnTooltipMap={{}}
  84. data={data}
  85. eventView={eventView}
  86. isLoading={isLoading}
  87. pageLinks={pageLinks}
  88. columnOrder={[
  89. 'transaction',
  90. 'avg(measurements.app_start_cold)',
  91. 'avg(measurements.app_start_warm)',
  92. `avg(mobile.slow_frames)`,
  93. `avg(mobile.frozen_frames)`,
  94. `avg(measurements.time_to_initial_display)`,
  95. `avg(measurements.time_to_full_display)`,
  96. `count()`,
  97. ]}
  98. defaultSort={[
  99. {
  100. key: `count()`,
  101. order: 'desc',
  102. },
  103. ]}
  104. customBodyCellRenderer={renderBodyCell}
  105. moduleName={ModuleName.MOBILE_UI}
  106. />
  107. );
  108. }
  109. export default ScreensOverviewTable;