results.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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 LoadingIndicator from 'sentry/components/loadingIndicator';
  22. import NoProjectMessage from 'sentry/components/noProjectMessage';
  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 {CursorHandler} from 'sentry/components/pagination';
  30. import ProjectPageFilter from 'sentry/components/projectPageFilter';
  31. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  32. import {MAX_QUERY_LENGTH} from 'sentry/constants';
  33. import {t, tct} from 'sentry/locale';
  34. import {PageContent} from 'sentry/styles/organization';
  35. import space from 'sentry/styles/space';
  36. import {Organization, PageFilters, SavedQuery} from 'sentry/types';
  37. import {defined, generateQueryWithTag} from 'sentry/utils';
  38. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  39. import {CustomMeasurementsContext} from 'sentry/utils/customMeasurements/customMeasurementsContext';
  40. import {CustomMeasurementsProvider} from 'sentry/utils/customMeasurements/customMeasurementsProvider';
  41. import EventView, {isAPIPayloadSimilar} from 'sentry/utils/discover/eventView';
  42. import {formatTagKey, generateAggregateFields} from 'sentry/utils/discover/fields';
  43. import {
  44. DisplayModes,
  45. MULTI_Y_AXIS_SUPPORTED_DISPLAY_MODES,
  46. } from 'sentry/utils/discover/types';
  47. import localStorage from 'sentry/utils/localStorage';
  48. import marked from 'sentry/utils/marked';
  49. import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
  50. import {decodeList, decodeScalar} from 'sentry/utils/queryString';
  51. import withApi from 'sentry/utils/withApi';
  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 {MetricsBaselineContainer} from './metricsBaselineContainer';
  57. import ResultsHeader from './resultsHeader';
  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 {api, 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. api.clear();
  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. 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. trackAnalyticsEvent({
  305. eventKey: 'discover_v2.results.toggle_tag_facets',
  306. eventName: 'Discoverv2: Toggle Tag Facets',
  307. organization_id: parseInt(organization.id, 10),
  308. });
  309. this.setState(state => {
  310. const newValue = !state.showTags;
  311. localStorage.setItem(SHOW_TAGS_STORAGE_KEY, newValue ? '1' : '0');
  312. return {...state, showTags: newValue};
  313. });
  314. };
  315. handleSearch = (query: string) => {
  316. const {router, location} = this.props;
  317. const queryParams = normalizeDateTimeParams({
  318. ...(location.query || {}),
  319. query,
  320. });
  321. // do not propagate pagination when making a new search
  322. const searchQueryParams = omit(queryParams, 'cursor');
  323. router.push({
  324. pathname: location.pathname,
  325. query: searchQueryParams,
  326. });
  327. };
  328. handleYAxisChange = (value: string[]) => {
  329. const {router, location} = this.props;
  330. const isDisplayMultiYAxisSupported = MULTI_Y_AXIS_SUPPORTED_DISPLAY_MODES.includes(
  331. location.query.display as DisplayModes
  332. );
  333. const newQuery = {
  334. ...location.query,
  335. yAxis: value.length > 0 ? value : [null],
  336. // If using Multi Y-axis and not in a supported display, change to the default display mode
  337. display:
  338. value.length > 1 && !isDisplayMultiYAxisSupported
  339. ? location.query.display === DisplayModes.DAILYTOP5
  340. ? DisplayModes.DAILY
  341. : DisplayModes.DEFAULT
  342. : location.query.display,
  343. };
  344. router.push({
  345. pathname: location.pathname,
  346. query: newQuery,
  347. });
  348. // Treat axis changing like the user already confirmed the query
  349. if (!this.state.needConfirmation) {
  350. this.handleConfirmed();
  351. }
  352. trackAnalyticsEvent({
  353. eventKey: 'discover_v2.y_axis_change',
  354. eventName: "Discoverv2: Change chart's y axis",
  355. organization_id: parseInt(this.props.organization.id, 10),
  356. y_axis_value: value,
  357. });
  358. };
  359. handleDisplayChange = (value: string) => {
  360. const {router, location} = this.props;
  361. const newQuery = {
  362. ...location.query,
  363. display: value,
  364. };
  365. router.push({
  366. pathname: location.pathname,
  367. query: newQuery,
  368. });
  369. // Treat display changing like the user already confirmed the query
  370. if (!this.state.needConfirmation) {
  371. this.handleConfirmed();
  372. }
  373. };
  374. handleIntervalChange = (value: string | undefined) => {
  375. const {router, location} = this.props;
  376. const newQuery = {
  377. ...location.query,
  378. interval: value,
  379. };
  380. if (location.query.interval !== value) {
  381. router.push({
  382. pathname: location.pathname,
  383. query: newQuery,
  384. });
  385. // Treat display changing like the user already confirmed the query
  386. if (!this.state.needConfirmation) {
  387. this.handleConfirmed();
  388. }
  389. }
  390. };
  391. handleTopEventsChange = (value: string) => {
  392. const {router, location} = this.props;
  393. const newQuery = {
  394. ...location.query,
  395. topEvents: value,
  396. };
  397. router.push({
  398. pathname: location.pathname,
  399. query: newQuery,
  400. });
  401. // Treat display changing like the user already confirmed the query
  402. if (!this.state.needConfirmation) {
  403. this.handleConfirmed();
  404. }
  405. };
  406. getDocumentTitle(): string {
  407. const {organization} = this.props;
  408. const {eventView} = this.state;
  409. if (!eventView) {
  410. return '';
  411. }
  412. return generateTitle({eventView, organization});
  413. }
  414. renderTagsTable() {
  415. const {organization, location} = this.props;
  416. const {eventView, totalValues, confirmedQuery} = this.state;
  417. return (
  418. <Layout.Side>
  419. <Tags
  420. generateUrl={this.generateTagUrl}
  421. totalValues={totalValues}
  422. eventView={eventView}
  423. organization={organization}
  424. location={location}
  425. confirmedQuery={confirmedQuery}
  426. />
  427. </Layout.Side>
  428. );
  429. }
  430. generateTagUrl = (key: string, value: string) => {
  431. const {organization, isHomepage} = this.props;
  432. const {eventView} = this.state;
  433. const url = eventView.getResultsViewUrlTarget(organization.slug, isHomepage);
  434. url.query = generateQueryWithTag(url.query, {
  435. key: formatTagKey(key),
  436. value,
  437. });
  438. return url;
  439. };
  440. renderError(error: string) {
  441. if (!error) {
  442. return null;
  443. }
  444. return (
  445. <Alert type="error" showIcon>
  446. {error}
  447. </Alert>
  448. );
  449. }
  450. setError = (error: string, errorCode: number) => {
  451. this.setState({error, errorCode});
  452. };
  453. renderMetricsFallbackBanner() {
  454. const {organization} = this.props;
  455. if (
  456. !organization.features.includes('performance-mep-bannerless-ui') &&
  457. this.state.showMetricsAlert
  458. ) {
  459. return (
  460. <Alert type="info" showIcon>
  461. {t(
  462. "You've navigated to this page from a performance metric widget generated from processed events. The results here only show indexed events."
  463. )}
  464. </Alert>
  465. );
  466. }
  467. if (this.state.showUnparameterizedBanner) {
  468. return (
  469. <Alert type="info" showIcon>
  470. {tct(
  471. 'These are unparameterized transactions. To better organize your transactions, [link:set transaction names manually].',
  472. {
  473. link: (
  474. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/#parameterized-transaction-names" />
  475. ),
  476. }
  477. )}
  478. </Alert>
  479. );
  480. }
  481. return null;
  482. }
  483. renderTips() {
  484. const {tips} = this.state;
  485. if (tips) {
  486. return tips.map((tip, index) => (
  487. <Alert type="info" showIcon key={`tip-${index}`}>
  488. <TipContainer dangerouslySetInnerHTML={{__html: marked(tip)}} />
  489. </Alert>
  490. ));
  491. }
  492. return null;
  493. }
  494. render() {
  495. const {organization, location, router, selection, api, setSavedQuery, isHomepage} =
  496. this.props;
  497. const {
  498. eventView,
  499. error,
  500. errorCode,
  501. totalValues,
  502. showTags,
  503. confirmedQuery,
  504. savedQuery,
  505. } = this.state;
  506. const fields = eventView.hasAggregateField()
  507. ? generateAggregateFields(organization, eventView.fields)
  508. : eventView.fields;
  509. const query = eventView.query;
  510. const title = this.getDocumentTitle();
  511. const yAxisArray = getYAxis(location, eventView, savedQuery);
  512. if (!eventView.isValid()) {
  513. return <LoadingIndicator />;
  514. }
  515. return (
  516. <SentryDocumentTitle title={title} orgSlug={organization.slug}>
  517. <StyledPageContent>
  518. <NoProjectMessage organization={organization}>
  519. <ResultsHeader
  520. setSavedQuery={setSavedQuery}
  521. errorCode={errorCode}
  522. organization={organization}
  523. location={location}
  524. eventView={eventView}
  525. yAxis={yAxisArray}
  526. router={router}
  527. isHomepage={isHomepage}
  528. />
  529. <Layout.Body>
  530. <CustomMeasurementsProvider
  531. organization={organization}
  532. selection={selection}
  533. >
  534. <Top fullWidth>
  535. {this.renderMetricsFallbackBanner()}
  536. {this.renderError(error)}
  537. {this.renderTips()}
  538. <StyledPageFilterBar condensed>
  539. <ProjectPageFilter />
  540. <EnvironmentPageFilter />
  541. <DatePageFilter alignDropdown="left" />
  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. <MetricsCardinalityProvider
  558. organization={organization}
  559. location={location}
  560. >
  561. <MetricsBaselineContainer
  562. api={api}
  563. router={router}
  564. organization={organization}
  565. eventView={eventView}
  566. location={location}
  567. onAxisChange={this.handleYAxisChange}
  568. onDisplayChange={this.handleDisplayChange}
  569. onTopEventsChange={this.handleTopEventsChange}
  570. onIntervalChange={this.handleIntervalChange}
  571. total={totalValues}
  572. confirmedQuery={confirmedQuery}
  573. yAxis={yAxisArray}
  574. />
  575. </MetricsCardinalityProvider>
  576. </Top>
  577. <Layout.Main fullWidth={!showTags}>
  578. <Table
  579. organization={organization}
  580. eventView={eventView}
  581. location={location}
  582. title={title}
  583. setError={this.setError}
  584. onChangeShowTags={this.handleChangeShowTags}
  585. showTags={showTags}
  586. confirmedQuery={confirmedQuery}
  587. onCursor={this.handleCursor}
  588. isHomepage={isHomepage}
  589. setTips={(tips: string[]) => this.setState({tips})}
  590. />
  591. </Layout.Main>
  592. {showTags ? this.renderTagsTable() : null}
  593. <Confirm
  594. priority="primary"
  595. header={<strong>{t('May lead to thumb twiddling')}</strong>}
  596. confirmText={t('Do it')}
  597. cancelText={t('Nevermind')}
  598. onConfirm={this.handleConfirmed}
  599. onCancel={this.handleCancelled}
  600. message={
  601. <p>
  602. {tct(
  603. `You've created a query that will search for events made
  604. [dayLimit:over more than 30 days] for [projectLimit:more than 10 projects].
  605. A lot has happened during that time, so this might take awhile.
  606. Are you sure you want to do this?`,
  607. {
  608. dayLimit: <strong />,
  609. projectLimit: <strong />,
  610. }
  611. )}
  612. </p>
  613. }
  614. >
  615. {this.setOpenFunction}
  616. </Confirm>
  617. </CustomMeasurementsProvider>
  618. </Layout.Body>
  619. </NoProjectMessage>
  620. </StyledPageContent>
  621. </SentryDocumentTitle>
  622. );
  623. }
  624. }
  625. const StyledPageContent = styled(PageContent)`
  626. padding: 0;
  627. `;
  628. const StyledPageFilterBar = styled(PageFilterBar)`
  629. margin-bottom: ${space(1)};
  630. `;
  631. const StyledSearchBar = styled(SearchBar)`
  632. margin-bottom: ${space(2)};
  633. `;
  634. const Top = styled(Layout.Main)`
  635. flex-grow: 0;
  636. `;
  637. const TipContainer = styled('span')`
  638. > p {
  639. margin: 0;
  640. }
  641. `;
  642. type SavedQueryState = AsyncComponent['state'] & {
  643. savedQuery?: SavedQuery | null;
  644. };
  645. class SavedQueryAPI extends AsyncComponent<Props, SavedQueryState> {
  646. shouldReload = true;
  647. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  648. const {organization, location} = this.props;
  649. const endpoints: ReturnType<AsyncComponent['getEndpoints']> = [];
  650. if (location.query.id) {
  651. endpoints.push([
  652. 'savedQuery',
  653. `/organizations/${organization.slug}/discover/saved/${location.query.id}/`,
  654. ]);
  655. return endpoints;
  656. }
  657. return endpoints;
  658. }
  659. setSavedQuery = (newSavedQuery?: SavedQuery) => {
  660. this.setState({savedQuery: newSavedQuery});
  661. };
  662. renderBody(): React.ReactNode {
  663. const {savedQuery, loading} = this.state;
  664. return (
  665. <Results
  666. {...this.props}
  667. savedQuery={savedQuery ?? undefined}
  668. loading={loading}
  669. setSavedQuery={this.setSavedQuery}
  670. />
  671. );
  672. }
  673. }
  674. function ResultsContainer(props: Props) {
  675. /**
  676. * Block `<Results>` from mounting until GSH is ready since there are API
  677. * requests being performed on mount.
  678. *
  679. * Also, we skip loading last used projects if you have multiple projects feature as
  680. * you no longer need to enforce a project if it is empty. We assume an empty project is
  681. * the desired behavior because saved queries can contain a project filter. The only
  682. * exception is if we are showing a prebuilt saved query in which case we want to
  683. * respect pinned filters.
  684. */
  685. return (
  686. <PageFiltersContainer
  687. skipLoadLastUsed={
  688. props.organization.features.includes('global-views') && !!props.savedQuery
  689. }
  690. >
  691. <SavedQueryAPI {...props} />
  692. </PageFiltersContainer>
  693. );
  694. }
  695. export default withApi(withOrganization(withPageFilters(ResultsContainer)));