results.tsx 22 KB

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