index.tsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 'sentry/components/button';
  6. import {EventUserFeedback} from 'sentry/components/events/userFeedback';
  7. import CompactIssue from 'sentry/components/issues/compactIssue';
  8. import * as Layout from 'sentry/components/layouts/thirds';
  9. import LoadingIndicator from 'sentry/components/loadingIndicator';
  10. import NoProjectMessage from 'sentry/components/noProjectMessage';
  11. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  12. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  13. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  14. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  15. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  16. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  17. import Pagination from 'sentry/components/pagination';
  18. import Panel from 'sentry/components/panels/panel';
  19. import {SegmentedControl} from 'sentry/components/segmentedControl';
  20. import {Tooltip} from 'sentry/components/tooltip';
  21. import {t} from 'sentry/locale';
  22. import {space} from 'sentry/styles/space';
  23. import {Organization, UserReport} from 'sentry/types';
  24. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  25. import withOrganization from 'sentry/utils/withOrganization';
  26. import DeprecatedAsyncView, {AsyncViewState} from 'sentry/views/deprecatedAsyncView';
  27. import {UserFeedbackEmpty} from './userFeedbackEmpty';
  28. import {getQuery} from './utils';
  29. interface State extends AsyncViewState {
  30. reportList: UserReport[];
  31. }
  32. interface Props extends RouteComponentProps<{}, {}> {
  33. organization: Organization;
  34. }
  35. class OrganizationUserFeedback extends DeprecatedAsyncView<Props, State> {
  36. getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
  37. const {
  38. organization,
  39. location: {search},
  40. } = this.props;
  41. return [
  42. [
  43. 'reportList',
  44. `/organizations/${organization.slug}/user-feedback/`,
  45. {
  46. query: getQuery(search),
  47. },
  48. ],
  49. ];
  50. }
  51. getTitle() {
  52. return `${t('User Feedback')} - ${this.props.organization.slug}`;
  53. }
  54. get projectIds() {
  55. const {project} = this.props.location.query;
  56. return Array.isArray(project)
  57. ? project
  58. : typeof project === 'string'
  59. ? [project]
  60. : [];
  61. }
  62. renderResults() {
  63. const {organization} = this.props;
  64. return (
  65. <Panel className="issue-list" data-test-id="user-feedback-list">
  66. {this.state.reportList.map(item => {
  67. const issue = item.issue;
  68. return (
  69. <CompactIssue key={item.id} id={issue.id} data={issue} eventId={item.eventID}>
  70. <StyledEventUserFeedback
  71. report={item}
  72. orgSlug={organization.slug}
  73. issueId={issue.id}
  74. />
  75. </CompactIssue>
  76. );
  77. })}
  78. </Panel>
  79. );
  80. }
  81. renderEmpty() {
  82. return <UserFeedbackEmpty projectIds={this.projectIds} />;
  83. }
  84. renderLoading() {
  85. return this.renderBody();
  86. }
  87. renderStreamBody() {
  88. const {loading, reportList} = this.state;
  89. if (loading) {
  90. return (
  91. <Panel>
  92. <LoadingIndicator />
  93. </Panel>
  94. );
  95. }
  96. if (!reportList.length) {
  97. return this.renderEmpty();
  98. }
  99. return this.renderResults();
  100. }
  101. renderBody() {
  102. const {organization, router} = this.props;
  103. const {location} = this.props;
  104. const {pathname, search, query} = location;
  105. const {status} = getQuery(search);
  106. const {reportListPageLinks} = this.state;
  107. const unresolvedQuery = omit(query, 'status');
  108. const allIssuesQuery = {...query, status: ''};
  109. const hasNewFeedback = organization.features.includes('user-feedback-ui');
  110. return (
  111. <PageFiltersContainer>
  112. <NoProjectMessage organization={organization}>
  113. <Layout.Header>
  114. <Layout.HeaderContent>
  115. <Layout.Title>
  116. {t('User Feedback')}
  117. <PageHeadingQuestionTooltip
  118. docsUrl="https://docs.sentry.io/product/user-feedback/"
  119. title={t(
  120. 'Feedback submitted by users who experienced an error while using your application, including their name, email address, and any additional comments.'
  121. )}
  122. />
  123. </Layout.Title>
  124. </Layout.HeaderContent>
  125. {hasNewFeedback && (
  126. <Layout.HeaderActions>
  127. <Tooltip
  128. title={t('Go back to the new feedback layout.')}
  129. position="left"
  130. isHoverable
  131. >
  132. <Button
  133. size="sm"
  134. priority="default"
  135. to={{
  136. pathname: normalizeUrl(
  137. `/organizations/${organization.slug}/feedback/`
  138. ),
  139. query: {
  140. ...location.query,
  141. query: undefined,
  142. cursor: undefined,
  143. },
  144. }}
  145. >
  146. {t('Go to New User Feedback')}
  147. </Button>
  148. </Tooltip>
  149. </Layout.HeaderActions>
  150. )}
  151. </Layout.Header>
  152. <Layout.Body data-test-id="user-feedback">
  153. <Layout.Main fullWidth>
  154. <Filters>
  155. <PageFilterBar>
  156. <ProjectPageFilter />
  157. <EnvironmentPageFilter />
  158. <DatePageFilter position="bottom-end" />
  159. </PageFilterBar>
  160. <SegmentedControl
  161. aria-label={t('Issue Status')}
  162. value={!Array.isArray(status) ? status || '' : ''}
  163. onChange={key =>
  164. router.replace({
  165. pathname,
  166. query: key === 'unresolved' ? unresolvedQuery : allIssuesQuery,
  167. })
  168. }
  169. >
  170. <SegmentedControl.Item key="unresolved">
  171. {t('Unresolved')}
  172. </SegmentedControl.Item>
  173. <SegmentedControl.Item key="">{t('All Issues')}</SegmentedControl.Item>
  174. </SegmentedControl>
  175. </Filters>
  176. {this.renderStreamBody()}
  177. <Pagination pageLinks={reportListPageLinks} />
  178. </Layout.Main>
  179. </Layout.Body>
  180. </NoProjectMessage>
  181. </PageFiltersContainer>
  182. );
  183. }
  184. }
  185. export default withOrganization(withProfiler(OrganizationUserFeedback));
  186. const Filters = styled('div')`
  187. display: grid;
  188. grid-template-columns: minmax(0, max-content) max-content;
  189. justify-content: start;
  190. gap: ${space(2)};
  191. margin-bottom: ${space(2)};
  192. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  193. grid-template-columns: minmax(0, 1fr) max-content;
  194. }
  195. @media (max-width: ${p => p.theme.breakpoints.small}) {
  196. grid-template-columns: minmax(0, 1fr);
  197. }
  198. `;
  199. const StyledEventUserFeedback = styled(EventUserFeedback)`
  200. margin: ${space(2)} 0;
  201. `;