solutionsHubNotices.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import onboardingInstall from 'sentry-images/spot/onboarding-install.svg';
  4. import {LinkButton} from 'sentry/components/button';
  5. import {Alert} from 'sentry/components/core/alert';
  6. import type {AutofixRepository} from 'sentry/components/events/autofix/types';
  7. import ExternalLink from 'sentry/components/links/externalLink';
  8. import {t, tct} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. interface SolutionsHubNoticesProps {
  12. autofixRepositories: AutofixRepository[];
  13. hasGithubIntegration?: boolean;
  14. }
  15. function GithubIntegrationSetupCard() {
  16. const organization = useOrganization();
  17. return (
  18. <IntegrationCard key="no-readable-repos">
  19. <CardContent>
  20. <CardTitle>{t('Set Up the GitHub Integration')}</CardTitle>
  21. <CardDescription>
  22. <span>
  23. {tct('Autofix is [bold:a lot better] when it has your codebase as context.', {
  24. bold: <b />,
  25. })}
  26. </span>
  27. <span>
  28. {tct(
  29. 'Set up the [integrationLink:GitHub Integration] to allow Autofix to go deeper when troubleshooting and fixing your issues–including writing the code and opening PRs.',
  30. {
  31. integrationLink: (
  32. <ExternalLink
  33. href={`/settings/${organization.slug}/integrations/github/`}
  34. />
  35. ),
  36. }
  37. )}
  38. </span>
  39. </CardDescription>
  40. <LinkButton
  41. href={`/settings/${organization.slug}/integrations/github/`}
  42. size="sm"
  43. priority="primary"
  44. >
  45. {t('Set Up Now')}
  46. </LinkButton>
  47. </CardContent>
  48. <CardIllustration src={onboardingInstall} alt="Install" />
  49. </IntegrationCard>
  50. );
  51. }
  52. export function SolutionsHubNotices({
  53. autofixRepositories,
  54. hasGithubIntegration,
  55. }: SolutionsHubNoticesProps) {
  56. const organization = useOrganization();
  57. const unreadableRepos = autofixRepositories.filter(repo => repo.is_readable === false);
  58. const notices: JSX.Element[] = [];
  59. const integrationId = autofixRepositories.find(repo =>
  60. repo.provider.includes('github')
  61. )?.integration_id;
  62. if (!hasGithubIntegration) {
  63. notices.push(<GithubIntegrationSetupCard key="github-setup" />);
  64. }
  65. if (unreadableRepos.length > 1) {
  66. const githubRepos = unreadableRepos.filter(repo => repo.provider.includes('github'));
  67. const nonGithubRepos = unreadableRepos.filter(
  68. repo => !repo.provider.includes('github')
  69. );
  70. notices.push(
  71. <Alert type="warning" showIcon key="multiple-repos">
  72. {tct("Autofix can't access these repositories: [repoList].", {
  73. repoList: <b>{unreadableRepos.map(repo => repo.name).join(', ')}</b>,
  74. })}
  75. {githubRepos.length > 0 && (
  76. <Fragment>
  77. {' '}
  78. {tct(
  79. 'For best performance, enable the [integrationLink:GitHub integration] and its [codeMappingsLink:code mappings].',
  80. {
  81. integrationLink: (
  82. <ExternalLink
  83. href={
  84. integrationId
  85. ? `/settings/${organization.slug}/integrations/github/${integrationId}/`
  86. : `/settings/${organization.slug}/integrations/github/`
  87. }
  88. />
  89. ),
  90. codeMappingsLink: integrationId ? (
  91. <ExternalLink
  92. href={`/settings/${organization.slug}/integrations/github/${integrationId}/?tab=codeMappings`}
  93. />
  94. ) : null,
  95. }
  96. )}
  97. </Fragment>
  98. )}
  99. {nonGithubRepos.length > 0 && (
  100. <Fragment>
  101. {' '}
  102. {t('Autofix currently only supports GitHub repositories.')}
  103. </Fragment>
  104. )}
  105. </Alert>
  106. );
  107. } else if (unreadableRepos.length === 1) {
  108. const unreadableRepo = unreadableRepos[0]!;
  109. notices.push(
  110. <Alert type="warning" showIcon key="single-repo">
  111. {unreadableRepo.provider.includes('github')
  112. ? tct(
  113. "Autofix can't access the [repo] repository, make sure the [integrationLink:GitHub integration] and its [codeMappingsLink:code mappings] are correctly set up.",
  114. {
  115. repo: <b>{unreadableRepo.name}</b>,
  116. integrationLink: (
  117. <ExternalLink
  118. href={`/settings/${organization.slug}/integrations/github/${unreadableRepo.integration_id}`}
  119. />
  120. ),
  121. codeMappingsLink: (
  122. <ExternalLink
  123. href={`/settings/${organization.slug}/integrations/github/${unreadableRepo.integration_id}/?tab=codeMappings`}
  124. />
  125. ),
  126. }
  127. )
  128. : tct(
  129. "Autofix can't access the [repo] repository. It currently only supports GitHub repositories.",
  130. {
  131. repo: <b>{unreadableRepo.name}</b>,
  132. }
  133. )}
  134. </Alert>
  135. );
  136. }
  137. if (notices.length === 0) {
  138. return null;
  139. }
  140. return <NoticesContainer>{notices}</NoticesContainer>;
  141. }
  142. const NoticesContainer = styled('div')`
  143. display: flex;
  144. flex-direction: column;
  145. gap: ${space(2)};
  146. align-items: stretch;
  147. margin-bottom: ${space(2)};
  148. `;
  149. const IntegrationCard = styled('div')`
  150. position: relative;
  151. overflow: hidden;
  152. border: 1px solid ${p => p.theme.border};
  153. border-radius: ${p => p.theme.borderRadius};
  154. display: flex;
  155. flex-direction: row;
  156. align-items: flex-end;
  157. gap: ${space(1)};
  158. background: linear-gradient(
  159. 90deg,
  160. ${p => p.theme.backgroundSecondary}00 0%,
  161. ${p => p.theme.backgroundSecondary}FF 70%,
  162. ${p => p.theme.backgroundSecondary}FF 100%
  163. );
  164. `;
  165. const CardContent = styled('div')`
  166. padding: ${space(2)};
  167. display: flex;
  168. flex-direction: column;
  169. gap: ${space(2)};
  170. align-items: flex-start;
  171. `;
  172. const CardDescription = styled('div')`
  173. display: flex;
  174. flex-direction: column;
  175. gap: ${space(1)};
  176. `;
  177. const CardTitle = styled('h3')`
  178. font-size: ${p => p.theme.fontSizeLarge};
  179. font-weight: 600;
  180. margin-bottom: 0;
  181. `;
  182. const CardIllustration = styled('img')`
  183. height: 100%;
  184. object-fit: contain;
  185. max-width: 30%;
  186. margin-bottom: -6px;
  187. margin-right: 10px;
  188. `;