results.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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 ResultsChart from './resultsChart';
  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 {location, organization, selection} = this.props;
  149. const {eventView, confirmedQuery, savedQuery} = this.state;
  150. this.checkEventView();
  151. const currentQuery = eventView.getEventsAPIPayload(location);
  152. const prevQuery = prevState.eventView.getEventsAPIPayload(prevProps.location);
  153. const yAxisArray = getYAxis(location, eventView, savedQuery);
  154. const prevYAxisArray = getYAxis(prevProps.location, eventView, prevState.savedQuery);
  155. if (
  156. !isAPIPayloadSimilar(currentQuery, prevQuery) ||
  157. this.hasChartParametersChanged(
  158. prevState.eventView,
  159. eventView,
  160. prevYAxisArray,
  161. yAxisArray
  162. )
  163. ) {
  164. this.canLoadEvents();
  165. }
  166. if (
  167. !isEqual(prevProps.selection.datetime, selection.datetime) ||
  168. !isEqual(prevProps.selection.projects, selection.projects)
  169. ) {
  170. loadOrganizationTags(this.tagsApi, organization.slug, selection);
  171. addRoutePerformanceContext(selection);
  172. }
  173. if (prevState.confirmedQuery !== confirmedQuery) {
  174. this.fetchTotalCount();
  175. }
  176. }
  177. tagsApi: Client = new Client();
  178. hasChartParametersChanged(
  179. prevEventView: EventView,
  180. eventView: EventView,
  181. prevYAxisArray: string[],
  182. yAxisArray: string[]
  183. ) {
  184. if (!isEqual(prevYAxisArray, yAxisArray)) {
  185. return true;
  186. }
  187. const prevDisplay = prevEventView.getDisplayMode();
  188. const display = eventView.getDisplayMode();
  189. return prevDisplay !== display;
  190. }
  191. canLoadEvents = async () => {
  192. const {api, location, organization} = this.props;
  193. const {eventView} = this.state;
  194. let needConfirmation = false;
  195. let confirmedQuery = true;
  196. const currentQuery = eventView.getEventsAPIPayload(location);
  197. const duration = eventView.getDays();
  198. if (duration > 30 && currentQuery.project) {
  199. let projectLength = currentQuery.project.length;
  200. if (
  201. projectLength === 0 ||
  202. (projectLength === 1 && currentQuery.project[0] === '-1')
  203. ) {
  204. try {
  205. const results = await fetchProjectsCount(api, organization.slug);
  206. if (projectLength === 0) {
  207. projectLength = results.myProjects;
  208. } else {
  209. projectLength = results.allProjects;
  210. }
  211. } catch (err) {
  212. // do nothing, so the length is 0 or 1 and the query is assumed safe
  213. }
  214. }
  215. if (projectLength > 10) {
  216. needConfirmation = true;
  217. confirmedQuery = false;
  218. }
  219. }
  220. // Once confirmed, a change of project or datetime will happen before this can set it to false,
  221. // this means a query will still happen even if the new conditions need confirmation
  222. // using a state callback to return this to false
  223. this.setState({needConfirmation, confirmedQuery}, () => {
  224. this.setState({confirmedQuery: false});
  225. });
  226. if (needConfirmation) {
  227. this.openConfirm();
  228. }
  229. };
  230. openConfirm = () => {};
  231. setOpenFunction = ({open}) => {
  232. this.openConfirm = open;
  233. return null;
  234. };
  235. handleConfirmed = () => {
  236. this.setState({needConfirmation: false, confirmedQuery: true}, () => {
  237. this.setState({confirmedQuery: false});
  238. });
  239. };
  240. handleCancelled = () => {
  241. this.setState({needConfirmation: false, confirmedQuery: false});
  242. };
  243. async fetchTotalCount() {
  244. const {api, organization, location} = this.props;
  245. const {eventView, confirmedQuery} = this.state;
  246. if (confirmedQuery === false || !eventView.isValid()) {
  247. return;
  248. }
  249. try {
  250. const totals = await fetchTotalCount(
  251. api,
  252. organization.slug,
  253. eventView.getEventsAPIPayload(location)
  254. );
  255. this.setState({totalValues: totals});
  256. } catch (err) {
  257. Sentry.captureException(err);
  258. }
  259. }
  260. checkEventView() {
  261. const {eventView} = this.state;
  262. const {loading} = this.props;
  263. if (eventView.isValid() || loading) {
  264. return;
  265. }
  266. // If the view is not valid, redirect to a known valid state.
  267. const {location, organization, selection, isHomepage, savedQuery} = this.props;
  268. const isReplayEnabled = organization.features.includes('session-replay-ui');
  269. const defaultEventView = Object.assign({}, DEFAULT_EVENT_VIEW, {
  270. fields: isReplayEnabled
  271. ? DEFAULT_EVENT_VIEW.fields.concat(['replayId'])
  272. : DEFAULT_EVENT_VIEW.fields,
  273. });
  274. const query = isHomepage && savedQuery ? omit(savedQuery, 'id') : defaultEventView;
  275. const nextEventView = EventView.fromNewQueryWithLocation(query, location);
  276. if (nextEventView.project.length === 0 && selection.projects) {
  277. nextEventView.project = selection.projects;
  278. }
  279. if (selection.datetime) {
  280. const {period, utc, start, end} = selection.datetime;
  281. nextEventView.statsPeriod = period ?? undefined;
  282. nextEventView.utc = utc?.toString();
  283. nextEventView.start = normalizeDateTimeString(start);
  284. nextEventView.end = normalizeDateTimeString(end);
  285. }
  286. if (location.query?.query) {
  287. nextEventView.query = decodeScalar(location.query.query, '');
  288. }
  289. if (isHomepage && !this.state.savedQuery) {
  290. this.setState({savedQuery, eventView: nextEventView});
  291. }
  292. browserHistory.replace(
  293. nextEventView.getResultsViewUrlTarget(organization.slug, isHomepage)
  294. );
  295. }
  296. handleCursor: CursorHandler = (cursor, path, query, _direction) => {
  297. const {router} = this.props;
  298. router.push({
  299. pathname: path,
  300. query: {...query, cursor},
  301. });
  302. // Treat pagination like the user already confirmed the query
  303. if (!this.state.needConfirmation) {
  304. this.handleConfirmed();
  305. }
  306. };
  307. handleChangeShowTags = () => {
  308. const {organization} = this.props;
  309. trackAnalyticsEvent({
  310. eventKey: 'discover_v2.results.toggle_tag_facets',
  311. eventName: 'Discoverv2: Toggle Tag Facets',
  312. organization_id: parseInt(organization.id, 10),
  313. });
  314. this.setState(state => {
  315. const newValue = !state.showTags;
  316. localStorage.setItem(SHOW_TAGS_STORAGE_KEY, newValue ? '1' : '0');
  317. return {...state, showTags: newValue};
  318. });
  319. };
  320. handleSearch = (query: string) => {
  321. const {router, location} = this.props;
  322. const queryParams = normalizeDateTimeParams({
  323. ...(location.query || {}),
  324. query,
  325. });
  326. // do not propagate pagination when making a new search
  327. const searchQueryParams = omit(queryParams, 'cursor');
  328. router.push({
  329. pathname: location.pathname,
  330. query: searchQueryParams,
  331. });
  332. };
  333. handleYAxisChange = (value: string[]) => {
  334. const {router, location} = this.props;
  335. const isDisplayMultiYAxisSupported = MULTI_Y_AXIS_SUPPORTED_DISPLAY_MODES.includes(
  336. location.query.display as DisplayModes
  337. );
  338. const newQuery = {
  339. ...location.query,
  340. yAxis: value.length > 0 ? value : [null],
  341. // If using Multi Y-axis and not in a supported display, change to the default display mode
  342. display:
  343. value.length > 1 && !isDisplayMultiYAxisSupported
  344. ? location.query.display === DisplayModes.DAILYTOP5
  345. ? DisplayModes.DAILY
  346. : DisplayModes.DEFAULT
  347. : location.query.display,
  348. };
  349. router.push({
  350. pathname: location.pathname,
  351. query: newQuery,
  352. });
  353. // Treat axis changing like the user already confirmed the query
  354. if (!this.state.needConfirmation) {
  355. this.handleConfirmed();
  356. }
  357. trackAnalyticsEvent({
  358. eventKey: 'discover_v2.y_axis_change',
  359. eventName: "Discoverv2: Change chart's y axis",
  360. organization_id: parseInt(this.props.organization.id, 10),
  361. y_axis_value: value,
  362. });
  363. };
  364. handleDisplayChange = (value: string) => {
  365. const {router, location} = this.props;
  366. const newQuery = {
  367. ...location.query,
  368. display: 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. handleIntervalChange = (value: string | undefined) => {
  380. const {router, location} = this.props;
  381. const newQuery = {
  382. ...location.query,
  383. interval: value,
  384. };
  385. if (location.query.interval !== value) {
  386. router.push({
  387. pathname: location.pathname,
  388. query: newQuery,
  389. });
  390. // Treat display changing like the user already confirmed the query
  391. if (!this.state.needConfirmation) {
  392. this.handleConfirmed();
  393. }
  394. }
  395. };
  396. handleTopEventsChange = (value: string) => {
  397. const {router, location} = this.props;
  398. const newQuery = {
  399. ...location.query,
  400. topEvents: value,
  401. };
  402. router.push({
  403. pathname: location.pathname,
  404. query: newQuery,
  405. });
  406. // Treat display changing like the user already confirmed the query
  407. if (!this.state.needConfirmation) {
  408. this.handleConfirmed();
  409. }
  410. };
  411. getDocumentTitle(): string {
  412. const {organization} = this.props;
  413. const {eventView} = this.state;
  414. if (!eventView) {
  415. return '';
  416. }
  417. return generateTitle({eventView, organization});
  418. }
  419. renderTagsTable() {
  420. const {organization, location} = this.props;
  421. const {eventView, totalValues, confirmedQuery} = this.state;
  422. return (
  423. <Layout.Side>
  424. <Tags
  425. generateUrl={this.generateTagUrl}
  426. totalValues={totalValues}
  427. eventView={eventView}
  428. organization={organization}
  429. location={location}
  430. confirmedQuery={confirmedQuery}
  431. />
  432. </Layout.Side>
  433. );
  434. }
  435. generateTagUrl = (key: string, value: string) => {
  436. const {organization, isHomepage} = this.props;
  437. const {eventView} = this.state;
  438. const url = eventView.getResultsViewUrlTarget(organization.slug, isHomepage);
  439. url.query = generateQueryWithTag(url.query, {
  440. key: formatTagKey(key),
  441. value,
  442. });
  443. return url;
  444. };
  445. renderError(error: string) {
  446. if (!error) {
  447. return null;
  448. }
  449. return (
  450. <Alert type="error" showIcon>
  451. {error}
  452. </Alert>
  453. );
  454. }
  455. setError = (error: string, errorCode: number) => {
  456. this.setState({error, errorCode});
  457. };
  458. renderMetricsFallbackBanner() {
  459. const {organization} = this.props;
  460. if (
  461. !organization.features.includes('performance-mep-bannerless-ui') &&
  462. this.state.showMetricsAlert
  463. ) {
  464. return (
  465. <Alert type="info" showIcon>
  466. {t(
  467. "You've navigated to this page from a performance metric widget generated from processed events. The results here only show indexed events."
  468. )}
  469. </Alert>
  470. );
  471. }
  472. if (this.state.showUnparameterizedBanner) {
  473. return (
  474. <Alert type="info" showIcon>
  475. {tct(
  476. 'These are unparameterized transactions. To better organize your transactions, [link:set transaction names manually].',
  477. {
  478. link: (
  479. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/#parameterized-transaction-names" />
  480. ),
  481. }
  482. )}
  483. </Alert>
  484. );
  485. }
  486. return null;
  487. }
  488. renderTips() {
  489. const {tips} = this.state;
  490. if (tips) {
  491. return tips.map((tip, index) => (
  492. <Alert type="info" showIcon key={`tip-${index}`}>
  493. <TipContainer dangerouslySetInnerHTML={{__html: marked(tip)}} />
  494. </Alert>
  495. ));
  496. }
  497. return null;
  498. }
  499. render() {
  500. const {organization, location, router, selection, api, setSavedQuery, isHomepage} =
  501. this.props;
  502. const {
  503. eventView,
  504. error,
  505. errorCode,
  506. totalValues,
  507. showTags,
  508. confirmedQuery,
  509. savedQuery,
  510. } = this.state;
  511. const fields = eventView.hasAggregateField()
  512. ? generateAggregateFields(organization, eventView.fields)
  513. : eventView.fields;
  514. const query = eventView.query;
  515. const title = this.getDocumentTitle();
  516. const yAxisArray = getYAxis(location, eventView, savedQuery);
  517. if (!eventView.isValid()) {
  518. return <LoadingIndicator />;
  519. }
  520. return (
  521. <SentryDocumentTitle title={title} orgSlug={organization.slug}>
  522. <StyledPageContent>
  523. <NoProjectMessage organization={organization}>
  524. <ResultsHeader
  525. setSavedQuery={setSavedQuery}
  526. errorCode={errorCode}
  527. organization={organization}
  528. location={location}
  529. eventView={eventView}
  530. yAxis={yAxisArray}
  531. router={router}
  532. isHomepage={isHomepage}
  533. />
  534. <Layout.Body>
  535. <CustomMeasurementsProvider
  536. organization={organization}
  537. selection={selection}
  538. >
  539. <Top fullWidth>
  540. {this.renderMetricsFallbackBanner()}
  541. {this.renderError(error)}
  542. {this.renderTips()}
  543. <StyledPageFilterBar condensed>
  544. <ProjectPageFilter />
  545. <EnvironmentPageFilter />
  546. <DatePageFilter alignDropdown="left" />
  547. </StyledPageFilterBar>
  548. <CustomMeasurementsContext.Consumer>
  549. {contextValue => (
  550. <StyledSearchBar
  551. searchSource="eventsv2"
  552. organization={organization}
  553. projectIds={eventView.project}
  554. query={query}
  555. fields={fields}
  556. onSearch={this.handleSearch}
  557. maxQueryLength={MAX_QUERY_LENGTH}
  558. customMeasurements={contextValue?.customMeasurements ?? undefined}
  559. />
  560. )}
  561. </CustomMeasurementsContext.Consumer>
  562. <MetricsCardinalityProvider
  563. organization={organization}
  564. location={location}
  565. >
  566. <ResultsChart
  567. api={api}
  568. router={router}
  569. organization={organization}
  570. eventView={eventView}
  571. location={location}
  572. onAxisChange={this.handleYAxisChange}
  573. onDisplayChange={this.handleDisplayChange}
  574. onTopEventsChange={this.handleTopEventsChange}
  575. onIntervalChange={this.handleIntervalChange}
  576. total={totalValues}
  577. confirmedQuery={confirmedQuery}
  578. yAxis={yAxisArray}
  579. />
  580. </MetricsCardinalityProvider>
  581. </Top>
  582. <Layout.Main fullWidth={!showTags}>
  583. <Table
  584. organization={organization}
  585. eventView={eventView}
  586. location={location}
  587. title={title}
  588. setError={this.setError}
  589. onChangeShowTags={this.handleChangeShowTags}
  590. showTags={showTags}
  591. confirmedQuery={confirmedQuery}
  592. onCursor={this.handleCursor}
  593. isHomepage={isHomepage}
  594. setTips={(tips: string[]) => this.setState({tips})}
  595. />
  596. </Layout.Main>
  597. {showTags ? this.renderTagsTable() : null}
  598. <Confirm
  599. priority="primary"
  600. header={<strong>{t('May lead to thumb twiddling')}</strong>}
  601. confirmText={t('Do it')}
  602. cancelText={t('Nevermind')}
  603. onConfirm={this.handleConfirmed}
  604. onCancel={this.handleCancelled}
  605. message={
  606. <p>
  607. {tct(
  608. `You've created a query that will search for events made
  609. [dayLimit:over more than 30 days] for [projectLimit:more than 10 projects].
  610. A lot has happened during that time, so this might take awhile.
  611. Are you sure you want to do this?`,
  612. {
  613. dayLimit: <strong />,
  614. projectLimit: <strong />,
  615. }
  616. )}
  617. </p>
  618. }
  619. >
  620. {this.setOpenFunction}
  621. </Confirm>
  622. </CustomMeasurementsProvider>
  623. </Layout.Body>
  624. </NoProjectMessage>
  625. </StyledPageContent>
  626. </SentryDocumentTitle>
  627. );
  628. }
  629. }
  630. const StyledPageContent = styled(PageContent)`
  631. padding: 0;
  632. `;
  633. const StyledPageFilterBar = styled(PageFilterBar)`
  634. margin-bottom: ${space(1)};
  635. `;
  636. const StyledSearchBar = styled(SearchBar)`
  637. margin-bottom: ${space(2)};
  638. `;
  639. const Top = styled(Layout.Main)`
  640. flex-grow: 0;
  641. `;
  642. const TipContainer = styled('span')`
  643. > p {
  644. margin: 0;
  645. }
  646. `;
  647. type SavedQueryState = AsyncComponent['state'] & {
  648. savedQuery?: SavedQuery | null;
  649. };
  650. class SavedQueryAPI extends AsyncComponent<Props, SavedQueryState> {
  651. shouldReload = true;
  652. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  653. const {organization, location} = this.props;
  654. const endpoints: ReturnType<AsyncComponent['getEndpoints']> = [];
  655. if (location.query.id) {
  656. endpoints.push([
  657. 'savedQuery',
  658. `/organizations/${organization.slug}/discover/saved/${location.query.id}/`,
  659. ]);
  660. return endpoints;
  661. }
  662. return endpoints;
  663. }
  664. setSavedQuery = (newSavedQuery?: SavedQuery) => {
  665. this.setState({savedQuery: newSavedQuery});
  666. };
  667. renderBody(): React.ReactNode {
  668. const {savedQuery, loading} = this.state;
  669. return (
  670. <Results
  671. {...this.props}
  672. savedQuery={savedQuery ?? undefined}
  673. loading={loading}
  674. setSavedQuery={this.setSavedQuery}
  675. />
  676. );
  677. }
  678. }
  679. function ResultsContainer(props: Props) {
  680. /**
  681. * Block `<Results>` from mounting until GSH is ready since there are API
  682. * requests being performed on mount.
  683. *
  684. * Also, we skip loading last used projects if you have multiple projects feature as
  685. * you no longer need to enforce a project if it is empty. We assume an empty project is
  686. * the desired behavior because saved queries can contain a project filter. The only
  687. * exception is if we are showing a prebuilt saved query in which case we want to
  688. * respect pinned filters.
  689. */
  690. return (
  691. <PageFiltersContainer
  692. skipLoadLastUsed={
  693. props.organization.features.includes('global-views') && !!props.savedQuery
  694. }
  695. >
  696. <SavedQueryAPI {...props} />
  697. </PageFiltersContainer>
  698. );
  699. }
  700. export default withApi(withOrganization(withPageFilters(ResultsContainer)));