processingIssueList.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {Component, Fragment} from 'react';
  2. import isEqual from 'lodash/isEqual';
  3. import {fetchProcessingIssues} from 'sentry/actionCreators/processingIssues';
  4. import {Client} from 'sentry/api';
  5. import ProcessingIssueHint from 'sentry/components/stream/processingIssueHint';
  6. import {Organization, ProcessingIssue} from 'sentry/types';
  7. const defaultProps = {
  8. showProject: false,
  9. };
  10. type Props = {
  11. organization: Organization;
  12. projectIds: string[];
  13. } & typeof defaultProps;
  14. type State = {
  15. issues: ProcessingIssue[];
  16. loading: boolean;
  17. };
  18. class ProcessingIssueList extends Component<Props, State> {
  19. static defaultProps = defaultProps;
  20. state: State = {
  21. loading: true,
  22. issues: [],
  23. };
  24. componentDidMount() {
  25. this.fetchIssues();
  26. }
  27. componentDidUpdate(prevProps: Props) {
  28. if (!isEqual(prevProps.projectIds, this.props.projectIds)) {
  29. this.fetchIssues();
  30. }
  31. }
  32. componentWillUnmount() {
  33. this.api.clear();
  34. }
  35. api = new Client();
  36. fetchIssues() {
  37. const {organization, projectIds} = this.props;
  38. const promise = fetchProcessingIssues(this.api, organization.slug, projectIds);
  39. promise.then(
  40. (data?: ProcessingIssue[]) => {
  41. const hasIssues = data?.some(
  42. p => p.hasIssues || p.resolveableIssues > 0 || p.issuesProcessing > 0
  43. );
  44. if (data && hasIssues) {
  45. this.setState({issues: data});
  46. }
  47. },
  48. () => {
  49. // this is okay. it's just a ui hint
  50. }
  51. );
  52. }
  53. render() {
  54. const {issues} = this.state;
  55. const {organization, showProject} = this.props;
  56. return (
  57. <Fragment>
  58. {issues.map((p, idx) => (
  59. <ProcessingIssueHint
  60. key={idx}
  61. issue={p}
  62. projectId={p.project}
  63. orgId={organization.slug}
  64. showProject={showProject}
  65. />
  66. ))}
  67. </Fragment>
  68. );
  69. }
  70. }
  71. export default ProcessingIssueList;