index.tsx 3.9 KB

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