results.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. import {Component, Fragment} from 'react';
  2. import {browserHistory, InjectedRouter} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import * as Sentry from '@sentry/react';
  5. import {Location} from 'history';
  6. import isEqual from 'lodash/isEqual';
  7. import omit from 'lodash/omit';
  8. import {updateSavedQueryVisit} from 'sentry/actionCreators/discoverSavedQueries';
  9. import {fetchTotalCount} from 'sentry/actionCreators/events';
  10. import {fetchProjectsCount} from 'sentry/actionCreators/projects';
  11. import {loadOrganizationTags} from 'sentry/actionCreators/tags';
  12. import {Client} from 'sentry/api';
  13. import {Alert} from 'sentry/components/alert';
  14. import Confirm from 'sentry/components/confirm';
  15. import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent';
  16. import SearchBar from 'sentry/components/events/searchBar';
  17. import * as Layout from 'sentry/components/layouts/thirds';
  18. import ExternalLink from 'sentry/components/links/externalLink';
  19. import LoadingIndicator from 'sentry/components/loadingIndicator';
  20. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  21. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  22. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  23. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  24. import {
  25. normalizeDateTimeParams,
  26. normalizeDateTimeString,
  27. } from 'sentry/components/organizations/pageFilters/parse';
  28. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  29. import {CursorHandler} from 'sentry/components/pagination';
  30. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  31. import {MAX_QUERY_LENGTH} from 'sentry/constants';
  32. import {t, tct} from 'sentry/locale';
  33. import {space} from 'sentry/styles/space';
  34. import {Organization, PageFilters, SavedQuery} from 'sentry/types';
  35. import {defined, generateQueryWithTag} from 'sentry/utils';
  36. import {trackAnalytics} from 'sentry/utils/analytics';
  37. import {CustomMeasurementsContext} from 'sentry/utils/customMeasurements/customMeasurementsContext';
  38. import {CustomMeasurementsProvider} from 'sentry/utils/customMeasurements/customMeasurementsProvider';
  39. import EventView, {isAPIPayloadSimilar} from 'sentry/utils/discover/eventView';
  40. import {formatTagKey, generateAggregateFields} from 'sentry/utils/discover/fields';
  41. import {
  42. DisplayModes,
  43. MULTI_Y_AXIS_SUPPORTED_DISPLAY_MODES,
  44. } from 'sentry/utils/discover/types';
  45. import localStorage from 'sentry/utils/localStorage';
  46. import marked from 'sentry/utils/marked';
  47. import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
  48. import {decodeList, decodeScalar} from 'sentry/utils/queryString';
  49. import withApi from 'sentry/utils/withApi';
  50. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  51. import withOrganization from 'sentry/utils/withOrganization';
  52. import withPageFilters from 'sentry/utils/withPageFilters';
  53. import {addRoutePerformanceContext} from '../performance/utils';
  54. import {DEFAULT_EVENT_VIEW} from './data';
  55. import ResultsChart from './resultsChart';
  56. import ResultsHeader from './resultsHeader';
  57. import {SampleDataAlert} from './sampleDataAlert';
  58. import Table from './table';
  59. import Tags from './tags';
  60. import {generateTitle} from './utils';
  61. type Props = {
  62. api: Client;
  63. loading: boolean;
  64. location: Location;
  65. organization: Organization;
  66. router: InjectedRouter;
  67. selection: PageFilters;
  68. setSavedQuery: (savedQuery?: SavedQuery) => void;
  69. isHomepage?: boolean;
  70. savedQuery?: SavedQuery;
  71. };
  72. type State = {
  73. confirmedQuery: boolean;
  74. error: string;
  75. errorCode: number;
  76. eventView: EventView;
  77. needConfirmation: boolean;
  78. showTags: boolean;
  79. tips: string[];
  80. totalValues: null | number;
  81. savedQuery?: SavedQuery;
  82. showMetricsAlert?: boolean;
  83. showUnparameterizedBanner?: boolean;
  84. };
  85. const SHOW_TAGS_STORAGE_KEY = 'discover2:show-tags';
  86. const SHOW_UNPARAM_BANNER = 'showUnparameterizedBanner';
  87. function readShowTagsState() {
  88. const value = localStorage.getItem(SHOW_TAGS_STORAGE_KEY);
  89. return value === '1';
  90. }
  91. function getYAxis(location: Location, eventView: EventView, savedQuery?: SavedQuery) {
  92. if (location.query.yAxis) {
  93. return decodeList(location.query.yAxis);
  94. }
  95. if (location.query.yAxis === null) {
  96. return [];
  97. }
  98. return savedQuery?.yAxis && savedQuery?.yAxis.length > 0
  99. ? decodeList(savedQuery?.yAxis)
  100. : [eventView.getYAxis()];
  101. }
  102. export class Results extends Component<Props, State> {
  103. static getDerivedStateFromProps(nextProps: Readonly<Props>, prevState: State): State {
  104. const eventView = EventView.fromSavedQueryOrLocation(
  105. nextProps.savedQuery,
  106. nextProps.location
  107. );
  108. return {...prevState, eventView, savedQuery: nextProps.savedQuery};
  109. }
  110. state: State = {
  111. eventView: EventView.fromSavedQueryOrLocation(
  112. this.props.savedQuery,
  113. this.props.location
  114. ),
  115. error: '',
  116. errorCode: 200,
  117. totalValues: null,
  118. showTags: readShowTagsState(),
  119. needConfirmation: false,
  120. confirmedQuery: false,
  121. tips: [],
  122. };
  123. componentDidMount() {
  124. const {organization, selection, location, isHomepage} = this.props;
  125. if (location.query.fromMetric) {
  126. this.setState({showMetricsAlert: true});
  127. browserHistory.replace({
  128. ...location,
  129. query: {...location.query, fromMetric: undefined},
  130. });
  131. }
  132. if (location.query[SHOW_UNPARAM_BANNER]) {
  133. this.setState({showUnparameterizedBanner: true});
  134. browserHistory.replace({
  135. ...location,
  136. query: {...location.query, [SHOW_UNPARAM_BANNER]: undefined},
  137. });
  138. }
  139. loadOrganizationTags(this.tagsApi, organization.slug, selection);
  140. addRoutePerformanceContext(selection);
  141. this.checkEventView();
  142. this.canLoadEvents();
  143. if (!isHomepage && defined(location.query.id)) {
  144. updateSavedQueryVisit(organization.slug, location.query.id);
  145. }
  146. }
  147. componentDidUpdate(prevProps: Props, prevState: State) {
  148. const {location, organization, selection} = this.props;
  149. const {eventView, confirmedQuery, savedQuery} = this.state;
  150. this.checkEventView();
  151. const currentQuery = eventView.getEventsAPIPayload(location);
  152. const prevQuery = prevState.eventView.getEventsAPIPayload(prevProps.location);
  153. const yAxisArray = getYAxis(location, eventView, savedQuery);
  154. const prevYAxisArray = getYAxis(prevProps.location, eventView, prevState.savedQuery);
  155. if (
  156. !isAPIPayloadSimilar(currentQuery, prevQuery) ||
  157. this.hasChartParametersChanged(
  158. prevState.eventView,
  159. eventView,
  160. prevYAxisArray,
  161. yAxisArray
  162. )
  163. ) {
  164. this.canLoadEvents();
  165. }
  166. if (
  167. !isEqual(prevProps.selection.datetime, selection.datetime) ||
  168. !isEqual(prevProps.selection.projects, selection.projects)
  169. ) {
  170. loadOrganizationTags(this.tagsApi, organization.slug, selection);
  171. addRoutePerformanceContext(selection);
  172. }
  173. if (prevState.confirmedQuery !== confirmedQuery) {
  174. this.fetchTotalCount();
  175. }
  176. }
  177. tagsApi: Client = new Client();
  178. hasChartParametersChanged(
  179. prevEventView: EventView,
  180. eventView: EventView,
  181. prevYAxisArray: string[],
  182. yAxisArray: string[]
  183. ) {
  184. if (!isEqual(prevYAxisArray, yAxisArray)) {
  185. return true;
  186. }
  187. const prevDisplay = prevEventView.getDisplayMode();
  188. const display = eventView.getDisplayMode();
  189. return prevDisplay !== display;
  190. }
  191. canLoadEvents = async () => {
  192. const {api, location, organization} = this.props;
  193. const {eventView} = this.state;
  194. let needConfirmation = false;
  195. let confirmedQuery = true;
  196. const currentQuery = eventView.getEventsAPIPayload(location);
  197. const duration = eventView.getDays();
  198. if (duration > 30 && currentQuery.project) {
  199. let projectLength = currentQuery.project.length;
  200. if (
  201. projectLength === 0 ||
  202. (projectLength === 1 && currentQuery.project[0] === '-1')
  203. ) {
  204. try {
  205. const results = await fetchProjectsCount(api, organization.slug);
  206. if (projectLength === 0) {
  207. projectLength = results.myProjects;
  208. } else {
  209. projectLength = results.allProjects;
  210. }
  211. } catch (err) {
  212. // do nothing, so the length is 0 or 1 and the query is assumed safe
  213. }
  214. }
  215. if (projectLength > 10) {
  216. needConfirmation = true;
  217. confirmedQuery = false;
  218. }
  219. }
  220. // Once confirmed, a change of project or datetime will happen before this can set it to false,
  221. // this means a query will still happen even if the new conditions need confirmation
  222. // using a state callback to return this to false
  223. this.setState({needConfirmation, confirmedQuery}, () => {
  224. this.setState({confirmedQuery: false});
  225. });
  226. if (needConfirmation) {
  227. this.openConfirm();
  228. }
  229. };
  230. openConfirm = () => {};
  231. setOpenFunction = ({open}) => {
  232. this.openConfirm = open;
  233. return null;
  234. };
  235. handleConfirmed = () => {
  236. this.setState({needConfirmation: false, confirmedQuery: true}, () => {
  237. this.setState({confirmedQuery: false});
  238. });
  239. };
  240. handleCancelled = () => {
  241. this.setState({needConfirmation: false, confirmedQuery: false});
  242. };
  243. async fetchTotalCount() {
  244. const {api, organization, location} = this.props;
  245. const {eventView, confirmedQuery} = this.state;
  246. if (confirmedQuery === false || !eventView.isValid()) {
  247. return;
  248. }
  249. try {
  250. const totals = await fetchTotalCount(
  251. api,
  252. organization.slug,
  253. eventView.getEventsAPIPayload(location)
  254. );
  255. this.setState({totalValues: totals});
  256. } catch (err) {
  257. Sentry.captureException(err);
  258. }
  259. }
  260. checkEventView() {
  261. const {eventView} = this.state;
  262. const {loading} = this.props;
  263. if (eventView.isValid() || loading) {
  264. return;
  265. }
  266. // If the view is not valid, redirect to a known valid state.
  267. const {location, organization, selection, isHomepage, savedQuery} = this.props;
  268. const isReplayEnabled = organization.features.includes('session-replay');
  269. const defaultEventView = Object.assign({}, DEFAULT_EVENT_VIEW, {
  270. fields: isReplayEnabled
  271. ? DEFAULT_EVENT_VIEW.fields.concat(['replayId'])
  272. : DEFAULT_EVENT_VIEW.fields,
  273. });
  274. const query = isHomepage && savedQuery ? omit(savedQuery, 'id') : defaultEventView;
  275. const nextEventView = EventView.fromNewQueryWithLocation(query, location);
  276. if (nextEventView.project.length === 0 && selection.projects) {
  277. nextEventView.project = selection.projects;
  278. }
  279. if (selection.datetime) {
  280. const {period, utc, start, end} = selection.datetime;
  281. nextEventView.statsPeriod = period ?? undefined;
  282. nextEventView.utc = utc?.toString();
  283. nextEventView.start = normalizeDateTimeString(start);
  284. nextEventView.end = normalizeDateTimeString(end);
  285. }
  286. if (location.query?.query) {
  287. nextEventView.query = decodeScalar(location.query.query, '');
  288. }
  289. if (isHomepage && !this.state.savedQuery) {
  290. this.setState({savedQuery, eventView: nextEventView});
  291. }
  292. browserHistory.replace(
  293. normalizeUrl(nextEventView.getResultsViewUrlTarget(organization.slug, isHomepage))
  294. );
  295. }
  296. handleCursor: CursorHandler = (cursor, path, query, _direction) => {
  297. const {router} = this.props;
  298. router.push({
  299. pathname: path,
  300. query: {...query, cursor},
  301. });
  302. // Treat pagination like the user already confirmed the query
  303. if (!this.state.needConfirmation) {
  304. this.handleConfirmed();
  305. }
  306. };
  307. handleChangeShowTags = () => {
  308. const {organization} = this.props;
  309. trackAnalytics('discover_v2.results.toggle_tag_facets', {
  310. organization,
  311. });
  312. this.setState(state => {
  313. const newValue = !state.showTags;
  314. localStorage.setItem(SHOW_TAGS_STORAGE_KEY, newValue ? '1' : '0');
  315. return {...state, showTags: newValue};
  316. });
  317. };
  318. handleSearch = (query: string) => {
  319. const {router, location} = this.props;
  320. const queryParams = normalizeDateTimeParams({
  321. ...(location.query || {}),
  322. query,
  323. });
  324. // If the user is searching for unresolved issues, we want to search the errors dataset
  325. if (
  326. /\bis:unresolved\b/.test(query) &&
  327. this.props.organization.features.includes('metric-alert-ignore-archived')
  328. ) {
  329. queryParams.dataset = 'errors';
  330. }
  331. // do not propagate pagination when making a new search
  332. const searchQueryParams = omit(queryParams, 'cursor');
  333. router.push({
  334. pathname: location.pathname,
  335. query: searchQueryParams,
  336. });
  337. };
  338. handleYAxisChange = (value: string[]) => {
  339. const {router, location} = this.props;
  340. const isDisplayMultiYAxisSupported = MULTI_Y_AXIS_SUPPORTED_DISPLAY_MODES.includes(
  341. location.query.display as DisplayModes
  342. );
  343. const newQuery = {
  344. ...location.query,
  345. yAxis: value.length > 0 ? value : [null],
  346. // If using Multi Y-axis and not in a supported display, change to the default display mode
  347. display:
  348. value.length > 1 && !isDisplayMultiYAxisSupported
  349. ? location.query.display === DisplayModes.DAILYTOP5
  350. ? DisplayModes.DAILY
  351. : DisplayModes.DEFAULT
  352. : location.query.display,
  353. };
  354. router.push({
  355. pathname: location.pathname,
  356. query: newQuery,
  357. });
  358. // Treat axis changing like the user already confirmed the query
  359. if (!this.state.needConfirmation) {
  360. this.handleConfirmed();
  361. }
  362. trackAnalytics('discover_v2.y_axis_change', {
  363. organization: this.props.organization,
  364. y_axis_value: value,
  365. });
  366. };
  367. handleDisplayChange = (value: string) => {
  368. const {router, location} = this.props;
  369. const newQuery = {
  370. ...location.query,
  371. display: value,
  372. };
  373. router.push({
  374. pathname: location.pathname,
  375. query: newQuery,
  376. });
  377. // Treat display changing like the user already confirmed the query
  378. if (!this.state.needConfirmation) {
  379. this.handleConfirmed();
  380. }
  381. };
  382. handleIntervalChange = (value: string | undefined) => {
  383. const {router, location} = this.props;
  384. const newQuery = {
  385. ...location.query,
  386. interval: value,
  387. };
  388. if (location.query.interval !== value) {
  389. router.push({
  390. pathname: location.pathname,
  391. query: newQuery,
  392. });
  393. // Treat display changing like the user already confirmed the query
  394. if (!this.state.needConfirmation) {
  395. this.handleConfirmed();
  396. }
  397. }
  398. };
  399. handleTopEventsChange = (value: string) => {
  400. const {router, location} = this.props;
  401. const newQuery = {
  402. ...location.query,
  403. topEvents: value,
  404. };
  405. router.push({
  406. pathname: location.pathname,
  407. query: newQuery,
  408. });
  409. // Treat display changing like the user already confirmed the query
  410. if (!this.state.needConfirmation) {
  411. this.handleConfirmed();
  412. }
  413. };
  414. getDocumentTitle(): string {
  415. const {organization} = this.props;
  416. const {eventView} = this.state;
  417. if (!eventView) {
  418. return '';
  419. }
  420. return generateTitle({eventView, organization});
  421. }
  422. renderTagsTable() {
  423. const {organization, location} = this.props;
  424. const {eventView, totalValues, confirmedQuery} = this.state;
  425. return (
  426. <Layout.Side>
  427. <Tags
  428. generateUrl={this.generateTagUrl}
  429. totalValues={totalValues}
  430. eventView={eventView}
  431. organization={organization}
  432. location={location}
  433. confirmedQuery={confirmedQuery}
  434. />
  435. </Layout.Side>
  436. );
  437. }
  438. generateTagUrl = (key: string, value: string) => {
  439. const {organization, isHomepage} = this.props;
  440. const {eventView} = this.state;
  441. const url = eventView.getResultsViewUrlTarget(organization.slug, isHomepage);
  442. url.query = generateQueryWithTag(url.query, {
  443. key: formatTagKey(key),
  444. value,
  445. });
  446. return url;
  447. };
  448. renderError(error: string) {
  449. if (!error) {
  450. return null;
  451. }
  452. return (
  453. <Alert type="error" showIcon>
  454. {error}
  455. </Alert>
  456. );
  457. }
  458. setError = (error: string, errorCode: number) => {
  459. this.setState({error, errorCode});
  460. };
  461. renderMetricsFallbackBanner() {
  462. const {organization} = this.props;
  463. if (
  464. !organization.features.includes('performance-mep-bannerless-ui') &&
  465. this.state.showMetricsAlert
  466. ) {
  467. return (
  468. <Alert type="info" showIcon>
  469. {t(
  470. "You've navigated to this page from a performance metric widget generated from processed events. The results here only show indexed events."
  471. )}
  472. </Alert>
  473. );
  474. }
  475. if (this.state.showUnparameterizedBanner) {
  476. return (
  477. <Alert type="info" showIcon>
  478. {tct(
  479. 'These are unparameterized transactions. To better organize your transactions, [link:set transaction names manually].',
  480. {
  481. link: (
  482. <ExternalLink href="https://docs.sentry.io/platforms/javascript/performance/instrumentation/automatic-instrumentation/#beforenavigate" />
  483. ),
  484. }
  485. )}
  486. </Alert>
  487. );
  488. }
  489. return null;
  490. }
  491. renderTips() {
  492. const {tips} = this.state;
  493. if (tips) {
  494. return tips.map((tip, index) => (
  495. <Alert type="info" showIcon key={`tip-${index}`}>
  496. <TipContainer dangerouslySetInnerHTML={{__html: marked(tip)}} />
  497. </Alert>
  498. ));
  499. }
  500. return null;
  501. }
  502. setTips = (tips: string[]) => {
  503. // If there are currently no tips set and the new tips are empty, do nothing
  504. // and bail out of an expensive entire table rerender
  505. if (!tips.length && !this.state.tips.length) {
  506. return;
  507. }
  508. this.setState({tips});
  509. };
  510. render() {
  511. const {organization, location, router, selection, api, setSavedQuery, isHomepage} =
  512. this.props;
  513. const {
  514. eventView,
  515. error,
  516. errorCode,
  517. totalValues,
  518. showTags,
  519. confirmedQuery,
  520. savedQuery,
  521. } = this.state;
  522. const fields = eventView.hasAggregateField()
  523. ? generateAggregateFields(organization, eventView.fields)
  524. : eventView.fields;
  525. const query = eventView.query;
  526. const title = this.getDocumentTitle();
  527. const yAxisArray = getYAxis(location, eventView, savedQuery);
  528. if (!eventView.isValid()) {
  529. return <LoadingIndicator />;
  530. }
  531. return (
  532. <SentryDocumentTitle title={title} orgSlug={organization.slug}>
  533. <Fragment>
  534. <ResultsHeader
  535. setSavedQuery={setSavedQuery}
  536. errorCode={errorCode}
  537. organization={organization}
  538. location={location}
  539. eventView={eventView}
  540. yAxis={yAxisArray}
  541. router={router}
  542. isHomepage={isHomepage}
  543. />
  544. <Layout.Body>
  545. <CustomMeasurementsProvider organization={organization} selection={selection}>
  546. <Top fullWidth>
  547. {this.renderMetricsFallbackBanner()}
  548. {this.renderError(error)}
  549. {this.renderTips()}
  550. <StyledPageFilterBar condensed>
  551. <ProjectPageFilter />
  552. <EnvironmentPageFilter />
  553. <DatePageFilter />
  554. </StyledPageFilterBar>
  555. <CustomMeasurementsContext.Consumer>
  556. {contextValue => (
  557. <StyledSearchBar
  558. searchSource="eventsv2"
  559. organization={organization}
  560. projectIds={eventView.project}
  561. query={query}
  562. fields={fields}
  563. onSearch={this.handleSearch}
  564. maxQueryLength={MAX_QUERY_LENGTH}
  565. customMeasurements={contextValue?.customMeasurements ?? undefined}
  566. />
  567. )}
  568. </CustomMeasurementsContext.Consumer>
  569. <SampleDataAlert query={query} />
  570. <MetricsCardinalityProvider
  571. organization={organization}
  572. location={location}
  573. >
  574. <ResultsChart
  575. api={api}
  576. router={router}
  577. organization={organization}
  578. eventView={eventView}
  579. location={location}
  580. onAxisChange={this.handleYAxisChange}
  581. onDisplayChange={this.handleDisplayChange}
  582. onTopEventsChange={this.handleTopEventsChange}
  583. onIntervalChange={this.handleIntervalChange}
  584. total={totalValues}
  585. confirmedQuery={confirmedQuery}
  586. yAxis={yAxisArray}
  587. />
  588. </MetricsCardinalityProvider>
  589. </Top>
  590. <Layout.Main fullWidth={!showTags}>
  591. <Table
  592. organization={organization}
  593. eventView={eventView}
  594. location={location}
  595. title={title}
  596. setError={this.setError}
  597. onChangeShowTags={this.handleChangeShowTags}
  598. showTags={showTags}
  599. confirmedQuery={confirmedQuery}
  600. onCursor={this.handleCursor}
  601. isHomepage={isHomepage}
  602. setTips={this.setTips}
  603. />
  604. </Layout.Main>
  605. {showTags ? this.renderTagsTable() : null}
  606. <Confirm
  607. priority="primary"
  608. header={<strong>{t('May lead to thumb twiddling')}</strong>}
  609. confirmText={t('Do it')}
  610. cancelText={t('Nevermind')}
  611. onConfirm={this.handleConfirmed}
  612. onCancel={this.handleCancelled}
  613. message={
  614. <p>
  615. {tct(
  616. `You've created a query that will search for events made
  617. [dayLimit:over more than 30 days] for [projectLimit:more than 10 projects].
  618. A lot has happened during that time, so this might take awhile.
  619. Are you sure you want to do this?`,
  620. {
  621. dayLimit: <strong />,
  622. projectLimit: <strong />,
  623. }
  624. )}
  625. </p>
  626. }
  627. >
  628. {this.setOpenFunction}
  629. </Confirm>
  630. </CustomMeasurementsProvider>
  631. </Layout.Body>
  632. </Fragment>
  633. </SentryDocumentTitle>
  634. );
  635. }
  636. }
  637. const StyledPageFilterBar = styled(PageFilterBar)`
  638. margin-bottom: ${space(1)};
  639. `;
  640. const StyledSearchBar = styled(SearchBar)`
  641. margin-bottom: ${space(2)};
  642. `;
  643. const Top = styled(Layout.Main)`
  644. flex-grow: 0;
  645. `;
  646. const TipContainer = styled('span')`
  647. > p {
  648. margin: 0;
  649. }
  650. `;
  651. type SavedQueryState = DeprecatedAsyncComponent['state'] & {
  652. savedQuery?: SavedQuery | null;
  653. };
  654. class SavedQueryAPI extends DeprecatedAsyncComponent<Props, SavedQueryState> {
  655. shouldReload = true;
  656. getEndpoints(): ReturnType<DeprecatedAsyncComponent['getEndpoints']> {
  657. const {organization, location} = this.props;
  658. const endpoints: ReturnType<DeprecatedAsyncComponent['getEndpoints']> = [];
  659. if (location.query.id) {
  660. endpoints.push([
  661. 'savedQuery',
  662. `/organizations/${organization.slug}/discover/saved/${location.query.id}/`,
  663. ]);
  664. return endpoints;
  665. }
  666. return endpoints;
  667. }
  668. setSavedQuery = (newSavedQuery?: SavedQuery) => {
  669. this.setState({savedQuery: newSavedQuery});
  670. };
  671. renderBody(): React.ReactNode {
  672. const {savedQuery, loading} = this.state;
  673. return (
  674. <Results
  675. {...this.props}
  676. savedQuery={savedQuery ?? undefined}
  677. loading={loading}
  678. setSavedQuery={this.setSavedQuery}
  679. />
  680. );
  681. }
  682. }
  683. function ResultsContainer(props: Props) {
  684. /**
  685. * Block `<Results>` from mounting until GSH is ready since there are API
  686. * requests being performed on mount.
  687. *
  688. * Also, we skip loading last used projects if you have multiple projects feature as
  689. * you no longer need to enforce a project if it is empty. We assume an empty project is
  690. * the desired behavior because saved queries can contain a project filter. The only
  691. * exception is if we are showing a prebuilt saved query in which case we want to
  692. * respect pinned filters.
  693. */
  694. return (
  695. <PageFiltersContainer
  696. disablePersistence={
  697. props.organization.features.includes('discover-query') &&
  698. !!(props.savedQuery || props.location.query.id)
  699. }
  700. skipLoadLastUsed={
  701. props.organization.features.includes('global-views') && !!props.savedQuery
  702. }
  703. >
  704. <SavedQueryAPI {...props} />
  705. </PageFiltersContainer>
  706. );
  707. }
  708. export default withApi(withOrganization(withPageFilters(ResultsContainer)));