groupUserFeedback.tsx 3.2 KB

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