11import { Fragment , useEffect } from 'react' ;
22import styled from '@emotion/styled' ;
33
4+ import { Button } from 'sentry/components/button' ;
45import {
56 type AutofixSetupRepoDefinition ,
67 type AutofixSetupResponse ,
78 useAutofixSetup ,
89} from 'sentry/components/events/autofix/useAutofixSetup' ;
10+ import { GuidedSteps } from 'sentry/components/guidedSteps/guidedSteps' ;
911import ExternalLink from 'sentry/components/links/externalLink' ;
1012import LoadingError from 'sentry/components/loadingError' ;
1113import LoadingIndicator from 'sentry/components/loadingIndicator' ;
1214import { IconCheckmark , IconGithub } from 'sentry/icons' ;
1315import { t , tct } from 'sentry/locale' ;
1416import { space } from 'sentry/styles/space' ;
17+ import type { Integration } from 'sentry/types/integrations' ;
1518import { trackAnalytics } from 'sentry/utils/analytics' ;
19+ import { useApiQuery } from 'sentry/utils/queryClient' ;
1620import useOrganization from 'sentry/utils/useOrganization' ;
1721
1822function AutofixIntegrationStep ( { autofixSetup} : { autofixSetup : AutofixSetupResponse } ) {
@@ -22,6 +26,9 @@ function AutofixIntegrationStep({autofixSetup}: {autofixSetup: AutofixSetupRespo
2226 { tct ( 'The GitHub integration is already installed, [link: view in settings].' , {
2327 link : < ExternalLink href = { `/settings/integrations/github/` } /> ,
2428 } ) }
29+ < GuidedSteps . ButtonWrapper >
30+ < GuidedSteps . NextButton />
31+ </ GuidedSteps . ButtonWrapper >
2532 </ Fragment >
2633 ) ;
2734 }
@@ -47,43 +54,23 @@ function AutofixIntegrationStep({autofixSetup}: {autofixSetup: AutofixSetupRespo
4754 }
4855 ) }
4956 </ p >
50- </ Fragment >
51- ) ;
52- }
53-
54- if ( autofixSetup . integration . reason === 'integration_no_code_mappings' ) {
55- return (
56- < Fragment >
57- < p >
58- { tct (
59- 'You have an active GitHub installation, but no code mappings for this project. Add code mappings by visiting the [link:integration settings page] and editing your configuration.' ,
60- {
61- link : < ExternalLink href = { `/settings/integrations/github/` } /> ,
62- }
63- ) }
64- </ p >
65- < p >
66- { tct (
67- 'Once added, come back to this page. For more information related to installing the GitHub integration, read the [link:documentation].' ,
68- {
69- link : (
70- < ExternalLink href = "https://docs.sentry.io/product/integrations/source-code-mgmt/github/" />
71- ) ,
72- }
73- ) }
74- </ p >
57+ < GuidedSteps . ButtonWrapper >
58+ < ExternalLink href = "/settings/integrations/github/" >
59+ < Button size = "sm" priority = "primary" >
60+ { t ( 'Set up Integration' ) }
61+ </ Button >
62+ </ ExternalLink >
63+ < GuidedSteps . NextButton />
64+ </ GuidedSteps . ButtonWrapper >
7565 </ Fragment >
7666 ) ;
7767 }
7868
7969 return (
8070 < Fragment >
8171 < p >
82- { tct (
83- 'Install the GitHub integration by navigating to the [link:integration settings page] and clicking the "Install" button. Follow the steps provided.' ,
84- {
85- link : < ExternalLink href = { `/settings/integrations/github/` } /> ,
86- }
72+ { t (
73+ 'Install the GitHub integration on the integration settings page and clicking the "Install" button. Follow the steps provided.'
8774 ) }
8875 </ p >
8976 < p >
@@ -96,6 +83,47 @@ function AutofixIntegrationStep({autofixSetup}: {autofixSetup: AutofixSetupRespo
9683 }
9784 ) }
9885 </ p >
86+ < GuidedSteps . ButtonWrapper >
87+ < ExternalLink href = "/settings/integrations/github/" >
88+ < Button size = "sm" priority = "primary" >
89+ { t ( 'Set up Integration' ) }
90+ </ Button >
91+ </ ExternalLink >
92+ < GuidedSteps . NextButton />
93+ </ GuidedSteps . ButtonWrapper >
94+ </ Fragment >
95+ ) ;
96+ }
97+
98+ function AutofixCodeMappingStep ( ) {
99+ const organization = useOrganization ( ) ;
100+ const { data : integrationConfigurations } = useApiQuery < Integration [ ] > (
101+ [
102+ `/organizations/${ organization . slug } /integrations/?provider_key=github&includeConfig=0` ,
103+ ] ,
104+ {
105+ staleTime : Infinity ,
106+ }
107+ ) ;
108+
109+ const configurationId = integrationConfigurations ?. at ( 0 ) ?. id ;
110+ const url = `/settings/integrations/github/${ configurationId ? configurationId + '/?tab=codeMappings' : '' } ` ;
111+
112+ return (
113+ < Fragment >
114+ < p >
115+ { t (
116+ 'Set up code mappings for the Github repositories you want to run Autofix on for this project.'
117+ ) }
118+ </ p >
119+ < GuidedSteps . ButtonWrapper >
120+ < GuidedSteps . BackButton />
121+ < ExternalLink href = { url } >
122+ < Button size = "sm" priority = "primary" >
123+ { configurationId ? t ( 'Configure Code Mappings' ) : t ( 'Configure Integration' ) }
124+ </ Button >
125+ </ ExternalLink >
126+ </ GuidedSteps . ButtonWrapper >
99127 </ Fragment >
100128 ) ;
101129}
@@ -122,34 +150,27 @@ export function GitRepoLink({repo}: {repo: AutofixSetupRepoDefinition}) {
122150 ) ;
123151}
124152
125- function SetupStep ( {
126- title,
127- isCompleted,
128- children,
129- } : {
130- children : React . ReactNode ;
131- isCompleted : boolean ;
132- title : string ;
133- } ) {
134- return (
135- < StepWrapper >
136- < StepHeader >
137- < StepTitle > { title } </ StepTitle >
138- { isCompleted && < IconCheckmark color = "success" size = "sm" /> }
139- </ StepHeader >
140- < div > { children } </ div >
141- </ StepWrapper >
142- ) ;
143- }
144-
145153function AutofixSetupSteps ( { autofixSetup} : { autofixSetup : AutofixSetupResponse } ) {
146154 return (
147- < SetupStep
148- title = { t ( 'Install the GitHub Integration' ) }
149- isCompleted = { autofixSetup . integration . ok }
150- >
151- < AutofixIntegrationStep autofixSetup = { autofixSetup } />
152- </ SetupStep >
155+ < GuidedSteps >
156+ < GuidedSteps . Step
157+ stepKey = "integration"
158+ title = { t ( 'Install the GitHub Integration' ) }
159+ isCompleted = {
160+ autofixSetup . integration . ok ||
161+ autofixSetup . integration . reason === 'integration_no_code_mappings'
162+ }
163+ >
164+ < AutofixIntegrationStep autofixSetup = { autofixSetup } />
165+ </ GuidedSteps . Step >
166+ < GuidedSteps . Step
167+ stepKey = "codeMappings"
168+ title = { t ( 'Set up Code Mappings' ) }
169+ isCompleted = { autofixSetup . integration . ok }
170+ >
171+ < AutofixCodeMappingStep />
172+ </ GuidedSteps . Step >
173+ </ GuidedSteps >
153174 ) ;
154175}
155176
@@ -237,22 +258,3 @@ const Divider = styled('div')`
237258 margin: ${ space ( 3 ) } 0;
238259 border-bottom: 2px solid ${ p => p . theme . gray100 } ;
239260` ;
240-
241- const StepWrapper = styled ( 'div' ) `
242- margin-top: ${ space ( 3 ) } ;
243- padding-left: ${ space ( 2 ) } ;
244- border-left: 2px solid ${ p => p . theme . border } ;
245- ` ;
246-
247- const StepHeader = styled ( 'div' ) `
248- display: flex;
249- align-items: center;
250- gap: ${ space ( 1 ) } ;
251- margin-bottom: ${ space ( 1 ) } ;
252- ` ;
253-
254- const StepTitle = styled ( 'p' ) `
255- font-size: ${ p => p . theme . fontSizeMedium } ;
256- font-weight: 600;
257- margin: 0;
258- ` ;
0 commit comments