22 <div v-if =" $resources.options.loading" class =" mt-2 flex justify-center" >
33 <LoadingText />
44 </div >
5- <div class =" flex justify-center pt-2" v-else-if =" !options?.authorized" >
6- <Button
7- v-if =" requiresReAuth "
8- variant="solid"
9- icon-left="github"
10- label="Re-authorize GitHub"
11- @click =" $resources .clearAccessToken .submit ()"
12- :loading =" $resources .clearAccessToken .loading "
13- />
14- <Button
15- v-if =" needsAuthorization "
16- variant="solid"
17- icon-left="github"
18- label="Connect To GitHub"
19- :link =" installationLink "
20- />
5+ <div class =" pt-2" v-else-if =" !options?.authorized" >
6+ <div v-if =" !!needsAuthorization" class =" flex justify-center" >
7+ <Button
8+ variant="solid"
9+ icon-left="github"
10+ label="Connect To GitHub"
11+ :link =" installationLink "
12+ />
13+ </div >
14+ <div v-else-if =" !!requiresReAuth" class =" flex justify-center" >
15+ <Button
16+ variant="solid"
17+ icon-left="github"
18+ label="Re-authorize GitHub"
19+ @click =" $resources .clearAccessToken .submit ()"
20+ :loading =" $resources .clearAccessToken .loading "
21+ />
22+ </div >
23+ <div
24+ v-else-if =" $resources.options.error?.messages?.[0]"
25+ class =" flex flex-row justify-center"
26+ >
27+ <ErrorMessage :message =" $resources .options .error ?.messages ?.[0 ]" />
28+ </div >
2129 </div >
2230 <div v-else class =" space-y-4" >
2331 <FormControl
117125</template >
118126
119127<script >
120- import { Combobox , debounce } from ' frappe-ui' ;
128+ import { Combobox , debounce } from ' frappe-ui'
121129
122130export default {
123131 components: {
@@ -130,31 +138,31 @@ export default {
130138 selectedBranch: null ,
131139 selectedGithubUser: null ,
132140 selectedGithubRepository: null ,
133- };
141+ }
134142 },
135143 watch: {
136144 selectedGithubUser () {
137- this .selectedBranch = ' ' ;
138- this .$emit (' fieldChange' );
145+ this .selectedBranch = ' '
146+ this .$emit (' fieldChange' )
139147 },
140148 selectedGithubRepository (repo ) {
141149 if (! repo) {
142- this .selectedBranch = ' ' ;
143- return ;
150+ this .selectedBranch = ' '
151+ return
144152 }
145- this .$emit (' fieldChange' );
153+ this .$emit (' fieldChange' )
146154 this .$resources .branches .submit ({
147155 owner: this .selectedGithubUser ? .login ,
148156 name: repo? .name ,
149157 installation: this .selectedGithubUser ? .id ,
150- });
158+ })
151159
152160 if (this .selectedGithubUserData ) {
153161 let defaultBranch = this .selectedGithubUserData .repos .find (
154162 (r ) => r .name === repo .name ,
155- ).default_branch ;
156- this .selectedBranch = { label: defaultBranch, value: defaultBranch };
157- } else this .selectedBranch = ' ' ;
163+ ).default_branch
164+ this .selectedBranch = { label: defaultBranch, value: defaultBranch }
165+ } else this .selectedBranch = ' '
158166 },
159167 selectedBranch (newSelectedBranch ) {
160168 if (this .appOwner && this .appName && newSelectedBranch)
@@ -163,7 +171,7 @@ export default {
163171 repository: this .appName ,
164172 branch: newSelectedBranch .value ,
165173 selectedGithubUser: this .selectedGithubUserData ,
166- });
174+ })
167175 },
168176 },
169177 resources: {
@@ -173,82 +181,82 @@ export default {
173181 makeParams () {
174182 return {
175183 redirect_url: window .location .href ,
176- };
184+ }
177185 },
178186 auto: true ,
179- };
187+ }
180188 },
181189 branches () {
182190 return {
183191 url: ' press.api.github.branches' ,
184- };
192+ }
185193 },
186194 clearAccessToken () {
187195 return {
188196 url: ' press.api.github.clear_token_and_get_installation_url' ,
189197 makeParams () {
190198 return {
191199 redirect_url: window .location .href ,
192- };
200+ }
193201 },
194202 onSuccess (installationData ) {
195- window .location .href = this .getInstallationLink (installationData);
203+ window .location .href = this .getInstallationLink (installationData)
196204 },
197- };
205+ }
198206 },
199207 },
200208 methods: {
201209 getInstallationLink (installationData ) {
202210 if (! installationData? .installation_url || ! installationData? .state ) {
203- return null ;
211+ return null
204212 }
205213
206- return ` ${ installationData .installation_url } ?state=${ installationData .state } ` ;
214+ return ` ${ installationData .installation_url } ?state=${ installationData .state } `
207215 },
208216 },
209217 computed: {
210218 options () {
211- return this .$resources .options .data ;
219+ return this .$resources .options .data
212220 },
213221 installationLink () {
214- return this .getInstallationLink (this .options );
222+ return this .getInstallationLink (this .options )
215223 },
216224 appOwner () {
217- return this .selectedGithubUser ? .login ;
225+ return this .selectedGithubUser ? .login
218226 },
219227 appName () {
220- return this .selectedGithubRepository ? .name ;
228+ return this .selectedGithubRepository ? .name
221229 },
222230 branchOptions () {
223231 return (this .$resources .branches .data || []).map ((branch ) => ({
224232 label: branch .name ,
225233 value: branch .name ,
226- }));
234+ }))
227235 },
228236 selectedGithubUserData () {
229- if (! this .selectedGithubUser ) return null ;
237+ if (! this .selectedGithubUser ) return null
230238 return this .options .installations .find (
231239 (i ) => i .id === Number (this .selectedGithubUser .id ),
232- );
240+ )
233241 },
234242 needsAuthorization () {
235- if (this .$resources .options .loading ) return false ;
243+ if (this .$resources .options .loading ) return false
236244 return (
237245 this .$resources .options .data &&
238246 (! this .$resources .options .data .authorized ||
239247 this .$resources .options .data .installations .length === 0 )
240- );
248+ )
241249 },
242250 requiresReAuth () {
243- return this .$resources .options ? .error ? .messages .some (( msg ) =>
244- msg .includes (' Bad credentials' ),
245- );
251+ return this .$resources .options ? .error ? .messages ? .some (
252+ ( msg ) => msg . includes && msg .includes (' Bad credentials' ),
253+ )
246254 },
247255 },
248256 created () {
249257 this .onChangeBranchDebounce = debounce ((val ) => {
250- this .selectedBranch = { label: val, value: val };
251- }, 500 );
258+ this .selectedBranch = { label: val, value: val }
259+ }, 500 )
252260 },
253- };
261+ }
254262< / script>
0 commit comments