index.tsx 5.1 KB

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