solutionsSection.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import {useRef, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import FeatureBadge from 'sentry/components/badge/featureBadge';
  4. import {Button} from 'sentry/components/button';
  5. import useDrawer from 'sentry/components/globalDrawer';
  6. import {GroupSummary, useGroupSummary} from 'sentry/components/group/groupSummary';
  7. import {IconChevron} from 'sentry/icons';
  8. import {t, tct} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import type {Event} from 'sentry/types/event';
  11. import type {Group} from 'sentry/types/group';
  12. import type {Project} from 'sentry/types/project';
  13. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  14. import {singleLineRenderer} from 'sentry/utils/marked';
  15. import useOrganization from 'sentry/utils/useOrganization';
  16. import Resources from 'sentry/views/issueDetails/streamline/resources';
  17. import {SidebarSectionTitle} from 'sentry/views/issueDetails/streamline/sidebar';
  18. import {SolutionsHubDrawer} from 'sentry/views/issueDetails/streamline/solutionsHubDrawer';
  19. import {useHasStreamlinedUI} from 'sentry/views/issueDetails/utils';
  20. const isSummaryEnabled = (
  21. hasGenAIConsent: boolean,
  22. hasIssueSummary: boolean,
  23. hideAiFeatures: boolean
  24. ) => {
  25. return hasGenAIConsent && hasIssueSummary && !hideAiFeatures;
  26. };
  27. export default function SolutionsSection({
  28. group,
  29. project,
  30. event,
  31. }: {
  32. event: Event | undefined;
  33. group: Group;
  34. project: Project;
  35. }) {
  36. const organization = useOrganization();
  37. const [isExpanded, setIsExpanded] = useState(false);
  38. const openButtonRef = useRef<HTMLButtonElement>(null);
  39. const {openDrawer} = useDrawer();
  40. const hasStreamlinedUI = useHasStreamlinedUI();
  41. const openSolutionsDrawer = () => {
  42. if (!event) {
  43. return;
  44. }
  45. openDrawer(
  46. () => <SolutionsHubDrawer group={group} project={project} event={event} />,
  47. {
  48. ariaLabel: t('Solutions drawer'),
  49. // We prevent a click on the Open/Close Autofix button from closing the drawer so that
  50. // we don't reopen it immediately, and instead let the button handle this itself.
  51. shouldCloseOnInteractOutside: element => {
  52. const viewAllButton = openButtonRef.current;
  53. if (
  54. viewAllButton?.contains(element) ||
  55. document.getElementById('sentry-feedback')?.contains(element) ||
  56. document.getElementById('autofix-rethink-input')?.contains(element)
  57. ) {
  58. return false;
  59. }
  60. return true;
  61. },
  62. transitionProps: {stiffness: 1000},
  63. }
  64. );
  65. };
  66. const hasGenAIConsent = organization.genAIConsent;
  67. const {
  68. data: summaryData,
  69. isPending: isSummaryLoading,
  70. isError: isSummaryError,
  71. } = useGroupSummary(group.id, group.issueCategory);
  72. const issueTypeConfig = getConfigForIssueType(group, group.project);
  73. const hasSummary = isSummaryEnabled(
  74. hasGenAIConsent,
  75. issueTypeConfig.issueSummary.enabled,
  76. organization.hideAiFeatures
  77. );
  78. const aiNeedsSetup =
  79. !hasGenAIConsent &&
  80. issueTypeConfig.issueSummary.enabled &&
  81. !organization.hideAiFeatures;
  82. const hasResources = issueTypeConfig.resources;
  83. return (
  84. <div>
  85. <SidebarSectionTitle style={{marginTop: 0}}>
  86. <HeaderContainer>
  87. {t('Solutions Hub')}
  88. {hasSummary && (
  89. <StyledFeatureBadge
  90. type="beta"
  91. title={tct(
  92. 'This feature is in beta. Try it out and let us know your feedback at [email:autofix@sentry.io].',
  93. {
  94. email: <a href="mailto:autofix@sentry.io" />,
  95. }
  96. )}
  97. />
  98. )}
  99. </HeaderContainer>
  100. </SidebarSectionTitle>
  101. {hasSummary && (
  102. <Summary>
  103. <GroupSummary
  104. data={summaryData ?? undefined}
  105. isError={isSummaryError}
  106. isPending={isSummaryLoading}
  107. preview
  108. />
  109. </Summary>
  110. )}
  111. {aiNeedsSetup && (
  112. <Summary>
  113. <HeadlineText
  114. dangerouslySetInnerHTML={{
  115. __html: singleLineRenderer(
  116. 'Explore potential root causes and solutions with Sentry AI.'
  117. ),
  118. }}
  119. />
  120. </Summary>
  121. )}
  122. {!hasSummary && hasResources && !aiNeedsSetup && (
  123. <ResourcesWrapper isExpanded={isExpanded}>
  124. <ResourcesContent isExpanded={isExpanded}>
  125. <Resources
  126. configResources={issueTypeConfig.resources!}
  127. eventPlatform={event?.platform}
  128. group={group}
  129. />
  130. </ResourcesContent>
  131. <ExpandButton onClick={() => setIsExpanded(!isExpanded)} size="zero">
  132. {isExpanded ? t('SHOW LESS') : t('READ MORE')}
  133. </ExpandButton>
  134. </ResourcesWrapper>
  135. )}
  136. {(hasSummary || aiNeedsSetup) && (
  137. <StyledButton
  138. ref={openButtonRef}
  139. onClick={() => openSolutionsDrawer()}
  140. analyticsEventKey="issue_details.solutions_hub_opened"
  141. analyticsEventName="Issue Details: Solutions Hub Opened"
  142. analyticsParams={{
  143. has_streamlined_ui: hasStreamlinedUI,
  144. }}
  145. >
  146. {t('Open Solutions Hub')}
  147. <IconChevron direction="right" size="xs" />
  148. </StyledButton>
  149. )}
  150. </div>
  151. );
  152. }
  153. const Summary = styled('div')`
  154. margin-bottom: ${space(0.5)};
  155. position: relative;
  156. `;
  157. const HeadlineText = styled('span')`
  158. margin-right: ${space(0.5)};
  159. word-break: break-word;
  160. `;
  161. const ResourcesWrapper = styled('div')<{isExpanded: boolean}>`
  162. position: relative;
  163. margin-bottom: ${space(1)};
  164. `;
  165. const ResourcesContent = styled('div')<{isExpanded: boolean}>`
  166. position: relative;
  167. max-height: ${p => (p.isExpanded ? 'none' : '68px')};
  168. overflow: hidden;
  169. padding-bottom: ${p => (p.isExpanded ? space(2) : 0)};
  170. ${p =>
  171. !p.isExpanded &&
  172. `
  173. &::after {
  174. content: '';
  175. position: absolute;
  176. bottom: 0;
  177. left: 0;
  178. right: 0;
  179. height: 40px;
  180. background: linear-gradient(transparent, ${p.theme.background});
  181. }
  182. `}
  183. `;
  184. const ExpandButton = styled(Button)`
  185. position: absolute;
  186. bottom: -${space(1)};
  187. right: 0;
  188. font-size: ${p => p.theme.fontSizeExtraSmall};
  189. color: ${p => p.theme.gray300};
  190. border: none;
  191. box-shadow: none;
  192. &:hover {
  193. color: ${p => p.theme.gray400};
  194. }
  195. `;
  196. const StyledButton = styled(Button)`
  197. margin-top: ${space(1)};
  198. width: 100%;
  199. background: ${p => p.theme.background}
  200. linear-gradient(to right, ${p => p.theme.background}, ${p => p.theme.pink400}20);
  201. color: ${p => p.theme.pink400};
  202. `;
  203. const HeaderContainer = styled('div')`
  204. display: flex;
  205. align-items: center;
  206. gap: ${space(1)};
  207. `;
  208. const StyledFeatureBadge = styled(FeatureBadge)`
  209. margin-left: ${space(0.25)};
  210. padding-bottom: 3px;
  211. `;