content.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import {browserHistory} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import omit from 'lodash/omit';
  5. import {Button} from 'sentry/components/button';
  6. import {CompactSelect} from 'sentry/components/compactSelect';
  7. import SearchBar from 'sentry/components/events/searchBar';
  8. import * as Layout from 'sentry/components/layouts/thirds';
  9. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  10. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  11. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  12. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  13. import {t} from 'sentry/locale';
  14. import {space} from 'sentry/styles/space';
  15. import type {Organization, Project} from 'sentry/types';
  16. import {trackAnalytics} from 'sentry/utils/analytics';
  17. import type EventView from 'sentry/utils/discover/eventView';
  18. import type {WebVital} from 'sentry/utils/fields';
  19. import {decodeScalar} from 'sentry/utils/queryString';
  20. import projectSupportsReplay from 'sentry/utils/replays/projectSupportsReplay';
  21. import {useRoutes} from 'sentry/utils/useRoutes';
  22. import {
  23. platformToPerformanceType,
  24. ProjectPerformanceType,
  25. } from 'sentry/views/performance/utils';
  26. import type {SpanOperationBreakdownFilter} from '../filter';
  27. import Filter, {filterToSearchConditions} from '../filter';
  28. import type {SetStateAction} from '../types';
  29. import EventsTable from './eventsTable';
  30. import type {EventsDisplayFilterName} from './utils';
  31. import {getEventsFilterOptions} from './utils';
  32. type Props = {
  33. eventView: EventView;
  34. eventsDisplayFilterName: EventsDisplayFilterName;
  35. location: Location;
  36. onChangeEventsDisplayFilter: (eventsDisplayFilterName: EventsDisplayFilterName) => void;
  37. onChangeSpanOperationBreakdownFilter: (newFilter: SpanOperationBreakdownFilter) => void;
  38. organization: Organization;
  39. projectId: string;
  40. projects: Project[];
  41. setError: SetStateAction<string | undefined>;
  42. spanOperationBreakdownFilter: SpanOperationBreakdownFilter;
  43. transactionName: string;
  44. percentileValues?: Record<EventsDisplayFilterName, number>;
  45. webVital?: WebVital;
  46. };
  47. export const TRANSACTIONS_LIST_TITLES: Readonly<string[]> = [
  48. t('event id'),
  49. t('user'),
  50. t('operation duration'),
  51. t('total duration'),
  52. t('trace id'),
  53. t('timestamp'),
  54. ];
  55. function EventsContent(props: Props) {
  56. const {
  57. location,
  58. organization,
  59. eventView: originalEventView,
  60. transactionName,
  61. spanOperationBreakdownFilter,
  62. webVital,
  63. setError,
  64. projectId,
  65. projects,
  66. } = props;
  67. const routes = useRoutes();
  68. const eventView = originalEventView.clone();
  69. const transactionsListTitles = TRANSACTIONS_LIST_TITLES.slice();
  70. const project = projects.find(p => p.id === projectId);
  71. const fields = [...eventView.fields];
  72. if (webVital) {
  73. transactionsListTitles.splice(3, 0, webVital);
  74. }
  75. const spanOperationBreakdownConditions = filterToSearchConditions(
  76. spanOperationBreakdownFilter,
  77. location
  78. );
  79. if (spanOperationBreakdownConditions) {
  80. eventView.query = `${eventView.query} ${spanOperationBreakdownConditions}`.trim();
  81. transactionsListTitles.splice(2, 1, t('%s duration', spanOperationBreakdownFilter));
  82. }
  83. const platform = platformToPerformanceType(projects, eventView.project);
  84. if (platform === ProjectPerformanceType.BACKEND) {
  85. const userIndex = transactionsListTitles.indexOf('user');
  86. if (userIndex > 0) {
  87. transactionsListTitles.splice(userIndex + 1, 0, 'http.method');
  88. fields.splice(userIndex + 1, 0, {field: 'http.method'});
  89. }
  90. }
  91. if (
  92. organization.features.includes('profiling') &&
  93. project &&
  94. // only show for projects that already sent a profile
  95. // once we have a more compact design we will show this for
  96. // projects that support profiling as well
  97. project.hasProfiles
  98. ) {
  99. transactionsListTitles.push(t('profile'));
  100. fields.push({field: 'profile.id'});
  101. }
  102. if (
  103. organization.features.includes('session-replay') &&
  104. project &&
  105. projectSupportsReplay(project)
  106. ) {
  107. transactionsListTitles.push(t('replay'));
  108. fields.push({field: 'replayId'});
  109. }
  110. eventView.fields = fields;
  111. return (
  112. <Layout.Main fullWidth>
  113. <Search {...props} eventView={eventView} />
  114. <EventsTable
  115. eventView={eventView}
  116. organization={organization}
  117. routes={routes}
  118. location={location}
  119. setError={setError}
  120. columnTitles={transactionsListTitles}
  121. transactionName={transactionName}
  122. />
  123. </Layout.Main>
  124. );
  125. }
  126. function Search(props: Props) {
  127. const {
  128. eventView,
  129. location,
  130. organization,
  131. spanOperationBreakdownFilter,
  132. onChangeSpanOperationBreakdownFilter,
  133. eventsDisplayFilterName,
  134. onChangeEventsDisplayFilter,
  135. percentileValues,
  136. } = props;
  137. const handleSearch = (query: string) => {
  138. const queryParams = normalizeDateTimeParams({
  139. ...(location.query || {}),
  140. query,
  141. });
  142. // do not propagate pagination when making a new search
  143. const searchQueryParams = omit(queryParams, 'cursor');
  144. browserHistory.push({
  145. pathname: location.pathname,
  146. query: searchQueryParams,
  147. });
  148. };
  149. const query = decodeScalar(location.query.query, '');
  150. const eventsFilterOptions = getEventsFilterOptions(
  151. spanOperationBreakdownFilter,
  152. percentileValues
  153. );
  154. const handleDiscoverButtonClick = () => {
  155. trackAnalytics('performance_views.all_events.open_in_discover', {
  156. organization,
  157. });
  158. };
  159. return (
  160. <FilterActions>
  161. <Filter
  162. organization={organization}
  163. currentFilter={spanOperationBreakdownFilter}
  164. onChangeFilter={onChangeSpanOperationBreakdownFilter}
  165. />
  166. <PageFilterBar condensed>
  167. <EnvironmentPageFilter />
  168. <DatePageFilter />
  169. </PageFilterBar>
  170. <StyledSearchBar
  171. organization={organization}
  172. projectIds={eventView.project}
  173. query={query}
  174. fields={eventView.fields}
  175. onSearch={handleSearch}
  176. />
  177. <CompactSelect
  178. triggerProps={{prefix: t('Percentile')}}
  179. value={eventsDisplayFilterName}
  180. onChange={opt => onChangeEventsDisplayFilter(opt.value)}
  181. options={Object.entries(eventsFilterOptions).map(([name, filter]) => ({
  182. value: name as EventsDisplayFilterName,
  183. label: filter.label,
  184. }))}
  185. />
  186. <Button
  187. to={eventView.getResultsViewUrlTarget(organization.slug)}
  188. onClick={handleDiscoverButtonClick}
  189. >
  190. {t('Open in Discover')}
  191. </Button>
  192. </FilterActions>
  193. );
  194. }
  195. const FilterActions = styled('div')`
  196. display: grid;
  197. gap: ${space(2)};
  198. margin-bottom: ${space(2)};
  199. @media (min-width: ${p => p.theme.breakpoints.small}) {
  200. grid-template-columns: repeat(4, min-content);
  201. }
  202. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  203. grid-template-columns: auto auto 1fr auto auto;
  204. }
  205. `;
  206. const StyledSearchBar = styled(SearchBar)`
  207. @media (min-width: ${p => p.theme.breakpoints.small}) {
  208. order: 1;
  209. grid-column: 1/6;
  210. }
  211. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  212. order: initial;
  213. grid-column: auto;
  214. }
  215. `;
  216. export default EventsContent;