screensOverviewTable.tsx 3.3 KB

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