index.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {Location} from 'history';
  2. import * as Layout from 'sentry/components/layouts/thirds';
  3. import LoadingIndicator from 'sentry/components/loadingIndicator';
  4. import {t} from 'sentry/locale';
  5. import {Organization, Project} from 'sentry/types';
  6. import DiscoverQuery from 'sentry/utils/discover/discoverQuery';
  7. import EventView from 'sentry/utils/discover/eventView';
  8. import {isAggregateField} from 'sentry/utils/discover/fields';
  9. import {decodeScalar} from 'sentry/utils/queryString';
  10. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  11. import withOrganization from 'sentry/utils/withOrganization';
  12. import withProjects from 'sentry/utils/withProjects';
  13. import PageLayout, {ChildProps} from '../pageLayout';
  14. import Tab from '../tabs';
  15. import ReplaysContent from './content';
  16. type Props = {
  17. location: Location;
  18. organization: Organization;
  19. projects: Project[];
  20. };
  21. function TransactionReplays(props: Props) {
  22. const {location, organization, projects} = props;
  23. return (
  24. <PageLayout
  25. location={location}
  26. organization={organization}
  27. projects={projects}
  28. tab={Tab.Replays}
  29. getDocumentTitle={getDocumentTitle}
  30. generateEventView={generateEventView}
  31. childComponent={ReplaysContentWrapper}
  32. />
  33. );
  34. }
  35. function ReplaysContentWrapper(props: ChildProps) {
  36. const {location, organization, eventView, transactionName, setError} = props;
  37. return (
  38. <DiscoverQuery
  39. eventView={eventView}
  40. orgSlug={organization.slug}
  41. location={location}
  42. setError={error => setError(error?.message)}
  43. referrer="api.performance.transaction-summary"
  44. cursor="0:0:0"
  45. useEvents
  46. >
  47. {({isLoading, tableData, pageLinks}) => {
  48. if (isLoading) {
  49. return (
  50. <Layout.Main fullWidth>
  51. <LoadingIndicator />
  52. </Layout.Main>
  53. );
  54. }
  55. return tableData ? (
  56. <ReplaysContent
  57. eventView={eventView}
  58. location={location}
  59. organization={organization}
  60. setError={setError}
  61. transactionName={transactionName}
  62. tableData={tableData}
  63. pageLinks={pageLinks}
  64. />
  65. ) : null;
  66. }}
  67. </DiscoverQuery>
  68. );
  69. }
  70. function getDocumentTitle(transactionName: string): string {
  71. const hasTransactionName =
  72. typeof transactionName === 'string' && String(transactionName).trim().length > 0;
  73. if (hasTransactionName) {
  74. return [String(transactionName).trim(), t('Replays')].join(' \u2014 ');
  75. }
  76. return [t('Summary'), t('Replays')].join(' \u2014 ');
  77. }
  78. function generateEventView({
  79. location,
  80. transactionName,
  81. }: {
  82. location: Location;
  83. transactionName: string;
  84. }): EventView {
  85. const query = decodeScalar(location.query.query, '');
  86. const conditions = new MutableSearch(query);
  87. conditions.setFilterValues('event.type', ['transaction']);
  88. conditions.setFilterValues('transaction', [transactionName]);
  89. Object.keys(conditions.filters).forEach(field => {
  90. if (isAggregateField(field)) {
  91. conditions.removeFilter(field);
  92. }
  93. });
  94. // Default fields for relative span view
  95. const fields = [
  96. 'replayId',
  97. 'eventID',
  98. 'project',
  99. 'timestamp',
  100. 'url',
  101. 'user.display',
  102. 'user.email',
  103. 'user.id',
  104. 'user.ip_address',
  105. 'user.name',
  106. 'user.username',
  107. ];
  108. return EventView.fromNewQueryWithLocation(
  109. {
  110. id: undefined,
  111. version: 2,
  112. name: transactionName,
  113. fields,
  114. query: `${conditions.formatString()} has:replayId`,
  115. projects: [],
  116. orderby: decodeScalar(location.query.sort, '-timestamp'),
  117. },
  118. location
  119. );
  120. }
  121. export default withProjects(withOrganization(TransactionReplays));