groupUserFeedback.tsx 3.3 KB

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