123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import {Component} from 'react';
- import {RouteComponentProps} from 'react-router';
- import isEqual from 'lodash/isEqual';
- import EventUserFeedback from 'sentry/components/events/userFeedback';
- import * as Layout from 'sentry/components/layouts/thirds';
- import LoadingError from 'sentry/components/loadingError';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import Pagination from 'sentry/components/pagination';
- import {Group, Organization, Project, UserReport} from 'sentry/types';
- import withOrganization from 'sentry/utils/withOrganization';
- import {UserFeedbackEmpty} from 'sentry/views/userFeedback/userFeedbackEmpty';
- import {fetchGroupUserReports} from './utils';
- type RouteParams = {
- groupId: string;
- orgId: string;
- };
- type Props = RouteComponentProps<RouteParams, {}> & {
- environments: string[];
- group: Group;
- organization: Organization;
- project: Project;
- };
- type State = {
- error: boolean;
- loading: boolean;
- reportList: UserReport[];
- pageLinks?: string | null;
- };
- class GroupUserFeedback extends Component<Props, State> {
- state: State = {
- loading: true,
- error: false,
- reportList: [],
- pageLinks: '',
- };
- componentDidMount() {
- this.fetchData();
- }
- componentDidUpdate(prevProps: Props) {
- if (
- !isEqual(prevProps.params, this.props.params) ||
- prevProps.location.pathname !== this.props.location.pathname ||
- prevProps.location.search !== this.props.location.search
- ) {
- this.fetchData();
- }
- }
- fetchData = () => {
- this.setState({
- loading: true,
- error: false,
- });
- fetchGroupUserReports(this.props.group.id, {
- ...this.props.params,
- cursor: this.props.location.query.cursor || '',
- })
- .then(([data, _, resp]) => {
- this.setState({
- error: false,
- loading: false,
- reportList: data,
- pageLinks: resp?.getResponseHeader('Link'),
- });
- })
- .catch(() => {
- this.setState({
- error: true,
- loading: false,
- });
- });
- };
- render() {
- const {reportList, loading, error} = this.state;
- const {organization, group} = this.props;
- if (loading) {
- return <LoadingIndicator />;
- }
- if (error) {
- return <LoadingError onRetry={this.fetchData} />;
- }
- if (reportList.length) {
- return (
- <Layout.Body>
- <Layout.Main>
- {reportList.map((item, idx) => (
- <EventUserFeedback
- key={idx}
- report={item}
- orgId={organization.slug}
- issueId={group.id}
- />
- ))}
- <Pagination pageLinks={this.state.pageLinks} {...this.props} />
- </Layout.Main>
- </Layout.Body>
- );
- }
- return (
- <Layout.Body>
- <Layout.Main fullWidth>
- <UserFeedbackEmpty projectIds={[group.project.id]} />
- </Layout.Main>
- </Layout.Body>
- );
- }
- }
- export default withOrganization(GroupUserFeedback);
|