overview.tsx 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  1. import {Component} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import * as Sentry from '@sentry/react';
  5. import type {Location} from 'history';
  6. import Cookies from 'js-cookie';
  7. import isEqual from 'lodash/isEqual';
  8. import mapValues from 'lodash/mapValues';
  9. import omit from 'lodash/omit';
  10. import pickBy from 'lodash/pickBy';
  11. import moment from 'moment';
  12. import * as qs from 'query-string';
  13. import {addMessage} from 'sentry/actionCreators/indicator';
  14. import {fetchOrgMembers, indexMembersByProject} from 'sentry/actionCreators/members';
  15. import {fetchTagValues, loadOrganizationTags} from 'sentry/actionCreators/tags';
  16. import type {Client} from 'sentry/api';
  17. import HookOrDefault from 'sentry/components/hookOrDefault';
  18. import * as Layout from 'sentry/components/layouts/thirds';
  19. import LoadingIndicator from 'sentry/components/loadingIndicator';
  20. import {extractSelectionParameters} from 'sentry/components/organizations/pageFilters/utils';
  21. import type {CursorHandler} from 'sentry/components/pagination';
  22. import Pagination from 'sentry/components/pagination';
  23. import Panel from 'sentry/components/panels/panel';
  24. import PanelBody from 'sentry/components/panels/panelBody';
  25. import QueryCount from 'sentry/components/queryCount';
  26. import ProcessingIssueList from 'sentry/components/stream/processingIssueList';
  27. import {DEFAULT_QUERY, DEFAULT_STATS_PERIOD, NEW_DEFAULT_QUERY} from 'sentry/constants';
  28. import {t, tct} from 'sentry/locale';
  29. import GroupStore from 'sentry/stores/groupStore';
  30. import IssueListCacheStore from 'sentry/stores/IssueListCacheStore';
  31. import SelectedGroupStore from 'sentry/stores/selectedGroupStore';
  32. import {space} from 'sentry/styles/space';
  33. import type {
  34. BaseGroup,
  35. Group,
  36. Organization,
  37. PageFilters,
  38. PriorityLevel,
  39. SavedSearch,
  40. TagCollection,
  41. } from 'sentry/types';
  42. import {GroupStatus, IssueCategory} from 'sentry/types';
  43. import {defined} from 'sentry/utils';
  44. import {trackAnalytics} from 'sentry/utils/analytics';
  45. import {browserHistory} from 'sentry/utils/browserHistory';
  46. import CursorPoller from 'sentry/utils/cursorPoller';
  47. import {getUtcDateString} from 'sentry/utils/dates';
  48. import getCurrentSentryReactRootSpan from 'sentry/utils/getCurrentSentryReactRootSpan';
  49. import parseApiError from 'sentry/utils/parseApiError';
  50. import parseLinkHeader from 'sentry/utils/parseLinkHeader';
  51. import {
  52. makeIssuesINPObserver,
  53. VisuallyCompleteWithData,
  54. } from 'sentry/utils/performanceForSentry';
  55. import {decodeScalar} from 'sentry/utils/queryString';
  56. import type {WithRouteAnalyticsProps} from 'sentry/utils/routeAnalytics/withRouteAnalytics';
  57. import withRouteAnalytics from 'sentry/utils/routeAnalytics/withRouteAnalytics';
  58. import withApi from 'sentry/utils/withApi';
  59. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  60. import withIssueTags from 'sentry/utils/withIssueTags';
  61. import withOrganization from 'sentry/utils/withOrganization';
  62. import withPageFilters from 'sentry/utils/withPageFilters';
  63. import withSavedSearches from 'sentry/utils/withSavedSearches';
  64. import SavedIssueSearches from 'sentry/views/issueList/savedIssueSearches';
  65. import type {IssueUpdateData} from 'sentry/views/issueList/types';
  66. import {parseIssuePrioritySearch} from 'sentry/views/issueList/utils/parseIssuePrioritySearch';
  67. import IssueListActions from './actions';
  68. import IssueListFilters from './filters';
  69. import GroupListBody from './groupListBody';
  70. import IssueListHeader from './header';
  71. import type {QueryCounts} from './utils';
  72. import {
  73. DEFAULT_ISSUE_STREAM_SORT,
  74. FOR_REVIEW_QUERIES,
  75. getTabs,
  76. getTabsWithCounts,
  77. isForReviewQuery,
  78. IssueSortOptions,
  79. Query,
  80. TAB_MAX_COUNT,
  81. } from './utils';
  82. const MAX_ITEMS = 25;
  83. // the default period for the graph in each issue row
  84. const DEFAULT_GRAPH_STATS_PERIOD = '24h';
  85. // the allowed period choices for graph in each issue row
  86. const DYNAMIC_COUNTS_STATS_PERIODS = new Set(['14d', '24h', 'auto']);
  87. const MAX_ISSUES_COUNT = 100;
  88. type Params = {
  89. orgId: string;
  90. };
  91. type Props = {
  92. api: Client;
  93. location: Location;
  94. organization: Organization;
  95. params: Params;
  96. savedSearch: SavedSearch;
  97. savedSearchLoading: boolean;
  98. savedSearches: SavedSearch[];
  99. selectedSearchId: string;
  100. selection: PageFilters;
  101. tags: TagCollection;
  102. } & RouteComponentProps<{}, {searchId?: string}> &
  103. WithRouteAnalyticsProps;
  104. type State = {
  105. error: string | null;
  106. groupIds: string[];
  107. issuesLoading: boolean;
  108. memberList: ReturnType<typeof indexMembersByProject>;
  109. pageLinks: string;
  110. /**
  111. * Current query total
  112. */
  113. queryCount: number;
  114. /**
  115. * Counts for each inbox tab
  116. */
  117. queryCounts: QueryCounts;
  118. queryMaxCount: number;
  119. realtimeActive: boolean;
  120. selectAllActive: boolean;
  121. // Will be set to true if there is valid session data from issue-stats api call
  122. query?: string;
  123. };
  124. interface EndpointParams extends Partial<PageFilters['datetime']> {
  125. environment: string[];
  126. project: number[];
  127. cursor?: string;
  128. groupStatsPeriod?: string | null;
  129. page?: number | string;
  130. query?: string;
  131. sort?: string;
  132. statsPeriod?: string | null;
  133. useGroupSnubaDataset?: boolean;
  134. }
  135. type CountsEndpointParams = Omit<EndpointParams, 'cursor' | 'page' | 'query'> & {
  136. query: string[];
  137. };
  138. type StatEndpointParams = Omit<EndpointParams, 'cursor' | 'page'> & {
  139. groups: string[];
  140. expand?: string | string[];
  141. };
  142. const DataConsentBanner = HookOrDefault({
  143. hookName: 'component:data-consent-banner',
  144. defaultComponent: null,
  145. });
  146. class IssueListOverview extends Component<Props, State> {
  147. state: State = this.getInitialState();
  148. getInitialState() {
  149. const realtimeActiveCookie = Cookies.get('realtimeActive');
  150. const realtimeActive =
  151. typeof realtimeActiveCookie === 'undefined'
  152. ? false
  153. : realtimeActiveCookie === 'true';
  154. return {
  155. groupIds: [],
  156. actionTaken: false,
  157. selectAllActive: false,
  158. realtimeActive,
  159. pageLinks: '',
  160. queryCount: 0,
  161. queryCounts: {},
  162. queryMaxCount: 0,
  163. error: null,
  164. issuesLoading: true,
  165. memberList: {},
  166. };
  167. }
  168. componentDidMount() {
  169. this._performanceObserver = makeIssuesINPObserver();
  170. this._poller = new CursorPoller({
  171. linkPreviousHref: parseLinkHeader(this.state.pageLinks)?.previous?.href,
  172. success: this.onRealtimePoll,
  173. });
  174. // Wait for saved searches to load so if the user is on a saved search
  175. // or they have a pinned search we load the correct data the first time.
  176. // But if searches are already there, we can go right to fetching issues
  177. if (
  178. !this.props.savedSearchLoading ||
  179. this.props.organization.features.includes('issue-stream-performance')
  180. ) {
  181. const loadedFromCache = this.loadFromCache();
  182. if (!loadedFromCache) {
  183. // It's possible the projects query parameter is not yet ready and this
  184. // request will be repeated in componentDidUpdate
  185. this.fetchData();
  186. }
  187. }
  188. this.fetchTags();
  189. this.fetchMemberList();
  190. // let custom analytics take control
  191. this.props.setDisableRouteAnalytics?.();
  192. }
  193. componentDidUpdate(prevProps: Props, prevState: State) {
  194. if (prevState.realtimeActive !== this.state.realtimeActive) {
  195. // User toggled realtime button
  196. if (this.state.realtimeActive) {
  197. this.resumePolling();
  198. } else {
  199. this._poller.disable();
  200. }
  201. }
  202. // If the project selection has changed reload the member list and tag keys
  203. // allowing autocomplete and tag sidebar to be more accurate.
  204. if (!isEqual(prevProps.selection.projects, this.props.selection.projects)) {
  205. this.loadFromCache();
  206. this.fetchMemberList();
  207. this.fetchTags();
  208. }
  209. const selectionChanged = !isEqual(prevProps.selection, this.props.selection);
  210. // Wait for saved searches to load before we attempt to fetch stream data
  211. // Selection changing could indicate that the projects query parameter has populated
  212. // and we should refetch data.
  213. if (this.props.savedSearchLoading && !selectionChanged) {
  214. return;
  215. }
  216. if (
  217. prevProps.savedSearchLoading &&
  218. !this.props.savedSearchLoading &&
  219. this.props.organization.features.includes('issue-stream-performance')
  220. ) {
  221. return;
  222. }
  223. if (
  224. prevProps.savedSearchLoading &&
  225. !this.props.organization.features.includes('issue-stream-performance')
  226. ) {
  227. const loadedFromCache = this.loadFromCache();
  228. if (!loadedFromCache) {
  229. this.fetchData();
  230. }
  231. return;
  232. }
  233. const prevUrlQuery = prevProps.location.query;
  234. const newUrlQuery = this.props.location.query;
  235. const prevQuery = this.getQueryFromSavedSearchOrLocation({
  236. savedSearch: prevProps.savedSearch,
  237. location: prevProps.location,
  238. });
  239. const newQuery = this.getQuery();
  240. const prevSort = this.getSortFromSavedSearchOrLocation({
  241. savedSearch: prevProps.savedSearch,
  242. location: prevProps.location,
  243. });
  244. const newSort = this.getSort();
  245. // If any important url parameter changed or saved search changed
  246. // reload data.
  247. if (
  248. selectionChanged ||
  249. prevUrlQuery.cursor !== newUrlQuery.cursor ||
  250. prevUrlQuery.statsPeriod !== newUrlQuery.statsPeriod ||
  251. prevUrlQuery.groupStatsPeriod !== newUrlQuery.groupStatsPeriod ||
  252. prevQuery !== newQuery ||
  253. prevSort !== newSort
  254. ) {
  255. this.fetchData(selectionChanged);
  256. } else if (
  257. !this._lastRequest &&
  258. prevState.issuesLoading === false &&
  259. this.state.issuesLoading
  260. ) {
  261. // Reload if we issues are loading or their loading state changed.
  262. // This can happen when transitionTo is called
  263. this.fetchData();
  264. }
  265. }
  266. componentWillUnmount() {
  267. const groups = GroupStore.getState() as Group[];
  268. if (groups.length > 0 && !this.state.issuesLoading && !this.state.realtimeActive) {
  269. IssueListCacheStore.save(this.getCacheEndpointParams(), {
  270. groups,
  271. queryCount: this.state.queryCount,
  272. queryMaxCount: this.state.queryMaxCount,
  273. pageLinks: this.state.pageLinks,
  274. });
  275. }
  276. if (this._performanceObserver) {
  277. this._performanceObserver.disconnect();
  278. }
  279. this._poller.disable();
  280. SelectedGroupStore.reset();
  281. GroupStore.reset();
  282. this.props.api.clear();
  283. this.listener?.();
  284. }
  285. private _performanceObserver: PerformanceObserver | undefined;
  286. private _poller: any;
  287. private _lastRequest: any;
  288. private _lastStatsRequest: any;
  289. private _lastFetchCountsRequest: any;
  290. private actionTaken = false;
  291. private undo = false;
  292. getQueryFromSavedSearchOrLocation({
  293. savedSearch,
  294. location,
  295. }: Pick<Props, 'savedSearch' | 'location'>): string {
  296. if (savedSearch) {
  297. return savedSearch.query;
  298. }
  299. const {query} = location.query;
  300. if (query !== undefined) {
  301. return decodeScalar(query, '');
  302. }
  303. return this.props.organization.features.includes('issue-priority-ui')
  304. ? NEW_DEFAULT_QUERY
  305. : DEFAULT_QUERY;
  306. }
  307. getSortFromSavedSearchOrLocation({
  308. savedSearch,
  309. location,
  310. }: Pick<Props, 'savedSearch' | 'location'>): string {
  311. if (!location.query.sort && savedSearch?.id) {
  312. return savedSearch.sort;
  313. }
  314. if (location.query.sort) {
  315. return location.query.sort as string;
  316. }
  317. return DEFAULT_ISSUE_STREAM_SORT;
  318. }
  319. /**
  320. * Load the previous
  321. * @returns Returns true if the data was loaded from cache
  322. */
  323. loadFromCache(): boolean {
  324. const cache = IssueListCacheStore.getFromCache(this.getCacheEndpointParams());
  325. if (!cache) {
  326. return false;
  327. }
  328. this.setState(
  329. {
  330. issuesLoading: false,
  331. queryCount: cache.queryCount,
  332. queryMaxCount: cache.queryMaxCount,
  333. pageLinks: cache.pageLinks,
  334. },
  335. () => {
  336. // Handle this in the next tick to avoid being overwritten by GroupStore.reset
  337. // Group details clears the GroupStore at the same time this component mounts
  338. GroupStore.add(cache.groups);
  339. // Clear cache after loading
  340. IssueListCacheStore.reset();
  341. }
  342. );
  343. return true;
  344. }
  345. getQuery(): string {
  346. return this.getQueryFromSavedSearchOrLocation({
  347. savedSearch: this.props.savedSearch,
  348. location: this.props.location,
  349. });
  350. }
  351. getSort(): string {
  352. return this.getSortFromSavedSearchOrLocation({
  353. savedSearch: this.props.savedSearch,
  354. location: this.props.location,
  355. });
  356. }
  357. getGroupStatsPeriod(): string {
  358. let currentPeriod: string;
  359. if (typeof this.props.location.query?.groupStatsPeriod === 'string') {
  360. currentPeriod = this.props.location.query.groupStatsPeriod;
  361. } else {
  362. currentPeriod = DEFAULT_GRAPH_STATS_PERIOD;
  363. }
  364. return DYNAMIC_COUNTS_STATS_PERIODS.has(currentPeriod)
  365. ? currentPeriod
  366. : DEFAULT_GRAPH_STATS_PERIOD;
  367. }
  368. getEndpointParams = (): EndpointParams => {
  369. const {selection} = this.props;
  370. const params: EndpointParams = {
  371. project: selection.projects,
  372. environment: selection.environments,
  373. query: this.getQuery(),
  374. ...selection.datetime,
  375. };
  376. if (selection.datetime.period) {
  377. delete params.period;
  378. params.statsPeriod = selection.datetime.period;
  379. }
  380. if (params.end) {
  381. params.end = getUtcDateString(params.end);
  382. }
  383. if (params.start) {
  384. params.start = getUtcDateString(params.start);
  385. }
  386. const sort = this.getSort();
  387. if (sort !== DEFAULT_ISSUE_STREAM_SORT) {
  388. params.sort = sort;
  389. }
  390. const groupStatsPeriod = this.getGroupStatsPeriod();
  391. if (groupStatsPeriod !== DEFAULT_GRAPH_STATS_PERIOD) {
  392. params.groupStatsPeriod = groupStatsPeriod;
  393. }
  394. if (this.props.location.query.useGroupSnubaDataset) {
  395. params.useGroupSnubaDataset = true;
  396. }
  397. // only include defined values.
  398. return pickBy(params, v => defined(v)) as EndpointParams;
  399. };
  400. getCacheEndpointParams = (): EndpointParams => {
  401. const cursor = this.props.location.query.cursor;
  402. return {
  403. ...this.getEndpointParams(),
  404. cursor,
  405. };
  406. };
  407. getSelectedProjectIds = (): string[] => {
  408. return this.props.selection.projects.map(projectId => String(projectId));
  409. };
  410. fetchMemberList() {
  411. const projectIds = this.getSelectedProjectIds();
  412. fetchOrgMembers(this.props.api, this.props.organization.slug, projectIds).then(
  413. members => {
  414. this.setState({memberList: indexMembersByProject(members)});
  415. }
  416. );
  417. }
  418. fetchTags() {
  419. const {api, organization, selection} = this.props;
  420. loadOrganizationTags(api, organization.slug, selection);
  421. }
  422. fetchStats = (groups: string[]) => {
  423. // If we have no groups to fetch, just skip stats
  424. if (!groups.length) {
  425. return;
  426. }
  427. const requestParams: StatEndpointParams = {
  428. ...this.getEndpointParams(),
  429. groups,
  430. };
  431. // If no stats period values are set, use default
  432. if (!requestParams.statsPeriod && !requestParams.start) {
  433. requestParams.statsPeriod = DEFAULT_STATS_PERIOD;
  434. }
  435. this._lastStatsRequest = this.props.api.request(this.groupStatsEndpoint, {
  436. method: 'GET',
  437. data: qs.stringify(requestParams),
  438. success: data => {
  439. if (!data) {
  440. return;
  441. }
  442. GroupStore.onPopulateStats(groups, data);
  443. this.trackTabViewed(groups, data, this.state.queryCount);
  444. },
  445. error: err => {
  446. this.setState({
  447. error: parseApiError(err),
  448. });
  449. },
  450. complete: () => {
  451. this._lastStatsRequest = null;
  452. // End navigation transaction to prevent additional page requests from impacting page metrics.
  453. // Other transactions include stacktrace preview request
  454. const currentSpan = Sentry.getActiveSpan();
  455. const rootSpan = currentSpan ? Sentry.getRootSpan(currentSpan) : undefined;
  456. if (rootSpan && Sentry.spanToJSON(rootSpan).op === 'navigation') {
  457. rootSpan.end();
  458. }
  459. },
  460. });
  461. };
  462. fetchCounts = (currentQueryCount: number, fetchAllCounts: boolean) => {
  463. const {organization} = this.props;
  464. const {queryCounts: _queryCounts} = this.state;
  465. let queryCounts: QueryCounts = {..._queryCounts};
  466. const endpointParams = this.getEndpointParams();
  467. const tabQueriesWithCounts = getTabsWithCounts(organization);
  468. const currentTabQuery = tabQueriesWithCounts.includes(endpointParams.query as Query)
  469. ? endpointParams.query
  470. : null;
  471. // Update the count based on the exact number of issues, these shown as is
  472. if (currentTabQuery) {
  473. queryCounts[currentTabQuery] = {
  474. count: currentQueryCount,
  475. hasMore: false,
  476. };
  477. }
  478. this.setState({queryCounts});
  479. // If all tabs' counts are fetched, skip and only set
  480. if (
  481. fetchAllCounts ||
  482. !tabQueriesWithCounts.every(tabQuery => queryCounts[tabQuery] !== undefined)
  483. ) {
  484. const requestParams: CountsEndpointParams = {
  485. ...omit(endpointParams, 'query'),
  486. // fetch the counts for the tabs whose counts haven't been fetched yet
  487. query: tabQueriesWithCounts.filter(_query => _query !== currentTabQuery),
  488. };
  489. // If no stats period values are set, use default
  490. if (!requestParams.statsPeriod && !requestParams.start) {
  491. requestParams.statsPeriod = DEFAULT_STATS_PERIOD;
  492. }
  493. this._lastFetchCountsRequest = this.props.api.request(this.groupCountsEndpoint, {
  494. method: 'GET',
  495. data: qs.stringify(requestParams),
  496. success: data => {
  497. if (!data) {
  498. return;
  499. }
  500. // Counts coming from the counts endpoint is limited to 100, for >= 100 we display 99+
  501. queryCounts = {
  502. ...queryCounts,
  503. ...mapValues(data, (count: number) => ({
  504. count,
  505. hasMore: count > TAB_MAX_COUNT,
  506. })),
  507. };
  508. },
  509. error: () => {
  510. this.setState({queryCounts: {}});
  511. },
  512. complete: () => {
  513. this._lastFetchCountsRequest = null;
  514. this.setState({queryCounts});
  515. },
  516. });
  517. }
  518. };
  519. fetchData = (fetchAllCounts = false) => {
  520. const {organization} = this.props;
  521. const query = this.getQuery();
  522. if (this.state.realtimeActive || (!this.actionTaken && !this.undo)) {
  523. GroupStore.loadInitialData([]);
  524. this.setState({
  525. issuesLoading: true,
  526. queryCount: 0,
  527. error: null,
  528. });
  529. }
  530. const span = getCurrentSentryReactRootSpan();
  531. span?.setAttribute('query.sort', this.getSort());
  532. this.setState({
  533. error: null,
  534. });
  535. // Used for Issue Stream Performance project, enabled means we are doing saved search look up in the backend
  536. const savedSearchLookupEnabled = 0;
  537. const savedSearchLookupDisabled = 1;
  538. const requestParams: any = {
  539. ...this.getEndpointParams(),
  540. limit: MAX_ITEMS,
  541. shortIdLookup: 1,
  542. savedSearch: this.props.organization.features.includes('issue-stream-performance')
  543. ? this.props.savedSearchLoading
  544. ? savedSearchLookupEnabled
  545. : savedSearchLookupDisabled
  546. : savedSearchLookupDisabled,
  547. };
  548. if (
  549. this.props.organization.features.includes('issue-stream-performance') &&
  550. this.props.selectedSearchId
  551. ) {
  552. requestParams.searchId = this.props.selectedSearchId;
  553. }
  554. if (
  555. this.props.organization.features.includes('issue-stream-performance') &&
  556. this.props.savedSearchLoading &&
  557. !defined(this.props.location.query.query)
  558. ) {
  559. delete requestParams.query;
  560. }
  561. const currentQuery = this.props.location.query || {};
  562. if ('cursor' in currentQuery) {
  563. requestParams.cursor = currentQuery.cursor;
  564. }
  565. // If no stats period values are set, use default
  566. if (!requestParams.statsPeriod && !requestParams.start) {
  567. requestParams.statsPeriod = DEFAULT_STATS_PERIOD;
  568. }
  569. requestParams.expand = ['owners', 'inbox'];
  570. requestParams.collapse = ['stats', 'unhandled'];
  571. if (this._lastRequest) {
  572. this._lastRequest.cancel();
  573. }
  574. if (this._lastStatsRequest) {
  575. this._lastStatsRequest.cancel();
  576. }
  577. if (this._lastFetchCountsRequest) {
  578. this._lastFetchCountsRequest.cancel();
  579. }
  580. this._poller.disable();
  581. this._lastRequest = this.props.api.request(this.groupListEndpoint, {
  582. method: 'GET',
  583. data: qs.stringify(requestParams),
  584. success: (data, _, resp) => {
  585. if (!resp) {
  586. return;
  587. }
  588. // If this is a direct hit, we redirect to the intended result directly.
  589. if (resp.getResponseHeader('X-Sentry-Direct-Hit') === '1') {
  590. let redirect: string;
  591. if (data[0]?.matchingEventId) {
  592. const {id, matchingEventId} = data[0];
  593. redirect = `/organizations/${organization.slug}/issues/${id}/events/${matchingEventId}/`;
  594. } else {
  595. const {id} = data[0];
  596. redirect = `/organizations/${organization.slug}/issues/${id}/`;
  597. }
  598. browserHistory.replace(
  599. normalizeUrl({
  600. pathname: redirect,
  601. query: {
  602. referrer: 'issue-list',
  603. ...extractSelectionParameters(this.props.location.query),
  604. },
  605. })
  606. );
  607. return;
  608. }
  609. if (this.undo) {
  610. GroupStore.loadInitialData(data);
  611. }
  612. GroupStore.add(data);
  613. this.fetchStats(data.map((group: BaseGroup) => group.id));
  614. const hits = resp.getResponseHeader('X-Hits');
  615. const queryCount =
  616. typeof hits !== 'undefined' && hits ? parseInt(hits, 10) || 0 : 0;
  617. const maxHits = resp.getResponseHeader('X-Max-Hits');
  618. const queryMaxCount =
  619. typeof maxHits !== 'undefined' && maxHits ? parseInt(maxHits, 10) || 0 : 0;
  620. const pageLinks = resp.getResponseHeader('Link');
  621. this.fetchCounts(queryCount, fetchAllCounts);
  622. this.setState({
  623. error: null,
  624. issuesLoading: false,
  625. queryCount,
  626. queryMaxCount,
  627. pageLinks: pageLinks !== null ? pageLinks : '',
  628. });
  629. if (data.length === 0) {
  630. trackAnalytics('issue_search.empty', {
  631. organization: this.props.organization,
  632. search_type: 'issues',
  633. search_source: 'main_search',
  634. query,
  635. });
  636. }
  637. },
  638. error: err => {
  639. trackAnalytics('issue_search.failed', {
  640. organization: this.props.organization,
  641. search_type: 'issues',
  642. search_source: 'main_search',
  643. error: parseApiError(err),
  644. });
  645. this.setState({
  646. error: parseApiError(err),
  647. issuesLoading: false,
  648. });
  649. },
  650. complete: () => {
  651. this._lastRequest = null;
  652. this.resumePolling();
  653. if (!this.state.realtimeActive) {
  654. this.actionTaken = false;
  655. this.undo = false;
  656. }
  657. },
  658. });
  659. };
  660. resumePolling = () => {
  661. if (!this.state.pageLinks) {
  662. return;
  663. }
  664. // Only resume polling if we're on the first page of results
  665. const links = parseLinkHeader(this.state.pageLinks);
  666. if (links && !links.previous.results && this.state.realtimeActive) {
  667. this._poller.setEndpoint(links?.previous?.href);
  668. this._poller.enable();
  669. }
  670. };
  671. get groupListEndpoint(): string {
  672. const {organization} = this.props;
  673. return `/organizations/${organization.slug}/issues/`;
  674. }
  675. get groupCountsEndpoint(): string {
  676. const {organization} = this.props;
  677. return `/organizations/${organization.slug}/issues-count/`;
  678. }
  679. get groupStatsEndpoint(): string {
  680. const {organization} = this.props;
  681. return `/organizations/${organization.slug}/issues-stats/`;
  682. }
  683. onRealtimeChange = (realtime: boolean) => {
  684. Cookies.set('realtimeActive', realtime.toString());
  685. this.setState({realtimeActive: realtime});
  686. trackAnalytics('issues_stream.realtime_clicked', {
  687. organization: this.props.organization,
  688. enabled: realtime,
  689. });
  690. };
  691. onSelectStatsPeriod = (period: string) => {
  692. const {location} = this.props;
  693. if (period !== this.getGroupStatsPeriod()) {
  694. const cursor = location.query.cursor;
  695. const queryPageInt = parseInt(location.query.page, 10);
  696. const page = isNaN(queryPageInt) || !location.query.cursor ? 0 : queryPageInt;
  697. this.transitionTo({cursor, page, groupStatsPeriod: period});
  698. }
  699. };
  700. onRealtimePoll = (data: any, {queryCount}: {queryCount: number}) => {
  701. // Note: We do not update state with cursors from polling,
  702. // `CursorPoller` updates itself with new cursors
  703. GroupStore.addToFront(data);
  704. this.setState({queryCount});
  705. };
  706. listener = GroupStore.listen(() => this.onGroupChange(), undefined);
  707. onGroupChange() {
  708. const groupIds = GroupStore.getAllItems()
  709. .map(item => item.id)
  710. .slice(0, MAX_ISSUES_COUNT);
  711. if (!isEqual(groupIds, this.state.groupIds)) {
  712. this.setState({groupIds});
  713. }
  714. }
  715. trackTabViewed(groups: string[], data: Group[], numHits: number | null) {
  716. const {organization, location} = this.props;
  717. const page = location.query.page;
  718. const endpointParams = this.getEndpointParams();
  719. const tabQueriesWithCounts = getTabsWithCounts(organization);
  720. const currentTabQuery = tabQueriesWithCounts.includes(endpointParams.query as Query)
  721. ? endpointParams.query
  722. : null;
  723. const tab = getTabs(organization).find(
  724. ([tabQuery]) => currentTabQuery === tabQuery
  725. )?.[1];
  726. const numPerfIssues = groups.filter(
  727. group => GroupStore.get(group)?.issueCategory === IssueCategory.PERFORMANCE
  728. ).length;
  729. // First and last seen are only available after the group has fetched stats
  730. // Number of issues shown whose first seen is more than 30 days ago
  731. const numOldIssues = data.filter((group: BaseGroup) =>
  732. moment(new Date(group.firstSeen)).isBefore(moment().subtract(30, 'd'))
  733. ).length;
  734. // number of issues shown whose first seen is less than 7 days
  735. const numNewIssues = data.filter((group: BaseGroup) =>
  736. moment(new Date(group.firstSeen)).isAfter(moment().subtract(7, 'd'))
  737. ).length;
  738. trackAnalytics('issues_tab.viewed', {
  739. organization,
  740. tab: tab?.analyticsName,
  741. page: page ? parseInt(page, 10) : 0,
  742. query: this.getQuery(),
  743. num_perf_issues: numPerfIssues,
  744. num_old_issues: numOldIssues,
  745. num_new_issues: numNewIssues,
  746. num_issues: data.length,
  747. total_issues_count: numHits,
  748. sort: this.getSort(),
  749. });
  750. }
  751. onSearch = (query: string) => {
  752. if (query === this.state.query) {
  753. // if query is the same, just re-fetch data
  754. this.fetchData();
  755. } else {
  756. // Clear the saved search as the user wants something else.
  757. this.transitionTo({query}, null);
  758. }
  759. };
  760. onSortChange = (sort: string) => {
  761. trackAnalytics('issues_stream.sort_changed', {
  762. organization: this.props.organization,
  763. sort,
  764. });
  765. this.transitionTo({sort});
  766. };
  767. onCursorChange: CursorHandler = (nextCursor, _path, _query, delta) => {
  768. const queryPageInt = parseInt(this.props.location.query.page, 10);
  769. let nextPage: number | undefined = isNaN(queryPageInt) ? delta : queryPageInt + delta;
  770. let cursor: undefined | string = nextCursor;
  771. // unset cursor and page when we navigate back to the first page
  772. // also reset cursor if somehow the previous button is enabled on
  773. // first page and user attempts to go backwards
  774. if (nextPage <= 0) {
  775. cursor = undefined;
  776. nextPage = undefined;
  777. }
  778. this.transitionTo({cursor, page: nextPage});
  779. };
  780. paginationAnalyticsEvent = (direction: string) => {
  781. trackAnalytics('issues_stream.paginate', {
  782. organization: this.props.organization,
  783. direction,
  784. });
  785. };
  786. /**
  787. * Returns true if all results in the current query are visible/on this page
  788. */
  789. allResultsVisible(): boolean {
  790. if (!this.state.pageLinks) {
  791. return false;
  792. }
  793. const links = parseLinkHeader(this.state.pageLinks);
  794. return links && !links.previous.results && !links.next.results;
  795. }
  796. transitionTo = (
  797. newParams: Partial<EndpointParams> = {},
  798. savedSearch: (SavedSearch & {projectId?: number}) | null = this.props.savedSearch
  799. ) => {
  800. const query = {
  801. ...omit(this.props.location.query, ['page', 'cursor']),
  802. referrer: 'issue-list',
  803. ...this.getEndpointParams(),
  804. ...newParams,
  805. };
  806. const {organization} = this.props;
  807. let path: string;
  808. if (savedSearch?.id) {
  809. path = `/organizations/${organization.slug}/issues/searches/${savedSearch.id}/`;
  810. // Remove the query as saved searches bring their own query string.
  811. delete query.query;
  812. // If we aren't going to another page in the same search
  813. // drop the query and replace the current project, with the saved search search project
  814. // if available.
  815. if (!query.cursor && savedSearch.projectId) {
  816. query.project = [savedSearch.projectId];
  817. }
  818. if (!query.cursor && !newParams.sort && savedSearch.sort) {
  819. query.sort = savedSearch.sort;
  820. }
  821. } else {
  822. path = `/organizations/${organization.slug}/issues/`;
  823. }
  824. if (
  825. query.sort === IssueSortOptions.INBOX &&
  826. !FOR_REVIEW_QUERIES.includes(query.query || '')
  827. ) {
  828. delete query.sort;
  829. }
  830. if (
  831. path !== this.props.location.pathname ||
  832. !isEqual(query, this.props.location.query)
  833. ) {
  834. browserHistory.push({
  835. pathname: normalizeUrl(path),
  836. query,
  837. });
  838. this.setState({issuesLoading: true});
  839. }
  840. };
  841. displayReprocessingTab() {
  842. return !!this.state.queryCounts?.[Query.REPROCESSING]?.count;
  843. }
  844. displayReprocessingLayout(showReprocessingTab: boolean, query: string) {
  845. return showReprocessingTab && query === Query.REPROCESSING;
  846. }
  847. renderLoading(): React.ReactNode {
  848. return (
  849. <Layout.Page withPadding>
  850. <LoadingIndicator />
  851. </Layout.Page>
  852. );
  853. }
  854. onSavedSearchSelect = (savedSearch: SavedSearch) => {
  855. trackAnalytics('organization_saved_search.selected', {
  856. organization: this.props.organization,
  857. search_type: 'issues',
  858. id: savedSearch.id ? parseInt(savedSearch.id, 10) : -1,
  859. is_global: savedSearch.isGlobal,
  860. query: savedSearch.query,
  861. visibility: savedSearch.visibility,
  862. });
  863. this.setState({issuesLoading: true}, () => this.transitionTo(undefined, savedSearch));
  864. };
  865. onDelete = () => {
  866. this.actionTaken = true;
  867. this.fetchData(true);
  868. };
  869. undoAction = ({data, groups}: {data: IssueUpdateData; groups: BaseGroup[]}) => {
  870. const {organization, selection} = this.props;
  871. const query = this.getQuery();
  872. const projectIds = selection?.projects?.map(p => p.toString());
  873. const endpoint = `/organizations/${organization.slug}/issues/`;
  874. if (this._lastRequest) {
  875. this._lastRequest.cancel();
  876. }
  877. if (this._lastStatsRequest) {
  878. this._lastStatsRequest.cancel();
  879. }
  880. if (this._lastFetchCountsRequest) {
  881. this._lastFetchCountsRequest.cancel();
  882. }
  883. this.props.api.request(endpoint, {
  884. method: 'PUT',
  885. data,
  886. query: {
  887. project: projectIds,
  888. id: groups.map(group => group.id),
  889. },
  890. success: response => {
  891. if (!response) {
  892. return;
  893. }
  894. // If on the Ignore or For Review tab, adding back to the GroupStore will make the issue show up
  895. // on this page for a second and then be removed (will show up on All Unresolved). This is to
  896. // stop this from happening and avoid confusion.
  897. if (!query.includes('is:ignored') && !isForReviewQuery(query)) {
  898. GroupStore.add(groups);
  899. }
  900. this.undo = true;
  901. },
  902. error: err => {
  903. this.setState({
  904. error: parseApiError(err),
  905. issuesLoading: false,
  906. });
  907. },
  908. complete: () => {
  909. this.fetchData();
  910. },
  911. });
  912. };
  913. onActionTaken = (itemIds: string[], data: IssueUpdateData) => {
  914. if (this.state.realtimeActive) {
  915. return;
  916. }
  917. const query = this.getQuery();
  918. const groups = itemIds.map(id => GroupStore.get(id)).filter(defined);
  919. if ('status' in data) {
  920. if (data.status === 'resolved') {
  921. this.onIssueAction({
  922. itemIds,
  923. actionType: 'Resolved',
  924. shouldRemove:
  925. query.includes('is:unresolved') ||
  926. query.includes('is:ignored') ||
  927. isForReviewQuery(query),
  928. undo: () =>
  929. this.undoAction({
  930. data: {status: GroupStatus.UNRESOLVED, statusDetails: {}},
  931. groups,
  932. }),
  933. });
  934. return;
  935. }
  936. if (data.status === 'ignored') {
  937. this.onIssueAction({
  938. itemIds,
  939. actionType: 'Archived',
  940. shouldRemove: query.includes('is:unresolved') || isForReviewQuery(query),
  941. undo: () =>
  942. this.undoAction({
  943. data: {status: GroupStatus.UNRESOLVED, statusDetails: {}},
  944. groups,
  945. }),
  946. });
  947. return;
  948. }
  949. }
  950. if ('inbox' in data && data.inbox === false) {
  951. this.onIssueAction({
  952. itemIds,
  953. actionType: 'Reviewed',
  954. shouldRemove: isForReviewQuery(query),
  955. });
  956. return;
  957. }
  958. if ('priority' in data && typeof data.priority === 'string') {
  959. const priorityValues = parseIssuePrioritySearch(query);
  960. const priority = data.priority.toLowerCase() as PriorityLevel;
  961. this.onIssueAction({
  962. itemIds,
  963. actionType: 'Reprioritized',
  964. shouldRemove: !priorityValues.has(priority),
  965. });
  966. return;
  967. }
  968. };
  969. onIssueAction = ({
  970. itemIds,
  971. actionType,
  972. shouldRemove,
  973. undo,
  974. }: {
  975. actionType: 'Reviewed' | 'Resolved' | 'Ignored' | 'Archived' | 'Reprioritized';
  976. itemIds: string[];
  977. shouldRemove: boolean;
  978. undo?: () => void;
  979. }) => {
  980. if (itemIds.length > 1) {
  981. addMessage(`${actionType} ${itemIds.length} ${t('Issues')}`, 'success', {
  982. duration: 4000,
  983. undo,
  984. });
  985. } else {
  986. const shortId = itemIds.map(item => GroupStore.get(item)?.shortId).toString();
  987. addMessage(`${actionType} ${shortId}`, 'success', {
  988. duration: 4000,
  989. undo,
  990. });
  991. }
  992. if (!shouldRemove) {
  993. return;
  994. }
  995. const links = parseLinkHeader(this.state.pageLinks);
  996. GroupStore.remove(itemIds);
  997. const queryCount = this.state.queryCount - itemIds.length;
  998. this.actionTaken = true;
  999. this.setState({queryCount});
  1000. if (GroupStore.getAllItemIds().length === 0) {
  1001. // If we run out of issues on the last page, navigate back a page to
  1002. // avoid showing an empty state - if not on the last page, just show a spinner
  1003. const shouldGoBackAPage = links?.previous?.results && !links?.next?.results;
  1004. this.transitionTo({cursor: shouldGoBackAPage ? links.previous.cursor : undefined});
  1005. this.fetchCounts(queryCount, true);
  1006. } else {
  1007. this.fetchData(true);
  1008. }
  1009. };
  1010. tagValueLoader = (key: string, search: string) => {
  1011. const {organization} = this.props;
  1012. const projectIds = this.getSelectedProjectIds();
  1013. const endpointParams = this.getEndpointParams();
  1014. return fetchTagValues({
  1015. api: this.props.api,
  1016. orgSlug: organization.slug,
  1017. tagKey: key,
  1018. search,
  1019. projectIds,
  1020. endpointParams: endpointParams as any,
  1021. });
  1022. };
  1023. getPageCounts = () => {
  1024. const {location} = this.props;
  1025. const {pageLinks, queryCount, groupIds} = this.state;
  1026. const links = parseLinkHeader(pageLinks);
  1027. const queryPageInt = parseInt(location.query.page, 10);
  1028. // Cursor must be present for the page number to be used
  1029. const page = isNaN(queryPageInt) || !location.query.cursor ? 0 : queryPageInt;
  1030. let numPreviousIssues = Math.min(page * MAX_ITEMS, queryCount);
  1031. // Because the query param `page` is not tied to the request, we need to
  1032. // validate that it's correct at the first and last page
  1033. if (!links?.next?.results || this.allResultsVisible()) {
  1034. // On last available page
  1035. numPreviousIssues = Math.max(queryCount - groupIds.length, 0);
  1036. } else if (!links?.previous?.results) {
  1037. // On first available page
  1038. numPreviousIssues = 0;
  1039. }
  1040. return {
  1041. numPreviousIssues,
  1042. numIssuesOnPage: groupIds.length,
  1043. };
  1044. };
  1045. render() {
  1046. if (
  1047. this.props.savedSearchLoading &&
  1048. !this.props.organization.features.includes('issue-stream-performance')
  1049. ) {
  1050. return this.renderLoading();
  1051. }
  1052. const {
  1053. pageLinks,
  1054. queryCount,
  1055. queryCounts,
  1056. realtimeActive,
  1057. groupIds,
  1058. queryMaxCount,
  1059. issuesLoading,
  1060. error,
  1061. } = this.state;
  1062. const {organization, selection, router} = this.props;
  1063. const query = this.getQuery();
  1064. const modifiedQueryCount = Math.max(queryCount, 0);
  1065. const projectIds = selection?.projects?.map(p => p.toString());
  1066. const showReprocessingTab = this.displayReprocessingTab();
  1067. const displayReprocessingActions = this.displayReprocessingLayout(
  1068. showReprocessingTab,
  1069. query
  1070. );
  1071. const {numPreviousIssues, numIssuesOnPage} = this.getPageCounts();
  1072. return (
  1073. <Layout.Page>
  1074. <IssueListHeader
  1075. organization={organization}
  1076. query={query}
  1077. sort={this.getSort()}
  1078. queryCount={queryCount}
  1079. queryCounts={queryCounts}
  1080. realtimeActive={realtimeActive}
  1081. onRealtimeChange={this.onRealtimeChange}
  1082. router={router}
  1083. displayReprocessingTab={showReprocessingTab}
  1084. selectedProjectIds={selection.projects}
  1085. />
  1086. <StyledBody>
  1087. <StyledMain>
  1088. <DataConsentBanner source="issues" />
  1089. <IssueListFilters query={query} onSearch={this.onSearch} />
  1090. <Panel>
  1091. {groupIds.length !== 0 && (
  1092. <IssueListActions
  1093. selection={selection}
  1094. query={query}
  1095. queryCount={modifiedQueryCount}
  1096. onSelectStatsPeriod={this.onSelectStatsPeriod}
  1097. onActionTaken={this.onActionTaken}
  1098. onDelete={this.onDelete}
  1099. statsPeriod={this.getGroupStatsPeriod()}
  1100. groupIds={groupIds}
  1101. allResultsVisible={this.allResultsVisible()}
  1102. displayReprocessingActions={displayReprocessingActions}
  1103. sort={this.getSort()}
  1104. onSortChange={this.onSortChange}
  1105. />
  1106. )}
  1107. <PanelBody>
  1108. <ProcessingIssueList
  1109. organization={organization}
  1110. projectIds={projectIds}
  1111. showProject
  1112. />
  1113. <VisuallyCompleteWithData
  1114. hasData={this.state.groupIds.length > 0}
  1115. id="IssueList-Body"
  1116. isLoading={this.state.issuesLoading}
  1117. >
  1118. <GroupListBody
  1119. memberList={this.state.memberList}
  1120. groupStatsPeriod={this.getGroupStatsPeriod()}
  1121. groupIds={groupIds}
  1122. displayReprocessingLayout={displayReprocessingActions}
  1123. query={query}
  1124. selectedProjectIds={selection.projects}
  1125. loading={issuesLoading}
  1126. error={error}
  1127. refetchGroups={this.fetchData}
  1128. onActionTaken={this.onActionTaken}
  1129. />
  1130. </VisuallyCompleteWithData>
  1131. </PanelBody>
  1132. </Panel>
  1133. <StyledPagination
  1134. caption={
  1135. !issuesLoading && modifiedQueryCount > 0
  1136. ? tct('[start]-[end] of [total]', {
  1137. start: numPreviousIssues + 1,
  1138. end: numPreviousIssues + numIssuesOnPage,
  1139. total: (
  1140. <StyledQueryCount
  1141. hideParens
  1142. hideIfEmpty={false}
  1143. count={modifiedQueryCount}
  1144. max={queryMaxCount || 100}
  1145. />
  1146. ),
  1147. })
  1148. : null
  1149. }
  1150. pageLinks={pageLinks}
  1151. onCursor={this.onCursorChange}
  1152. paginationAnalyticsEvent={this.paginationAnalyticsEvent}
  1153. />
  1154. </StyledMain>
  1155. <SavedIssueSearches
  1156. {...{organization, query}}
  1157. onSavedSearchSelect={this.onSavedSearchSelect}
  1158. sort={this.getSort()}
  1159. />
  1160. </StyledBody>
  1161. </Layout.Page>
  1162. );
  1163. }
  1164. }
  1165. export default withRouteAnalytics(
  1166. withApi(
  1167. withPageFilters(
  1168. withSavedSearches(
  1169. withOrganization(withIssueTags(Sentry.withProfiler(IssueListOverview)))
  1170. )
  1171. )
  1172. )
  1173. );
  1174. export {IssueListOverview};
  1175. const StyledBody = styled('div')`
  1176. background-color: ${p => p.theme.background};
  1177. flex: 1;
  1178. display: grid;
  1179. gap: 0;
  1180. padding: 0;
  1181. grid-template-rows: 1fr;
  1182. grid-template-columns: minmax(0, 1fr) auto;
  1183. grid-template-areas: 'content saved-searches';
  1184. `;
  1185. const StyledMain = styled('section')`
  1186. grid-area: content;
  1187. padding: ${space(2)};
  1188. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  1189. padding: ${space(3)} ${space(4)};
  1190. }
  1191. `;
  1192. const StyledPagination = styled(Pagination)`
  1193. margin-top: 0;
  1194. `;
  1195. const StyledQueryCount = styled(QueryCount)`
  1196. margin-left: 0;
  1197. `;