solutionsHubDrawer.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. import {Fragment, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import starImage from 'sentry-images/spot/banner-star.svg';
  4. import {SeerIcon} from 'sentry/components/ai/SeerIcon';
  5. import ProjectAvatar from 'sentry/components/avatar/projectAvatar';
  6. import FeatureBadge from 'sentry/components/badge/featureBadge';
  7. import {Breadcrumbs as NavigationBreadcrumbs} from 'sentry/components/breadcrumbs';
  8. import {Button} from 'sentry/components/button';
  9. import {AutofixSetupContent} from 'sentry/components/events/autofix/autofixSetupModal';
  10. import {AutofixSteps} from 'sentry/components/events/autofix/autofixSteps';
  11. import {useAiAutofix} from 'sentry/components/events/autofix/useAutofix';
  12. import {DrawerBody, DrawerHeader} from 'sentry/components/globalDrawer/components';
  13. import {GroupSummary} from 'sentry/components/group/groupSummary';
  14. import HookOrDefault from 'sentry/components/hookOrDefault';
  15. import Input from 'sentry/components/input';
  16. import LoadingIndicator from 'sentry/components/loadingIndicator';
  17. import {IconDocs} from 'sentry/icons';
  18. import {t, tct} from 'sentry/locale';
  19. import {space} from 'sentry/styles/space';
  20. import type {Event} from 'sentry/types/event';
  21. import type {Group} from 'sentry/types/group';
  22. import type {Project} from 'sentry/types/project';
  23. import {getShortEventId} from 'sentry/utils/events';
  24. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  25. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  26. import {MIN_NAV_HEIGHT} from 'sentry/views/issueDetails/streamline/eventTitle';
  27. import {useAiConfig} from 'sentry/views/issueDetails/streamline/hooks/useAiConfig';
  28. import Resources from 'sentry/views/issueDetails/streamline/sidebar/resources';
  29. interface AutofixStartBoxProps {
  30. groupId: string;
  31. onSend: (message: string) => void;
  32. }
  33. function AutofixStartBox({onSend, groupId}: AutofixStartBoxProps) {
  34. const [message, setMessage] = useState('');
  35. const stars = [
  36. {size: 10, left: 20, top: 5, rotation: 30, opacity: 0.15},
  37. {size: 12, left: 50, top: 8, rotation: 45, opacity: 0.2},
  38. {size: 10, left: 80, top: 12, rotation: 15, opacity: 0.2},
  39. {size: 14, left: 15, top: 20, rotation: 60, opacity: 0.3},
  40. {size: 16, left: 45, top: 25, rotation: 30, opacity: 0.35},
  41. {size: 14, left: 75, top: 22, rotation: 45, opacity: 0.3},
  42. {size: 18, left: 25, top: 35, rotation: 20, opacity: 0.4},
  43. {size: 20, left: 60, top: 38, rotation: 50, opacity: 0.45},
  44. {size: 18, left: 85, top: 42, rotation: 35, opacity: 0.4},
  45. {size: 22, left: 15, top: 55, rotation: 25, opacity: 0.5},
  46. {size: 24, left: 40, top: 58, rotation: 40, opacity: 0.55},
  47. {size: 22, left: 70, top: 52, rotation: 30, opacity: 0.5},
  48. {size: 26, left: 30, top: 70, rotation: 35, opacity: 0.65},
  49. {size: 28, left: 50, top: 75, rotation: 45, opacity: 0.7},
  50. {size: 26, left: 80, top: 72, rotation: 25, opacity: 0.7},
  51. ];
  52. const handleSubmit = (e: React.FormEvent) => {
  53. e.preventDefault();
  54. onSend(message);
  55. };
  56. return (
  57. <StartBox>
  58. <StarTrail>
  59. {stars.map((star, i) => (
  60. <TrailStar
  61. key={i}
  62. src={starImage}
  63. style={{
  64. left: `${star.left}%`,
  65. top: `${star.top}%`,
  66. width: `${star.size}px`,
  67. height: `${star.size}px`,
  68. opacity: star.opacity,
  69. transform: `rotate(${star.rotation}deg)`,
  70. }}
  71. />
  72. ))}
  73. </StarTrail>
  74. <ContentContainer>
  75. <HeaderText>Autofix</HeaderText>
  76. <p>Work together with Autofix to find the root cause and fix the issue.</p>
  77. <form onSubmit={handleSubmit}>
  78. <Row>
  79. <Input
  80. type="text"
  81. value={message}
  82. onChange={e => setMessage(e.target.value)}
  83. placeholder={'(Optional) Share helpful context here...'}
  84. />
  85. <ButtonWithStars>
  86. <StarLarge1 src={starImage} />
  87. <StarLarge2 src={starImage} />
  88. <StarLarge3 src={starImage} />
  89. <Button
  90. type="submit"
  91. priority="primary"
  92. analyticsEventKey={
  93. message
  94. ? 'autofix.give_instructions_clicked'
  95. : 'autofix.start_fix_clicked'
  96. }
  97. analyticsEventName={
  98. message
  99. ? 'Autofix: Give Instructions Clicked'
  100. : 'Autofix: Start Fix Clicked'
  101. }
  102. analyticsParams={{group_id: groupId}}
  103. aria-label="Start Autofix"
  104. >
  105. {t('Start Autofix')}
  106. </Button>
  107. </ButtonWithStars>
  108. </Row>
  109. </form>
  110. </ContentContainer>
  111. </StartBox>
  112. );
  113. }
  114. interface SolutionsHubDrawerProps {
  115. event: Event;
  116. group: Group;
  117. project: Project;
  118. }
  119. const AiSetupDataConsent = HookOrDefault({
  120. hookName: 'component:ai-setup-data-consent',
  121. defaultComponent: () => <div data-test-id="ai-setup-data-consent" />,
  122. });
  123. export function SolutionsHubDrawer({group, project, event}: SolutionsHubDrawerProps) {
  124. const {autofixData, triggerAutofix, reset} = useAiAutofix(group, event);
  125. const aiConfig = useAiConfig(group, event, project);
  126. useRouteAnalyticsParams({
  127. autofix_status: autofixData?.status ?? 'none',
  128. });
  129. const config = getConfigForIssueType(group, project);
  130. return (
  131. <SolutionsDrawerContainer className="solutions-drawer-container">
  132. <SolutionsDrawerHeader>
  133. <NavigationCrumbs
  134. crumbs={[
  135. {
  136. label: (
  137. <CrumbContainer>
  138. <ProjectAvatar project={project} />
  139. <ShortId>{group.shortId}</ShortId>
  140. </CrumbContainer>
  141. ),
  142. },
  143. {label: getShortEventId(event.id)},
  144. {label: t('Solutions Hub')},
  145. ]}
  146. />
  147. </SolutionsDrawerHeader>
  148. <SolutionsDrawerNavigator>
  149. <Header>{t('Solutions Hub')}</Header>
  150. </SolutionsDrawerNavigator>
  151. <SolutionsDrawerBody>
  152. {config.resources && (
  153. <ResourcesContainer>
  154. <ResourcesHeader>
  155. <IconDocs size="md" />
  156. {t('Resources')}
  157. </ResourcesHeader>
  158. <ResourcesBody>
  159. <Resources
  160. eventPlatform={event?.platform}
  161. group={group}
  162. configResources={config.resources}
  163. />
  164. </ResourcesBody>
  165. </ResourcesContainer>
  166. )}
  167. <HeaderText>
  168. <HeaderContainer>
  169. <SeerIcon size="lg" />
  170. {t('Sentry AI')}
  171. <StyledFeatureBadge
  172. type="beta"
  173. title={tct(
  174. 'This feature is in beta. Try it out and let us know your feedback at [email:autofix@sentry.io].',
  175. {
  176. email: <a href="mailto:autofix@sentry.io" />,
  177. }
  178. )}
  179. />
  180. </HeaderContainer>
  181. {autofixData && (
  182. <Button
  183. size="xs"
  184. onClick={reset}
  185. title={
  186. autofixData.created_at
  187. ? `Last run at ${autofixData.created_at.split('T')[0]}`
  188. : null
  189. }
  190. >
  191. {t('Start Over')}
  192. </Button>
  193. )}
  194. </HeaderText>
  195. {aiConfig.isAutofixSetupLoading ? (
  196. <div data-test-id="ai-setup-loading-indicator">
  197. <LoadingIndicator />
  198. </div>
  199. ) : aiConfig.needsGenAIConsent ? (
  200. <AiSetupDataConsent groupId={group.id} />
  201. ) : (
  202. <Fragment>
  203. {aiConfig.hasSummary && (
  204. <StyledCard>
  205. <GroupSummary group={group} event={event} project={project} />
  206. </StyledCard>
  207. )}
  208. {aiConfig.hasAutofix && (
  209. <Fragment>
  210. {aiConfig.needsAutofixSetup ? (
  211. <AutofixSetupContent groupId={group.id} projectId={project.id} />
  212. ) : !autofixData ? (
  213. <AutofixStartBox onSend={triggerAutofix} groupId={group.id} />
  214. ) : (
  215. <AutofixSteps
  216. data={autofixData}
  217. groupId={group.id}
  218. runId={autofixData.run_id}
  219. onRetry={reset}
  220. />
  221. )}
  222. </Fragment>
  223. )}
  224. </Fragment>
  225. )}
  226. </SolutionsDrawerBody>
  227. </SolutionsDrawerContainer>
  228. );
  229. }
  230. const ResourcesContainer = styled('div')``;
  231. const ResourcesBody = styled('div')`
  232. padding: 0 ${space(2)} ${space(2)} ${space(2)};
  233. border-bottom: 1px solid ${p => p.theme.border};
  234. margin-bottom: ${space(2)};
  235. `;
  236. const Row = styled('div')`
  237. display: flex;
  238. gap: ${space(1)};
  239. `;
  240. const StartBox = styled('div')`
  241. padding: ${space(2)};
  242. position: absolute;
  243. bottom: ${space(2)};
  244. left: ${space(2)};
  245. right: ${space(2)};
  246. `;
  247. const ContentContainer = styled('div')`
  248. position: relative;
  249. z-index: 1;
  250. margin-top: 80px;
  251. `;
  252. const SolutionsDrawerContainer = styled('div')`
  253. height: 100%;
  254. display: grid;
  255. grid-template-rows: auto auto 1fr;
  256. position: relative;
  257. `;
  258. const SolutionsDrawerHeader = styled(DrawerHeader)`
  259. position: unset;
  260. max-height: ${MIN_NAV_HEIGHT}px;
  261. box-shadow: none;
  262. border-bottom: 1px solid ${p => p.theme.border};
  263. `;
  264. const SolutionsDrawerNavigator = styled('div')`
  265. display: grid;
  266. grid-template-columns: 1fr;
  267. align-items: center;
  268. padding: ${space(0.75)} 24px;
  269. background: ${p => p.theme.background};
  270. z-index: 1;
  271. min-height: ${MIN_NAV_HEIGHT}px;
  272. box-shadow: ${p => p.theme.translucentBorder} 0 1px;
  273. `;
  274. const SolutionsDrawerBody = styled(DrawerBody)`
  275. overflow: auto;
  276. overscroll-behavior: contain;
  277. /* Move the scrollbar to the left edge */
  278. scroll-margin: 0 ${space(2)};
  279. direction: rtl;
  280. * {
  281. direction: ltr;
  282. }
  283. `;
  284. const Header = styled('h3')`
  285. display: block;
  286. font-size: ${p => p.theme.fontSizeExtraLarge};
  287. font-weight: ${p => p.theme.fontWeightBold};
  288. margin: 0;
  289. `;
  290. const NavigationCrumbs = styled(NavigationBreadcrumbs)`
  291. margin: 0;
  292. padding: 0;
  293. `;
  294. const CrumbContainer = styled('div')`
  295. display: flex;
  296. gap: ${space(1)};
  297. align-items: center;
  298. `;
  299. const ShortId = styled('div')`
  300. font-family: ${p => p.theme.text.family};
  301. font-size: ${p => p.theme.fontSizeMedium};
  302. line-height: 1;
  303. `;
  304. const ButtonWithStars = styled('div')`
  305. position: relative;
  306. display: flex;
  307. align-items: center;
  308. `;
  309. const StarLarge = styled('img')`
  310. position: absolute;
  311. z-index: 0;
  312. filter: sepia(1) saturate(3) hue-rotate(290deg);
  313. `;
  314. const StarLarge1 = styled(StarLarge)`
  315. left: 45px;
  316. bottom: -15px;
  317. transform: rotate(90deg);
  318. width: 16px;
  319. height: 16px;
  320. `;
  321. const StarLarge2 = styled(StarLarge)`
  322. left: -5px;
  323. top: -15px;
  324. transform: rotate(-30deg);
  325. width: 24px;
  326. height: 24px;
  327. `;
  328. const StarLarge3 = styled(StarLarge)`
  329. right: -25px;
  330. bottom: 0px;
  331. transform: rotate(20deg);
  332. width: 28px;
  333. height: 28px;
  334. `;
  335. const StyledCard = styled('div')`
  336. background: ${p => p.theme.backgroundElevated};
  337. border-radius: ${p => p.theme.borderRadius};
  338. border: 1px solid ${p => p.theme.border};
  339. overflow: hidden;
  340. box-shadow: ${p => p.theme.dropShadowMedium};
  341. padding: ${space(1.5)} ${space(2)};
  342. `;
  343. const HeaderText = styled('div')`
  344. font-weight: bold;
  345. font-size: ${p => p.theme.fontSizeLarge};
  346. display: flex;
  347. align-items: center;
  348. gap: ${space(0.5)};
  349. padding-bottom: ${space(2)};
  350. justify-content: space-between;
  351. `;
  352. const StyledFeatureBadge = styled(FeatureBadge)`
  353. margin-left: ${space(0.25)};
  354. padding-bottom: 3px;
  355. `;
  356. const ResourcesHeader = styled('div')`
  357. gap: ${space(1)};
  358. font-weight: bold;
  359. font-size: ${p => p.theme.fontSizeLarge};
  360. display: flex;
  361. align-items: center;
  362. padding-bottom: ${space(2)};
  363. `;
  364. const StarTrail = styled('div')`
  365. height: 450px;
  366. width: 100%;
  367. position: absolute;
  368. bottom: 5rem;
  369. left: 0;
  370. right: 0;
  371. z-index: -1;
  372. pointer-events: none;
  373. overflow: hidden;
  374. `;
  375. const TrailStar = styled('img')`
  376. position: absolute;
  377. filter: sepia(1) saturate(3) hue-rotate(290deg);
  378. transition: all 0.2s ease-in-out;
  379. `;
  380. const HeaderContainer = styled('div')`
  381. display: flex;
  382. align-items: center;
  383. gap: ${space(0.5)};
  384. `;