groupUserFeedback.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {Fragment} from 'react';
  2. import {css} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import {EventUserFeedback} from 'sentry/components/events/userFeedback';
  5. import * as Layout from 'sentry/components/layouts/thirds';
  6. import LoadingError from 'sentry/components/loadingError';
  7. import LoadingIndicator from 'sentry/components/loadingIndicator';
  8. import Pagination from 'sentry/components/pagination';
  9. import {space} from 'sentry/styles/space';
  10. import type {Group} from 'sentry/types/group';
  11. import {useLocation} from 'sentry/utils/useLocation';
  12. import useOrganization from 'sentry/utils/useOrganization';
  13. import {useGroupUserFeedback} from 'sentry/views/issueDetails/useGroupUserFeedback';
  14. import {useHasStreamlinedUI} from 'sentry/views/issueDetails/utils';
  15. import {UserFeedbackEmpty} from 'sentry/views/userFeedback/userFeedbackEmpty';
  16. interface GroupUserFeedbackProps {
  17. group: Group;
  18. }
  19. function GroupUserFeedback({group}: GroupUserFeedbackProps) {
  20. const organization = useOrganization();
  21. const hasStreamlinedUI = useHasStreamlinedUI();
  22. const location = useLocation();
  23. const {
  24. data: reportList,
  25. isPending,
  26. isError,
  27. refetch,
  28. getResponseHeader,
  29. } = useGroupUserFeedback({
  30. groupId: group.id,
  31. query: {
  32. cursor: location.query.cursor as string | undefined,
  33. },
  34. });
  35. if (isError) {
  36. return <LoadingError onRetry={refetch} />;
  37. }
  38. if (isPending) {
  39. return (
  40. <StyledLayoutBody hasStreamlinedUI={hasStreamlinedUI}>
  41. <Layout.Main fullWidth>
  42. <LoadingIndicator />
  43. </Layout.Main>
  44. </StyledLayoutBody>
  45. );
  46. }
  47. const pageLinks = getResponseHeader?.('Link');
  48. return (
  49. <StyledLayoutBody hasStreamlinedUI={hasStreamlinedUI}>
  50. <Layout.Main fullWidth>
  51. {reportList.length === 0 ? (
  52. <UserFeedbackEmpty projectIds={[group.project.id]} issueTab />
  53. ) : (
  54. <Fragment>
  55. {reportList.map((item, idx) => (
  56. <StyledEventUserFeedback
  57. key={idx}
  58. report={item}
  59. orgSlug={organization.slug}
  60. issueId={group.id}
  61. />
  62. ))}
  63. <Pagination pageLinks={pageLinks} />
  64. </Fragment>
  65. )}
  66. </Layout.Main>
  67. </StyledLayoutBody>
  68. );
  69. }
  70. const StyledEventUserFeedback = styled(EventUserFeedback)`
  71. margin-bottom: ${space(2)};
  72. `;
  73. const StyledLayoutBody = styled(Layout.Body)<{hasStreamlinedUI?: boolean}>`
  74. ${p =>
  75. p.hasStreamlinedUI &&
  76. css`
  77. border: 1px solid ${p.theme.border};
  78. border-radius: ${p.theme.borderRadius};
  79. padding: ${space(2)} 0;
  80. @media (min-width: ${p.theme.breakpoints.medium}) {
  81. padding: ${space(2)} ${space(2)};
  82. }
  83. `}
  84. `;
  85. export default GroupUserFeedback;