eventSamples.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 {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. const DEFAULT_SORT = {
  19. kind: 'desc',
  20. field: 'measurements.time_to_initial_display',
  21. };
  22. type Props = {
  23. cursorName: string;
  24. release: string;
  25. sortKey: string;
  26. transaction: string;
  27. showDeviceClassSelector?: boolean;
  28. };
  29. export function ScreenLoadEventSamples({
  30. cursorName,
  31. transaction,
  32. release,
  33. sortKey,
  34. showDeviceClassSelector,
  35. }: Props) {
  36. const location = useLocation();
  37. const {selection} = usePageFilters();
  38. const {primaryRelease} = useReleaseSelection();
  39. const cursor = decodeScalar(location.query?.[cursorName]);
  40. const {selectedPlatform: platform, isProjectCrossPlatform} = useCrossPlatformProject();
  41. const deviceClass = decodeScalar(location.query['device.class']);
  42. const searchQuery = useMemo(() => {
  43. const mutableQuery = new MutableSearch([
  44. 'transaction.op:ui.load',
  45. `transaction:${transaction}`,
  46. `release:${release}`,
  47. ]);
  48. if (isProjectCrossPlatform) {
  49. mutableQuery.addFilterValue('os.name', platform);
  50. }
  51. if (deviceClass) {
  52. if (deviceClass === 'Unknown') {
  53. mutableQuery.addFilterValue('!has', 'device.class');
  54. } else {
  55. mutableQuery.addFilterValue('device.class', deviceClass);
  56. }
  57. }
  58. return mutableQuery;
  59. }, [deviceClass, isProjectCrossPlatform, platform, release, transaction]);
  60. const sort = decodeSorts(location.query[sortKey])[0] ?? DEFAULT_SORT;
  61. const columnNameMap = {
  62. id: t(
  63. 'Event ID (%s)',
  64. release === primaryRelease ? PRIMARY_RELEASE_ALIAS : SECONDARY_RELEASE_ALIAS
  65. ),
  66. 'profile.id': t('Profile'),
  67. 'measurements.time_to_initial_display': t('TTID'),
  68. 'measurements.time_to_full_display': t('TTFD'),
  69. };
  70. const newQuery: NewQuery = {
  71. name: '',
  72. fields: [
  73. 'id',
  74. 'trace',
  75. 'project.name',
  76. 'profile.id',
  77. 'measurements.time_to_initial_display',
  78. 'measurements.time_to_full_display',
  79. ],
  80. query: searchQuery.formatString(),
  81. dataset: DiscoverDatasets.DISCOVER,
  82. version: 2,
  83. projects: selection.projects,
  84. };
  85. const eventView = EventView.fromNewQueryWithLocation(newQuery, location);
  86. eventView.sorts = [sort];
  87. const {data, isLoading, pageLinks} = useTableQuery({
  88. eventView,
  89. enabled: true,
  90. limit: 4,
  91. cursor,
  92. referrer: 'api.starfish.mobile-event-samples',
  93. });
  94. return (
  95. <EventSamplesTable
  96. eventIdKey="id"
  97. profileIdKey="profile.id"
  98. isLoading={isLoading}
  99. cursorName={cursorName}
  100. pageLinks={pageLinks}
  101. eventView={eventView}
  102. sortKey={sortKey}
  103. data={data}
  104. showDeviceClassSelector={showDeviceClassSelector}
  105. columnNameMap={columnNameMap}
  106. sort={sort}
  107. />
  108. );
  109. }