results.tsx 24 KB

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