allEventsTable.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import {useEffect, useState} from 'react';
  2. import {Location} from 'history';
  3. import LoadingError from 'sentry/components/loadingError';
  4. import {PlatformCategory, PlatformKey} from 'sentry/data/platformCategories';
  5. import {t} from 'sentry/locale';
  6. import {Group, IssueCategory, Organization} from 'sentry/types';
  7. import EventView, {decodeSorts} from 'sentry/utils/discover/eventView';
  8. import {platformToCategory} from 'sentry/utils/platform';
  9. import {useRoutes} from 'sentry/utils/useRoutes';
  10. import EventsTable from 'sentry/views/performance/transactionSummary/transactionEvents/eventsTable';
  11. export interface Props {
  12. group: Group;
  13. issueId: string;
  14. location: Location;
  15. organization: Organization;
  16. excludedTags?: string[];
  17. }
  18. const AllEventsTable = (props: Props) => {
  19. const {location, organization, issueId, excludedTags, group} = props;
  20. const [error, setError] = useState<string>('');
  21. const routes = useRoutes();
  22. const {fields, columnTitles} = getColumns(group, organization);
  23. const eventView: EventView = EventView.fromLocation(props.location);
  24. eventView.fields = fields.map(fieldName => ({field: fieldName}));
  25. eventView.sorts = decodeSorts(location).filter(sort => fields.includes(sort.field));
  26. useEffect(() => {
  27. setError('');
  28. }, [eventView.query]);
  29. if (!eventView.sorts.length) {
  30. eventView.sorts = [{field: 'timestamp', kind: 'desc'}];
  31. }
  32. const idQuery =
  33. group.issueCategory === IssueCategory.PERFORMANCE
  34. ? `performance.issue_ids:${issueId} event.type:transaction`
  35. : `issue.id:${issueId}`;
  36. eventView.project = [parseInt(group.project.id, 10)];
  37. eventView.query = `${idQuery} ${props.location.query.query || ''}`;
  38. eventView.statsPeriod = '90d';
  39. if (error) {
  40. return <LoadingError message={error} onRetry={() => setError('')} />;
  41. }
  42. const isReplayEnabled = organization.features.includes('session-replay-ui');
  43. return (
  44. <EventsTable
  45. eventView={eventView}
  46. location={location}
  47. issueId={issueId}
  48. organization={organization}
  49. routes={routes}
  50. excludedTags={excludedTags}
  51. projectSlug={group.project.slug}
  52. customColumns={['minidump']}
  53. setError={(msg: string | undefined) => setError(msg ?? '')}
  54. transactionName=""
  55. columnTitles={columnTitles.slice()}
  56. referrer="api.issues.issue_events"
  57. showReplayCol={isReplayEnabled}
  58. />
  59. );
  60. };
  61. type ColumnInfo = {columnTitles: string[]; fields: string[]};
  62. const getColumns = (group: Group, organization: Organization): ColumnInfo => {
  63. const isPerfIssue = group.issueCategory === IssueCategory.PERFORMANCE;
  64. const isReplayEnabled = organization.features.includes('session-replay-ui');
  65. const {fields: platformSpecificFields, columnTitles: platformSpecificColumnTitles} =
  66. getPlatformColumns(group.project.platform ?? group.platform, {isReplayEnabled});
  67. const fields: string[] = [
  68. 'id',
  69. 'transaction',
  70. 'title',
  71. 'release',
  72. 'environment',
  73. 'user.display',
  74. 'device',
  75. 'os',
  76. ...platformSpecificFields,
  77. ...(isPerfIssue ? ['transaction.duration'] : []),
  78. 'timestamp',
  79. ];
  80. const columnTitles: string[] = [
  81. t('event id'),
  82. t('transaction'),
  83. t('title'),
  84. t('release'),
  85. t('environment'),
  86. t('user'),
  87. t('device'),
  88. t('os'),
  89. ...platformSpecificColumnTitles,
  90. ...(isPerfIssue ? [t('total duration')] : []),
  91. t('timestamp'),
  92. t('minidump'),
  93. ];
  94. return {
  95. fields,
  96. columnTitles,
  97. };
  98. };
  99. const getPlatformColumns = (
  100. platform: PlatformKey | undefined,
  101. options: {isReplayEnabled: boolean}
  102. ): ColumnInfo => {
  103. const replayField = options.isReplayEnabled ? ['replayId'] : [];
  104. const replayColumnTitle = options.isReplayEnabled ? [t('replay')] : [];
  105. const backendServerlessColumnInfo = {
  106. fields: ['url', 'runtime'],
  107. columnTitles: [t('url'), t('runtime')],
  108. };
  109. const categoryToColumnMap: Record<PlatformCategory, ColumnInfo> = {
  110. [PlatformCategory.BACKEND]: backendServerlessColumnInfo,
  111. [PlatformCategory.SERVERLESS]: backendServerlessColumnInfo,
  112. [PlatformCategory.FRONTEND]: {
  113. fields: ['url', 'browser', ...replayField],
  114. columnTitles: [t('url'), t('browser'), ...replayColumnTitle],
  115. },
  116. [PlatformCategory.MOBILE]: {
  117. fields: ['url'],
  118. columnTitles: [t('url')],
  119. },
  120. [PlatformCategory.DESKTOP]: {
  121. fields: [],
  122. columnTitles: [],
  123. },
  124. [PlatformCategory.OTHER]: {
  125. fields: [],
  126. columnTitles: [],
  127. },
  128. };
  129. const platformCategory = platformToCategory(platform);
  130. return categoryToColumnMap[platformCategory];
  131. };
  132. export default AllEventsTable;