eventSamples.tsx 4.1 KB

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