index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import {withProfiler} from '@sentry/react';
  4. import omit from 'lodash/omit';
  5. import Button from 'app/components/button';
  6. import ButtonBar from 'app/components/buttonBar';
  7. import EventUserFeedback from 'app/components/events/userFeedback';
  8. import CompactIssue from 'app/components/issues/compactIssue';
  9. import LightWeightNoProjectMessage from 'app/components/lightWeightNoProjectMessage';
  10. import LoadingIndicator from 'app/components/loadingIndicator';
  11. import GlobalSelectionHeader from 'app/components/organizations/globalSelectionHeader';
  12. import PageHeading from 'app/components/pageHeading';
  13. import Pagination from 'app/components/pagination';
  14. import {Panel} from 'app/components/panels';
  15. import {t} from 'app/locale';
  16. import {PageContent} from 'app/styles/organization';
  17. import space from 'app/styles/space';
  18. import {Organization, UserReport} from 'app/types';
  19. import withOrganization from 'app/utils/withOrganization';
  20. import AsyncView from 'app/views/asyncView';
  21. import UserFeedbackEmpty from './userFeedbackEmpty';
  22. import {getQuery} from './utils';
  23. type State = AsyncView['state'] & {
  24. reportList: UserReport[];
  25. };
  26. type Props = RouteComponentProps<{orgId: string}, {}> & {
  27. organization: Organization;
  28. };
  29. class OrganizationUserFeedback extends AsyncView<Props, State> {
  30. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  31. const {
  32. organization,
  33. location: {search},
  34. } = this.props;
  35. return [
  36. [
  37. 'reportList',
  38. `/organizations/${organization.slug}/user-feedback/`,
  39. {
  40. query: getQuery(search),
  41. },
  42. ],
  43. ];
  44. }
  45. getTitle() {
  46. return `${t('User Feedback')} - ${this.props.organization.slug}`;
  47. }
  48. get projectIds() {
  49. const {project} = this.props.location.query;
  50. return Array.isArray(project)
  51. ? project
  52. : typeof project === 'string'
  53. ? [project]
  54. : [];
  55. }
  56. renderResults() {
  57. const {orgId} = this.props.params;
  58. return (
  59. <Panel className="issue-list" data-test-id="user-feedback-list">
  60. {this.state.reportList.map(item => {
  61. const issue = item.issue;
  62. return (
  63. <CompactIssue key={item.id} id={issue.id} data={issue} eventId={item.eventID}>
  64. <StyledEventUserFeedback report={item} orgId={orgId} issueId={issue.id} />
  65. </CompactIssue>
  66. );
  67. })}
  68. </Panel>
  69. );
  70. }
  71. renderEmpty() {
  72. return <UserFeedbackEmpty projectIds={this.projectIds} />;
  73. }
  74. renderLoading() {
  75. return this.renderBody();
  76. }
  77. renderStreamBody() {
  78. const {loading, reportList} = this.state;
  79. if (loading) {
  80. return (
  81. <Panel>
  82. <LoadingIndicator />
  83. </Panel>
  84. );
  85. }
  86. if (!reportList.length) {
  87. return this.renderEmpty();
  88. }
  89. return this.renderResults();
  90. }
  91. renderBody() {
  92. const {organization} = this.props;
  93. const {location} = this.props;
  94. const {pathname, search, query} = location;
  95. const {status} = getQuery(search);
  96. const {reportListPageLinks} = this.state;
  97. const unresolvedQuery = omit(query, 'status');
  98. const allIssuesQuery = {...query, status: ''};
  99. return (
  100. <GlobalSelectionHeader>
  101. <PageContent>
  102. <LightWeightNoProjectMessage organization={organization}>
  103. <div data-test-id="user-feedback">
  104. <Header>
  105. <PageHeading>{t('User Feedback')}</PageHeading>
  106. <ButtonBar active={!Array.isArray(status) ? status || '' : ''} merged>
  107. <Button
  108. size="small"
  109. barId="unresolved"
  110. to={{pathname, query: unresolvedQuery}}
  111. >
  112. {t('Unresolved')}
  113. </Button>
  114. <Button size="small" barId="" to={{pathname, query: allIssuesQuery}}>
  115. {t('All Issues')}
  116. </Button>
  117. </ButtonBar>
  118. </Header>
  119. {this.renderStreamBody()}
  120. <Pagination pageLinks={reportListPageLinks} />
  121. </div>
  122. </LightWeightNoProjectMessage>
  123. </PageContent>
  124. </GlobalSelectionHeader>
  125. );
  126. }
  127. }
  128. export default withOrganization(withProfiler(OrganizationUserFeedback));
  129. const Header = styled('div')`
  130. display: flex;
  131. align-items: center;
  132. justify-content: space-between;
  133. margin-bottom: ${space(2)};
  134. `;
  135. const StyledEventUserFeedback = styled(EventUserFeedback)`
  136. margin: ${space(2)} 0 0;
  137. `;