index.tsx 7.3 KB

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