index.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {Component} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import * as qs from 'query-string';
  4. import {Alert} from 'sentry/components/alert';
  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 {t} from 'sentry/locale';
  9. import GroupingStore, {Fingerprint} from 'sentry/stores/groupingStore';
  10. import {Group, Organization, Project} from 'sentry/types';
  11. import {trackAnalytics} from 'sentry/utils/analytics';
  12. import withOrganization from 'sentry/utils/withOrganization';
  13. import MergedList from './mergedList';
  14. type Props = RouteComponentProps<
  15. {groupId: Group['id']; orgId: Organization['slug']},
  16. {}
  17. > & {
  18. organization: Organization;
  19. project: Project;
  20. };
  21. type State = {
  22. error: boolean;
  23. loading: boolean;
  24. mergedItems: Array<Fingerprint>;
  25. query: string;
  26. mergedLinks?: string;
  27. };
  28. class GroupMergedView extends Component<Props, State> {
  29. state: State = {
  30. mergedItems: [],
  31. loading: true,
  32. error: false,
  33. query: this.props.location.query.query || '',
  34. };
  35. componentDidMount() {
  36. this.fetchData();
  37. }
  38. UNSAFE_componentWillReceiveProps(nextProps: Props) {
  39. if (
  40. nextProps.params.groupId !== this.props.params.groupId ||
  41. nextProps.location.search !== this.props.location.search
  42. ) {
  43. const queryParams = nextProps.location.query;
  44. this.setState(
  45. {
  46. query: queryParams.query,
  47. },
  48. this.fetchData
  49. );
  50. }
  51. }
  52. componentWillUnmount() {
  53. this.listener?.();
  54. }
  55. onGroupingChange = ({mergedItems, mergedLinks, loading, error}) => {
  56. if (mergedItems) {
  57. this.setState({
  58. mergedItems,
  59. mergedLinks,
  60. loading: typeof loading !== 'undefined' ? loading : false,
  61. error: typeof error !== 'undefined' ? error : false,
  62. });
  63. }
  64. };
  65. listener = GroupingStore.listen(this.onGroupingChange, undefined);
  66. getEndpoint() {
  67. const {params, location} = this.props;
  68. const {groupId} = params;
  69. const queryParams = {
  70. ...location.query,
  71. limit: 50,
  72. query: this.state.query,
  73. };
  74. return `/issues/${groupId}/hashes/?${qs.stringify(queryParams)}`;
  75. }
  76. fetchData = () => {
  77. GroupingStore.onFetch([
  78. {
  79. endpoint: this.getEndpoint(),
  80. dataKey: 'merged',
  81. queryParams: this.props.location.query,
  82. },
  83. ]);
  84. };
  85. handleUnmerge = () => {
  86. GroupingStore.onUnmerge({
  87. groupId: this.props.params.groupId,
  88. loadingMessage: t('Unmerging events\u2026'),
  89. successMessage: t('Events successfully queued for unmerging.'),
  90. errorMessage: t('Unable to queue events for unmerging.'),
  91. });
  92. const unmergeKeys = [...GroupingStore.getState().unmergeList.values()];
  93. trackAnalytics('issue_details.merged_tab.unmerge_clicked', {
  94. organization: this.props.organization,
  95. group_id: this.props.params.groupId,
  96. event_ids_unmerged: unmergeKeys.join(','),
  97. total_unmerged: unmergeKeys.length,
  98. });
  99. };
  100. render() {
  101. const {project, params} = this.props;
  102. const {groupId} = params;
  103. const {loading: isLoading, error, mergedItems, mergedLinks} = this.state;
  104. const isError = error && !isLoading;
  105. const isLoadedSuccessfully = !isError && !isLoading;
  106. return (
  107. <Layout.Body>
  108. <Layout.Main fullWidth>
  109. <Alert type="warning">
  110. {t(
  111. 'This is an experimental feature. Data may not be immediately available while we process unmerges.'
  112. )}
  113. </Alert>
  114. {isLoading && <LoadingIndicator />}
  115. {isError && (
  116. <LoadingError
  117. message={t('Unable to load merged events, please try again later')}
  118. onRetry={this.fetchData}
  119. />
  120. )}
  121. {isLoadedSuccessfully && (
  122. <MergedList
  123. project={project}
  124. fingerprints={mergedItems}
  125. pageLinks={mergedLinks}
  126. groupId={groupId}
  127. onUnmerge={this.handleUnmerge}
  128. onToggleCollapse={GroupingStore.onToggleCollapseFingerprints}
  129. />
  130. )}
  131. </Layout.Main>
  132. </Layout.Body>
  133. );
  134. }
  135. }
  136. export {GroupMergedView};
  137. export default withOrganization(GroupMergedView);