eventSamples.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import {useMemo} from 'react';
  2. import {t} from 'sentry/locale';
  3. import type {NewQuery} from 'sentry/types/organization';
  4. import EventView from 'sentry/utils/discover/eventView';
  5. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  6. import {decodeList, decodeScalar, decodeSorts} from 'sentry/utils/queryString';
  7. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  8. import {useLocation} from 'sentry/utils/useLocation';
  9. import usePageFilters from 'sentry/utils/usePageFilters';
  10. import {
  11. PRIMARY_RELEASE_ALIAS,
  12. SECONDARY_RELEASE_ALIAS,
  13. } from 'sentry/views/insights/common/components/releaseSelector';
  14. import {useReleaseSelection} from 'sentry/views/insights/common/queries/useReleases';
  15. import useCrossPlatformProject from 'sentry/views/insights/mobile/common/queries/useCrossPlatformProject';
  16. import {EventSamplesTable} from 'sentry/views/insights/mobile/screenload/components/tables/eventSamplesTable';
  17. import {useTableQuery} from 'sentry/views/insights/mobile/screenload/components/tables/screensTable';
  18. import {SpanMetricsField} from 'sentry/views/insights/types';
  19. const DEFAULT_SORT = {
  20. kind: 'desc',
  21. field: 'measurements.time_to_initial_display',
  22. };
  23. type Props = {
  24. cursorName: string;
  25. release: string;
  26. sortKey: string;
  27. transaction: string;
  28. showDeviceClassSelector?: boolean;
  29. };
  30. export function ScreenLoadEventSamples({
  31. cursorName,
  32. transaction,
  33. release,
  34. sortKey,
  35. showDeviceClassSelector,
  36. }: Props) {
  37. const location = useLocation();
  38. const {selection} = usePageFilters();
  39. const {primaryRelease} = useReleaseSelection();
  40. const cursor = decodeScalar(location.query?.[cursorName]);
  41. const {selectedPlatform: platform, isProjectCrossPlatform} = useCrossPlatformProject();
  42. const deviceClass = decodeScalar(location.query[SpanMetricsField.DEVICE_CLASS]);
  43. const subregions = decodeList(location.query[SpanMetricsField.USER_GEO_SUBREGION]);
  44. const searchQuery = useMemo(() => {
  45. const mutableQuery = new MutableSearch([
  46. 'transaction.op:ui.load',
  47. `transaction:${transaction}`,
  48. `release:${release}`,
  49. ]);
  50. if (subregions.length > 0) {
  51. mutableQuery.addDisjunctionFilterValues(
  52. SpanMetricsField.USER_GEO_SUBREGION,
  53. subregions
  54. );
  55. }
  56. if (isProjectCrossPlatform) {
  57. mutableQuery.addFilterValue('os.name', platform);
  58. }
  59. if (deviceClass) {
  60. if (deviceClass === 'Unknown') {
  61. mutableQuery.addFilterValue('!has', 'device.class');
  62. } else {
  63. mutableQuery.addFilterValue('device.class', deviceClass);
  64. }
  65. }
  66. return mutableQuery;
  67. }, [deviceClass, isProjectCrossPlatform, platform, release, transaction, subregions]);
  68. const sort = decodeSorts(location.query[sortKey])[0] ?? DEFAULT_SORT;
  69. const columnNameMap = {
  70. id: t(
  71. 'Event ID (%s)',
  72. release === primaryRelease ? PRIMARY_RELEASE_ALIAS : SECONDARY_RELEASE_ALIAS
  73. ),
  74. 'profile.id': t('Profile'),
  75. 'measurements.time_to_initial_display': t('TTID'),
  76. 'measurements.time_to_full_display': t('TTFD'),
  77. };
  78. const newQuery: NewQuery = {
  79. name: '',
  80. fields: [
  81. 'id',
  82. 'trace',
  83. 'project.name',
  84. 'profile.id',
  85. 'measurements.time_to_initial_display',
  86. 'measurements.time_to_full_display',
  87. ],
  88. query: searchQuery.formatString(),
  89. dataset: DiscoverDatasets.DISCOVER,
  90. version: 2,
  91. projects: selection.projects,
  92. };
  93. const eventView = EventView.fromNewQueryWithLocation(newQuery, location);
  94. eventView.sorts = [sort];
  95. const {data, isPending, pageLinks} = useTableQuery({
  96. eventView,
  97. enabled: true,
  98. limit: 4,
  99. cursor,
  100. referrer: 'api.starfish.mobile-event-samples',
  101. });
  102. return (
  103. <EventSamplesTable
  104. eventIdKey="id"
  105. profileIdKey="profile.id"
  106. isLoading={isPending}
  107. cursorName={cursorName}
  108. pageLinks={pageLinks}
  109. eventView={eventView}
  110. sortKey={sortKey}
  111. data={data}
  112. showDeviceClassSelector={showDeviceClassSelector}
  113. columnNameMap={columnNameMap}
  114. sort={sort}
  115. />
  116. );
  117. }