index.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as qs from 'query-string';
  4. import LoadingError from 'sentry/components/loadingError';
  5. import LoadingIndicator from 'sentry/components/loadingIndicator';
  6. import QueryCount from 'sentry/components/queryCount';
  7. import {t, tct} from 'sentry/locale';
  8. import type {Fingerprint} from 'sentry/stores/groupingStore';
  9. import GroupingStore from 'sentry/stores/groupingStore';
  10. import {space} from 'sentry/styles/space';
  11. import type {Group} from 'sentry/types/group';
  12. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  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 = Pick<
  19. RouteComponentProps<{groupId: Group['id']}, {}>,
  20. 'params' | 'location'
  21. > & {
  22. organization: Organization;
  23. project: Project;
  24. };
  25. type State = {
  26. error: boolean;
  27. loading: boolean;
  28. mergedItems: Array<Fingerprint>;
  29. query: string;
  30. mergedLinks?: string;
  31. };
  32. class GroupMergedView extends Component<Props, State> {
  33. state: State = {
  34. mergedItems: [],
  35. loading: true,
  36. error: false,
  37. query: this.props.location.query.query || '',
  38. };
  39. componentDidMount() {
  40. this.fetchData();
  41. }
  42. UNSAFE_componentWillReceiveProps(nextProps: Props) {
  43. if (
  44. nextProps.params.groupId !== this.props.params.groupId ||
  45. nextProps.location.search !== this.props.location.search
  46. ) {
  47. const queryParams = nextProps.location.query;
  48. this.setState(
  49. {
  50. query: queryParams.query,
  51. },
  52. this.fetchData
  53. );
  54. }
  55. }
  56. componentWillUnmount() {
  57. this.listener?.();
  58. }
  59. onGroupingChange = ({mergedItems, mergedLinks, loading, error}) => {
  60. if (mergedItems) {
  61. this.setState({
  62. mergedItems,
  63. mergedLinks,
  64. loading: typeof loading !== 'undefined' ? loading : false,
  65. error: typeof error !== 'undefined' ? error : false,
  66. });
  67. }
  68. };
  69. listener = GroupingStore.listen(this.onGroupingChange, undefined);
  70. getEndpoint() {
  71. const {params, location, organization} = this.props;
  72. const {groupId} = params;
  73. const queryParams = {
  74. ...location.query,
  75. limit: 50,
  76. query: this.state.query,
  77. };
  78. return `/organizations/${organization.slug}/issues/${groupId}/hashes/?${qs.stringify(
  79. queryParams
  80. )}`;
  81. }
  82. fetchData = () => {
  83. GroupingStore.onFetch([
  84. {
  85. endpoint: this.getEndpoint(),
  86. dataKey: 'merged',
  87. queryParams: this.props.location.query,
  88. },
  89. ]);
  90. };
  91. handleUnmerge = () => {
  92. const {organization, params} = this.props;
  93. GroupingStore.onUnmerge({
  94. groupId: params.groupId,
  95. orgSlug: organization.slug,
  96. loadingMessage: t('Unmerging events\u2026'),
  97. successMessage: t('Events successfully queued for unmerging.'),
  98. errorMessage: t('Unable to queue events for unmerging.'),
  99. });
  100. const unmergeKeys = [...GroupingStore.getState().unmergeList.values()];
  101. trackAnalytics('issue_details.merged_tab.unmerge_clicked', {
  102. organization,
  103. group_id: params.groupId,
  104. event_ids_unmerged: unmergeKeys.join(','),
  105. total_unmerged: unmergeKeys.length,
  106. });
  107. };
  108. render() {
  109. const {project, organization, params} = this.props;
  110. const {groupId} = params;
  111. const {loading: isLoading, error, mergedItems, mergedLinks} = this.state;
  112. const isError = error && !isLoading;
  113. const isLoadedSuccessfully = !isError && !isLoading;
  114. const fingerprintsWithLatestEvent = mergedItems.filter(
  115. ({latestEvent}) => !!latestEvent
  116. );
  117. return (
  118. <Fragment>
  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. </Fragment>
  154. );
  155. }
  156. }
  157. export default withOrganization(GroupMergedView);
  158. const Title = styled('h4')`
  159. font-size: ${p => p.theme.fontSizeLarge};
  160. margin-bottom: ${space(0.75)};
  161. `;
  162. const HeaderWrapper = styled('div')`
  163. margin-bottom: ${space(2)};
  164. small {
  165. color: ${p => p.theme.subText};
  166. }
  167. `;