groupUserFeedback.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {Component} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import isEqual from 'lodash/isEqual';
  4. import EventUserFeedback from 'sentry/components/events/userFeedback';
  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 Pagination from 'sentry/components/pagination';
  9. import {Group, Organization, Project, UserReport} from 'sentry/types';
  10. import withOrganization from 'sentry/utils/withOrganization';
  11. import {UserFeedbackEmpty} from 'sentry/views/userFeedback/userFeedbackEmpty';
  12. import {fetchGroupUserReports} from './utils';
  13. type RouteParams = {
  14. groupId: string;
  15. orgId: string;
  16. };
  17. type Props = RouteComponentProps<RouteParams, {}> & {
  18. environments: string[];
  19. group: Group;
  20. organization: Organization;
  21. project: Project;
  22. };
  23. type State = {
  24. error: boolean;
  25. loading: boolean;
  26. reportList: UserReport[];
  27. pageLinks?: string | null;
  28. };
  29. class GroupUserFeedback extends Component<Props, State> {
  30. state: State = {
  31. loading: true,
  32. error: false,
  33. reportList: [],
  34. pageLinks: '',
  35. };
  36. componentDidMount() {
  37. this.fetchData();
  38. }
  39. componentDidUpdate(prevProps: Props) {
  40. if (
  41. !isEqual(prevProps.params, this.props.params) ||
  42. prevProps.location.pathname !== this.props.location.pathname ||
  43. prevProps.location.search !== this.props.location.search
  44. ) {
  45. this.fetchData();
  46. }
  47. }
  48. fetchData = () => {
  49. this.setState({
  50. loading: true,
  51. error: false,
  52. });
  53. fetchGroupUserReports(this.props.group.id, {
  54. ...this.props.params,
  55. cursor: this.props.location.query.cursor || '',
  56. })
  57. .then(([data, _, resp]) => {
  58. this.setState({
  59. error: false,
  60. loading: false,
  61. reportList: data,
  62. pageLinks: resp?.getResponseHeader('Link'),
  63. });
  64. })
  65. .catch(() => {
  66. this.setState({
  67. error: true,
  68. loading: false,
  69. });
  70. });
  71. };
  72. render() {
  73. const {reportList, loading, error} = this.state;
  74. const {organization, group} = this.props;
  75. if (loading) {
  76. return <LoadingIndicator />;
  77. }
  78. if (error) {
  79. return <LoadingError onRetry={this.fetchData} />;
  80. }
  81. if (reportList.length) {
  82. return (
  83. <Layout.Body>
  84. <Layout.Main>
  85. {reportList.map((item, idx) => (
  86. <EventUserFeedback
  87. key={idx}
  88. report={item}
  89. orgId={organization.slug}
  90. issueId={group.id}
  91. />
  92. ))}
  93. <Pagination pageLinks={this.state.pageLinks} {...this.props} />
  94. </Layout.Main>
  95. </Layout.Body>
  96. );
  97. }
  98. return (
  99. <Layout.Body>
  100. <Layout.Main fullWidth>
  101. <UserFeedbackEmpty projectIds={[group.project.id]} />
  102. </Layout.Main>
  103. </Layout.Body>
  104. );
  105. }
  106. }
  107. export default withOrganization(GroupUserFeedback);