content.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import React from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Location} from 'history';
  5. import Button from 'app/components/button';
  6. import {CreateAlertFromViewButton} from 'app/components/createAlertButton';
  7. import DropdownControl, {DropdownItem} from 'app/components/dropdownControl';
  8. import SearchBar from 'app/components/events/searchBar';
  9. import * as Layout from 'app/components/layouts/thirds';
  10. import {getParams} from 'app/components/organizations/globalSelectionHeader/getParams';
  11. import {t} from 'app/locale';
  12. import space from 'app/styles/space';
  13. import {Organization, Project} from 'app/types';
  14. import {trackAnalyticsEvent} from 'app/utils/analytics';
  15. import EventView from 'app/utils/discover/eventView';
  16. import Histogram from 'app/utils/performance/histogram';
  17. import {FILTER_OPTIONS} from 'app/utils/performance/histogram/constants';
  18. import {decodeScalar} from 'app/utils/queryString';
  19. import TransactionHeader, {Tab} from '../transactionSummary/header';
  20. import {ZOOM_KEYS} from './constants';
  21. import VitalsPanel from './vitalsPanel';
  22. type Props = {
  23. location: Location;
  24. eventView: EventView;
  25. transactionName: string;
  26. organization: Organization;
  27. projects: Project[];
  28. };
  29. type State = {
  30. incompatibleAlertNotice: React.ReactNode;
  31. };
  32. class VitalsContent extends React.Component<Props, State> {
  33. state: State = {
  34. incompatibleAlertNotice: null,
  35. };
  36. handleSearch = (query: string) => {
  37. const {location} = this.props;
  38. const queryParams = getParams({
  39. ...(location.query || {}),
  40. query,
  41. });
  42. // do not propagate pagination when making a new search
  43. delete queryParams.cursor;
  44. browserHistory.push({
  45. pathname: location.pathname,
  46. query: queryParams,
  47. });
  48. };
  49. handleIncompatibleQuery: React.ComponentProps<
  50. typeof CreateAlertFromViewButton
  51. >['onIncompatibleQuery'] = (incompatibleAlertNoticeFn, _errors) => {
  52. const incompatibleAlertNotice = incompatibleAlertNoticeFn(() =>
  53. this.setState({incompatibleAlertNotice: null})
  54. );
  55. this.setState({incompatibleAlertNotice});
  56. };
  57. render() {
  58. const {transactionName, location, eventView, projects, organization} = this.props;
  59. const {incompatibleAlertNotice} = this.state;
  60. const query = decodeScalar(location.query.query, '');
  61. return (
  62. <React.Fragment>
  63. <TransactionHeader
  64. eventView={eventView}
  65. location={location}
  66. organization={organization}
  67. projects={projects}
  68. transactionName={transactionName}
  69. currentTab={Tab.RealUserMonitoring}
  70. hasWebVitals
  71. handleIncompatibleQuery={this.handleIncompatibleQuery}
  72. />
  73. <Histogram location={location} zoomKeys={ZOOM_KEYS}>
  74. {({activeFilter, handleFilterChange, handleResetView, isZoomed}) => {
  75. return (
  76. <Layout.Body>
  77. {incompatibleAlertNotice && (
  78. <Layout.Main fullWidth>{incompatibleAlertNotice}</Layout.Main>
  79. )}
  80. <Layout.Main fullWidth>
  81. <StyledActions>
  82. <StyledSearchBar
  83. organization={organization}
  84. projectIds={eventView.project}
  85. query={query}
  86. fields={eventView.fields}
  87. onSearch={this.handleSearch}
  88. />
  89. <DropdownControl
  90. buttonProps={{prefix: t('Outliers')}}
  91. label={activeFilter.label}
  92. >
  93. {FILTER_OPTIONS.map(({label, value}) => (
  94. <DropdownItem
  95. key={value}
  96. onSelect={(filterOption: string) => {
  97. trackAnalyticsEvent({
  98. eventKey: 'performance_views.vitals.filter_changed',
  99. eventName: 'Performance Views: Change vitals filter',
  100. organization_id: organization.id,
  101. value: filterOption,
  102. });
  103. handleFilterChange(filterOption);
  104. }}
  105. eventKey={value}
  106. isActive={value === activeFilter.value}
  107. >
  108. {label}
  109. </DropdownItem>
  110. ))}
  111. </DropdownControl>
  112. <Button
  113. onClick={() => {
  114. trackAnalyticsEvent({
  115. eventKey: 'performance_views.vitals.reset_view',
  116. eventName: 'Performance Views: Reset vitals view',
  117. organization_id: organization.id,
  118. });
  119. handleResetView();
  120. }}
  121. disabled={!isZoomed}
  122. data-test-id="reset-view"
  123. >
  124. {t('Reset View')}
  125. </Button>
  126. </StyledActions>
  127. <VitalsPanel
  128. organization={organization}
  129. location={location}
  130. eventView={eventView}
  131. dataFilter={activeFilter.value}
  132. />
  133. </Layout.Main>
  134. </Layout.Body>
  135. );
  136. }}
  137. </Histogram>
  138. </React.Fragment>
  139. );
  140. }
  141. }
  142. const StyledSearchBar = styled(SearchBar)`
  143. flex-grow: 1;
  144. `;
  145. const StyledActions = styled('div')`
  146. display: grid;
  147. grid-gap: ${space(2)};
  148. grid-template-columns: auto max-content max-content;
  149. align-items: center;
  150. margin-bottom: ${space(3)};
  151. `;
  152. export default VitalsContent;