index.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import {Component} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import * as qs from 'query-string';
  5. import * as Layout from 'sentry/components/layouts/thirds';
  6. import LoadingError from 'sentry/components/loadingError';
  7. import LoadingIndicator from 'sentry/components/loadingIndicator';
  8. import QueryCount from 'sentry/components/queryCount';
  9. import {t, tct} from 'sentry/locale';
  10. import type {Fingerprint} from 'sentry/stores/groupingStore';
  11. import GroupingStore from 'sentry/stores/groupingStore';
  12. import {space} from 'sentry/styles/space';
  13. import type {Group} from 'sentry/types/group';
  14. import type {Organization} from 'sentry/types/organization';
  15. import type {Project} from 'sentry/types/project';
  16. import {trackAnalytics} from 'sentry/utils/analytics';
  17. import withOrganization from 'sentry/utils/withOrganization';
  18. import MergedList from './mergedList';
  19. type Props = RouteComponentProps<
  20. {groupId: Group['id']; orgId: Organization['slug']},
  21. {}
  22. > & {
  23. organization: Organization;
  24. project: Project;
  25. };
  26. type State = {
  27. error: boolean;
  28. loading: boolean;
  29. mergedItems: Array<Fingerprint>;
  30. query: string;
  31. mergedLinks?: string;
  32. };
  33. class GroupMergedView extends Component<Props, State> {
  34. state: State = {
  35. mergedItems: [],
  36. loading: true,
  37. error: false,
  38. query: this.props.location.query.query || '',
  39. };
  40. componentDidMount() {
  41. this.fetchData();
  42. }
  43. UNSAFE_componentWillReceiveProps(nextProps: Props) {
  44. if (
  45. nextProps.params.groupId !== this.props.params.groupId ||
  46. nextProps.location.search !== this.props.location.search
  47. ) {
  48. const queryParams = nextProps.location.query;
  49. this.setState(
  50. {
  51. query: queryParams.query,
  52. },
  53. this.fetchData
  54. );
  55. }
  56. }
  57. componentWillUnmount() {
  58. this.listener?.();
  59. }
  60. onGroupingChange = ({mergedItems, mergedLinks, loading, error}) => {
  61. if (mergedItems) {
  62. this.setState({
  63. mergedItems,
  64. mergedLinks,
  65. loading: typeof loading !== 'undefined' ? loading : false,
  66. error: typeof error !== 'undefined' ? error : false,
  67. });
  68. }
  69. };
  70. listener = GroupingStore.listen(this.onGroupingChange, undefined);
  71. getEndpoint() {
  72. const {params, location, organization} = this.props;
  73. const {groupId} = params;
  74. const queryParams = {
  75. ...location.query,
  76. limit: 50,
  77. query: this.state.query,
  78. };
  79. return `/organizations/${organization.slug}/issues/${groupId}/hashes/?${qs.stringify(
  80. queryParams
  81. )}`;
  82. }
  83. fetchData = () => {
  84. GroupingStore.onFetch([
  85. {
  86. endpoint: this.getEndpoint(),
  87. dataKey: 'merged',
  88. queryParams: this.props.location.query,
  89. },
  90. ]);
  91. };
  92. handleUnmerge = () => {
  93. const {organization, params} = this.props;
  94. GroupingStore.onUnmerge({
  95. groupId: params.groupId,
  96. orgSlug: organization.slug,
  97. loadingMessage: t('Unmerging events\u2026'),
  98. successMessage: t('Events successfully queued for unmerging.'),
  99. errorMessage: t('Unable to queue events for unmerging.'),
  100. });
  101. const unmergeKeys = [...GroupingStore.getState().unmergeList.values()];
  102. trackAnalytics('issue_details.merged_tab.unmerge_clicked', {
  103. organization,
  104. group_id: params.groupId,
  105. event_ids_unmerged: unmergeKeys.join(','),
  106. total_unmerged: unmergeKeys.length,
  107. });
  108. };
  109. render() {
  110. const {project, organization, params} = this.props;
  111. const {groupId} = params;
  112. const {loading: isLoading, error, mergedItems, mergedLinks} = this.state;
  113. const isError = error && !isLoading;
  114. const isLoadedSuccessfully = !isError && !isLoading;
  115. const fingerprintsWithLatestEvent = mergedItems.filter(
  116. ({latestEvent}) => !!latestEvent
  117. );
  118. return (
  119. <Layout.Body>
  120. <Layout.Main fullWidth>
  121. <HeaderWrapper>
  122. <Title>
  123. {tct('Fingerprints included in this issue [count]', {
  124. count: <QueryCount count={fingerprintsWithLatestEvent.length} />,
  125. })}
  126. </Title>
  127. <small>
  128. {
  129. // TODO: Once clickhouse is upgraded and the lag is no longer an issue, revisit this wording.
  130. // See https://github.com/getsentry/sentry/issues/56334.
  131. t(
  132. 'This is an experimental feature. All changes may take up to 24 hours take effect.'
  133. )
  134. }
  135. </small>
  136. </HeaderWrapper>
  137. {isLoading && <LoadingIndicator />}
  138. {isError && (
  139. <LoadingError
  140. message={t('Unable to load merged events, please try again later')}
  141. onRetry={this.fetchData}
  142. />
  143. )}
  144. {isLoadedSuccessfully && (
  145. <MergedList
  146. project={project}
  147. organization={organization}
  148. fingerprints={mergedItems}
  149. pageLinks={mergedLinks}
  150. groupId={groupId}
  151. onUnmerge={this.handleUnmerge}
  152. onToggleCollapse={GroupingStore.onToggleCollapseFingerprints}
  153. />
  154. )}
  155. </Layout.Main>
  156. </Layout.Body>
  157. );
  158. }
  159. }
  160. export {GroupMergedView};
  161. export default withOrganization(GroupMergedView);
  162. const Title = styled('h4')`
  163. margin-bottom: ${space(0.75)};
  164. `;
  165. const HeaderWrapper = styled('div')`
  166. margin-bottom: ${space(2)};
  167. small {
  168. color: ${p => p.theme.subText};
  169. }
  170. `;