content.tsx 6.6 KB

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