content.tsx 7.2 KB

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