solutionsSection.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import {useRef, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import useDrawer from 'sentry/components/globalDrawer';
  5. import {useGroupSummary} from 'sentry/components/group/groupSummary';
  6. import Placeholder from 'sentry/components/placeholder';
  7. import {IconChevron} from 'sentry/icons';
  8. import {t} 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 {data: summaryData} = useGroupSummary(group.id, group.issueCategory);
  68. const issueTypeConfig = getConfigForIssueType(group, group.project);
  69. const hasSummary = isSummaryEnabled(
  70. hasGenAIConsent,
  71. issueTypeConfig.issueSummary.enabled,
  72. organization.hideAiFeatures
  73. );
  74. const aiNeedsSetup =
  75. !hasGenAIConsent &&
  76. issueTypeConfig.issueSummary.enabled &&
  77. !organization.hideAiFeatures;
  78. const hasResources = issueTypeConfig.resources;
  79. return (
  80. <div>
  81. <SidebarSectionTitle style={{marginTop: 0}}>
  82. {t('Solutions Hub')}
  83. </SidebarSectionTitle>
  84. {hasSummary && !summaryData && (
  85. <Placeholder
  86. height="60px"
  87. style={{marginBottom: space(1)}}
  88. testId="loading-placeholder"
  89. />
  90. )}
  91. {hasSummary && summaryData && (
  92. <Summary>
  93. <HeadlineText
  94. dangerouslySetInnerHTML={{
  95. __html: singleLineRenderer(
  96. summaryData.whatsWrong?.replaceAll('**', '') ?? ''
  97. ),
  98. }}
  99. />
  100. </Summary>
  101. )}
  102. {aiNeedsSetup && (
  103. <Summary>
  104. <HeadlineText
  105. dangerouslySetInnerHTML={{
  106. __html: singleLineRenderer(
  107. 'Explore potential root causes and solutions with Sentry AI.'
  108. ),
  109. }}
  110. />
  111. </Summary>
  112. )}
  113. {!hasSummary && hasResources && !aiNeedsSetup && (
  114. <ResourcesWrapper isExpanded={isExpanded}>
  115. <ResourcesContent isExpanded={isExpanded}>
  116. <Resources
  117. configResources={issueTypeConfig.resources!}
  118. eventPlatform={event?.platform}
  119. group={group}
  120. />
  121. </ResourcesContent>
  122. <ExpandButton onClick={() => setIsExpanded(!isExpanded)} size="zero">
  123. {isExpanded ? t('SHOW LESS') : t('READ MORE')}
  124. </ExpandButton>
  125. </ResourcesWrapper>
  126. )}
  127. {(hasSummary || aiNeedsSetup) && (
  128. <StyledButton
  129. ref={openButtonRef}
  130. onClick={() => openSolutionsDrawer()}
  131. analyticsEventKey="issue_details.solutions_hub_opened"
  132. analyticsEventName="Issue Details: Solutions Hub Opened"
  133. analyticsParams={{
  134. has_streamlined_ui: hasStreamlinedUI,
  135. }}
  136. >
  137. {t('Open Solutions Hub')}
  138. <IconChevron direction="right" size="xs" />
  139. </StyledButton>
  140. )}
  141. </div>
  142. );
  143. }
  144. const Summary = styled('div')`
  145. margin-bottom: ${space(0.5)};
  146. `;
  147. const HeadlineText = styled('span')`
  148. margin-right: ${space(0.5)};
  149. word-break: break-word;
  150. `;
  151. const ResourcesWrapper = styled('div')<{isExpanded: boolean}>`
  152. position: relative;
  153. margin-bottom: ${space(1)};
  154. `;
  155. const ResourcesContent = styled('div')<{isExpanded: boolean}>`
  156. position: relative;
  157. max-height: ${p => (p.isExpanded ? 'none' : '68px')};
  158. overflow: hidden;
  159. padding-bottom: ${p => (p.isExpanded ? space(2) : 0)};
  160. ${p =>
  161. !p.isExpanded &&
  162. `
  163. &::after {
  164. content: '';
  165. position: absolute;
  166. bottom: 0;
  167. left: 0;
  168. right: 0;
  169. height: 40px;
  170. background: linear-gradient(transparent, ${p.theme.background});
  171. }
  172. `}
  173. `;
  174. const ExpandButton = styled(Button)`
  175. position: absolute;
  176. bottom: -${space(1)};
  177. right: 0;
  178. font-size: ${p => p.theme.fontSizeExtraSmall};
  179. color: ${p => p.theme.gray300};
  180. border: none;
  181. box-shadow: none;
  182. &:hover {
  183. color: ${p => p.theme.gray400};
  184. }
  185. `;
  186. const StyledButton = styled(Button)`
  187. margin-top: ${space(1)};
  188. width: 100%;
  189. background: ${p => p.theme.background}
  190. linear-gradient(to right, ${p => p.theme.background}, ${p => p.theme.pink400}20);
  191. color: ${p => p.theme.pink400};
  192. `;