index.tsx 5.3 KB

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