results.tsx 23 KB

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