index.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import {Component} from 'react';
  2. import {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 GroupingStore, {Fingerprint} from 'sentry/stores/groupingStore';
  11. import {space} from 'sentry/styles/space';
  12. import {Group, Organization, Project} from 'sentry/types';
  13. import {trackAnalytics} from 'sentry/utils/analytics';
  14. import withOrganization from 'sentry/utils/withOrganization';
  15. import MergedList from './mergedList';
  16. type Props = RouteComponentProps<
  17. {groupId: Group['id']; orgId: Organization['slug']},
  18. {}
  19. > & {
  20. organization: Organization;
  21. project: Project;
  22. };
  23. type State = {
  24. error: boolean;
  25. loading: boolean;
  26. mergedItems: Array<Fingerprint>;
  27. query: string;
  28. mergedLinks?: string;
  29. };
  30. class GroupMergedView extends Component<Props, State> {
  31. state: State = {
  32. mergedItems: [],
  33. loading: true,
  34. error: false,
  35. query: this.props.location.query.query || '',
  36. };
  37. componentDidMount() {
  38. this.fetchData();
  39. }
  40. UNSAFE_componentWillReceiveProps(nextProps: Props) {
  41. if (
  42. nextProps.params.groupId !== this.props.params.groupId ||
  43. nextProps.location.search !== this.props.location.search
  44. ) {
  45. const queryParams = nextProps.location.query;
  46. this.setState(
  47. {
  48. query: queryParams.query,
  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 {params, location} = this.props;
  70. const {groupId} = params;
  71. const queryParams = {
  72. ...location.query,
  73. limit: 50,
  74. query: this.state.query,
  75. };
  76. return `/issues/${groupId}/hashes/?${qs.stringify(queryParams)}`;
  77. }
  78. fetchData = () => {
  79. GroupingStore.onFetch([
  80. {
  81. endpoint: this.getEndpoint(),
  82. dataKey: 'merged',
  83. queryParams: this.props.location.query,
  84. },
  85. ]);
  86. };
  87. handleUnmerge = () => {
  88. GroupingStore.onUnmerge({
  89. groupId: this.props.params.groupId,
  90. loadingMessage: t('Unmerging events\u2026'),
  91. successMessage: t('Events successfully queued for unmerging.'),
  92. errorMessage: t('Unable to queue events for unmerging.'),
  93. });
  94. const unmergeKeys = [...GroupingStore.getState().unmergeList.values()];
  95. trackAnalytics('issue_details.merged_tab.unmerge_clicked', {
  96. organization: this.props.organization,
  97. group_id: this.props.params.groupId,
  98. event_ids_unmerged: unmergeKeys.join(','),
  99. total_unmerged: unmergeKeys.length,
  100. });
  101. };
  102. render() {
  103. const {project, organization, params} = this.props;
  104. const {groupId} = params;
  105. const {loading: isLoading, error, mergedItems, mergedLinks} = this.state;
  106. const isError = error && !isLoading;
  107. const isLoadedSuccessfully = !isError && !isLoading;
  108. const fingerprintsWithLatestEvent = mergedItems.filter(
  109. ({latestEvent}) => !!latestEvent
  110. );
  111. return (
  112. <Layout.Body>
  113. <Layout.Main fullWidth>
  114. <HeaderWrapper>
  115. <Title>
  116. {tct('Merged fingerprints with latest event [count]', {
  117. count: <QueryCount count={fingerprintsWithLatestEvent.length} />,
  118. })}
  119. </Title>
  120. <small>
  121. {t(
  122. 'This is an experimental feature. Data may not be immediately available while we process unmerges.'
  123. )}
  124. </small>
  125. </HeaderWrapper>
  126. {isLoading && <LoadingIndicator />}
  127. {isError && (
  128. <LoadingError
  129. message={t('Unable to load merged events, please try again later')}
  130. onRetry={this.fetchData}
  131. />
  132. )}
  133. {isLoadedSuccessfully && (
  134. <MergedList
  135. project={project}
  136. organization={organization}
  137. fingerprints={mergedItems}
  138. pageLinks={mergedLinks}
  139. groupId={groupId}
  140. onUnmerge={this.handleUnmerge}
  141. onToggleCollapse={GroupingStore.onToggleCollapseFingerprints}
  142. />
  143. )}
  144. </Layout.Main>
  145. </Layout.Body>
  146. );
  147. }
  148. }
  149. export {GroupMergedView};
  150. export default withOrganization(GroupMergedView);
  151. const Title = styled('h4')`
  152. margin-bottom: ${space(0.75)};
  153. `;
  154. const HeaderWrapper = styled('div')`
  155. margin-bottom: ${space(2)};
  156. small {
  157. color: ${p => p.theme.subText};
  158. }
  159. `;