content.tsx 7.0 KB

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