@@ -172,17 +172,61 @@ if (syncStatusCloseBtn != null) {
172
172
} ;
173
173
}
174
174
175
- const handleDisconnectRequest = ( path , data ) => {
175
+ const handleDisconnectRequest = ( path , data , callback ) => {
176
+ $ ( ".modal__header__container" ) . hide ( ) ;
177
+ $ ( ".modal__information" ) . hide ( ) ;
178
+ $ ( ".modal__footer" ) . hide ( ) ;
179
+ $ ( ".modal__spinner" ) . removeClass ( "hidden" ) ;
180
+
176
181
$ . ajax ( {
177
182
type : "DELETE" ,
178
183
url : path ,
179
184
data,
180
185
success : function ( ) {
181
- AP . navigator . reload ( ) ;
186
+ // For deleting GH server or a GH server app
187
+ if ( callback ) {
188
+ callback ( ) ;
189
+ $ ( ".modal__spinner" ) . addClass ( "hidden" ) ;
190
+ $ ( ".modal__information" ) . show ( ) ;
191
+ $ ( ".modal__header__container" ) . show ( ) ;
192
+ $ ( ".modal__footer" ) . show ( ) ;
193
+ } else { // For deleting an individual GH server app connection
194
+ AP . navigator . reload ( ) ;
195
+ }
182
196
} ,
183
197
error : function ( error ) {
184
198
// TODO - we should render an error here when the app fails to delete
185
- } ,
199
+ console . error ( "Failed: " , error ) ;
200
+ }
201
+ } ) ;
202
+ }
203
+
204
+ const deleteAppsInGitHub = ( GHEServerUrl , appName ) => {
205
+ $ ( ".modal__header__icon" ) . remove ( ) ;
206
+ let content = "" ;
207
+ if ( ! appName ) {
208
+ // Get the list of all the apps within the GH Enterprise server
209
+ const apps = $ ( `.jiraConfiguration__enterpriseServer__header__container[data-server-baseurl='${ GHEServerUrl } '] + .jiraConfiguration__enterpriseConnections > details` ) ;
210
+ if ( $ ( apps ) . length > 0 ) {
211
+ $ ( ".modal__header__title" ) . empty ( ) . append ( "Server disconnected" ) ;
212
+ content += "<p style='margin-bottom: 12px;'>You can now delete these unused apps from your GitHub server. Select the app, then in GitHub select <b>Delete GitHub app</b>.</p>" ;
213
+ $ ( apps ) . map ( ( index , app ) => {
214
+ const serverAppName = $ ( app ) . find ( ".jiraConfiguration__optionHeader" ) . text ( ) ;
215
+ content += `<span style="margin-right: 12px">•</span><a target="_blank" href="${ GHEServerUrl } /settings/apps/${ serverAppName } /advanced">${ serverAppName } </a><br/>` ;
216
+ } ) ;
217
+ }
218
+ } else {
219
+ $ ( ".modal__header__title" ) . empty ( ) . append ( "App disconnected" ) ;
220
+ content += `<p style='margin-bottom: 12px;'>To delete this app from your GitHub server, <a target=\"_blank\" href=\"${ GHEServerUrl } /settings/apps/${ appName } /advanced\">go to the app in GitHub</a> and select <b>Delete GitHub App</b>.</p>` ;
221
+ }
222
+
223
+ $ ( ".modal__information" ) . empty ( ) . append ( content ) ;
224
+
225
+ // Adding a close button which refreshes the iframe
226
+ $ ( ".modal__footer" ) . empty ( )
227
+ . append ( "<button class=\"aui-button aui-button-primary modal__footer__close\">Close</button>" ) ;
228
+ $ ( ".modal__footer__close" ) . click ( ( ) => {
229
+ AP . navigator . reload ( ) ;
186
230
} ) ;
187
231
}
188
232
@@ -192,19 +236,26 @@ const mapDisconnectRequest = (disconnectType, data) => {
192
236
jwt : token ,
193
237
jiraHost
194
238
}
239
+ // Replacing single quotes by double in order to parse the JSON properly
240
+ const parsedData = JSON . parse ( data . replace ( / ' / g, '"' ) ) ;
195
241
196
242
switch ( disconnectType ) {
197
243
case "server" :
198
- payload . serverUrl = data . disconnectData ;
199
- handleDisconnectRequest ( `/jira/connect/enterprise` , payload ) ;
244
+ payload . serverUrl = parsedData . serverUrl ;
245
+ handleDisconnectRequest ( `/jira/connect/enterprise` , payload , ( ) => {
246
+ deleteAppsInGitHub ( parsedData . serverUrl ) ;
247
+ } ) ;
200
248
return ;
201
249
case "app" :
202
- payload . uuid = data . disconnectData ;
203
- handleDisconnectRequest ( `/jira/connect/enterprise/app/${ payload . uuid } ` , payload ) ;
250
+ payload . uuid = parsedData . uuid ;
251
+ handleDisconnectRequest ( `/jira/connect/enterprise/app/${ payload . uuid } ` , payload , ( ) => {
252
+ deleteAppsInGitHub ( parsedData . serverUrl , parsedData . appName ) ;
253
+ } ) ;
254
+ deleteAppsInGitHub ( parsedData ) ;
204
255
return ;
205
256
default :
206
- payload . gitHubInstallationId = data . disconnectData ;
207
- payload . appId = data . optionalDisconnectData ;
257
+ payload . gitHubInstallationId = parsedData . gitHubInstallationId ;
258
+ payload . appId = parsedData . appId ;
208
259
handleDisconnectRequest ( "/jira/configuration" , payload ) ;
209
260
return ;
210
261
}
@@ -215,9 +266,7 @@ if (genericModalAction != null) {
215
266
$ ( genericModalAction ) . click ( ( event ) => {
216
267
event . preventDefault ( ) ;
217
268
const disconnectType = $ ( event . target ) . data ( "disconnect-type" ) ;
218
- const disconnectData = $ ( event . target ) . data ( "modal-data" ) ;
219
- const optionalDisconnectData = $ ( event . target ) . data ( "optional-modal-data" ) ;
220
- const data = { disconnectData, optionalDisconnectData }
269
+ const data = $ ( event . target ) . data ( "modal-data" ) ;
221
270
mapDisconnectRequest ( disconnectType , data ) ;
222
271
} ) ;
223
272
}
@@ -227,24 +276,25 @@ const handleModalDisplay = (title, info, type, data) => {
227
276
$ ( ".modal__header__icon" ) . addClass ( "aui-iconfont-warning" ) . empty ( ) . append ( "Warning icon" ) ;
228
277
$ ( ".modal__header__title" ) . empty ( ) . append ( title ) ;
229
278
$ ( ".modal__information" ) . empty ( ) . append ( info ) ;
279
+
280
+ // Modal data is a JSON, so stringified using single quotes
281
+ const stringifiedData = JSON . stringify ( data . modalData ) . replace ( / " / g, "'" ) ;
230
282
$ ( ".modal__footer__actionBtn" )
231
283
. empty ( )
232
284
. append ( "Disconnect" )
233
285
. attr ( "data-disconnect-type" , type )
234
- . attr ( "data-modal-data" , data . modalData )
235
- . attr ( "data-optional-modal-data" , data . appId ) ;
286
+ . attr ( "data-modal-data" , stringifiedData ) ;
236
287
}
237
288
238
289
if ( disconnectServerBtn != null ) {
239
290
$ ( disconnectServerBtn ) . click ( ( event ) => {
240
291
event . preventDefault ( ) ;
241
292
const serverUrl = $ ( event . target ) . data ( "server-baseurl" ) ;
242
- const modalTitle = "Disconnect server?" ;
243
- const modalInfo = "Are you sure you want to disconnect your server? You 'll need to recreate your GitHub apps and backfill historical data from your GitHub organisations and repositories again if you ever want to reconnect ."
293
+ const modalTitle = "Are you sure you want to disconnect this server?" ;
294
+ const modalInfo = "To reconnect this server, you 'll need to create new GitHub apps and import data about its organizations and repositories again."
244
295
const disconnectType = "server" ;
245
- const data = { modalData : serverUrl }
296
+ const data = { modalData : { serverUrl } }
246
297
handleModalDisplay ( modalTitle , modalInfo , disconnectType , data ) ;
247
- $ ( ".modal__additionalContent" ) . append ( serverUrl ) . css ( 'font-weight' , 'bold' ) ;
248
298
} ) ;
249
299
}
250
300
@@ -253,10 +303,11 @@ if (disconnectAppBtn != null) {
253
303
event . preventDefault ( ) ;
254
304
const appName = $ ( event . target ) . data ( "app-name" ) ;
255
305
const uuid = $ ( event . target ) . data ( "app-uuid" ) ;
256
- const modalTitle = `Disconnect ${ appName } ?` ;
257
- const modalInfo = `Are you sure you want to delete your application, ${ appName } ? You’ll need to backfill your historical data again if you ever want to reconnect.` ;
306
+ const serverUrl = $ ( event . target ) . data ( "app-server-url" ) ;
307
+ const modalTitle = `Are you sure you want to disconnect this app?` ;
308
+ const modalInfo = `To reconnect this app, you'll need to recreate it and import data about its organizations and repositories again.` ;
258
309
const disconnectType = "app" ;
259
- const data = { modalData : uuid }
310
+ const data = { modalData : { uuid, appName , serverUrl } }
260
311
handleModalDisplay ( modalTitle , modalInfo , disconnectType , data ) ;
261
312
} ) ;
262
313
}
@@ -271,7 +322,7 @@ if (disconnectOrgBtn != null) {
271
322
const modalTitle = `Disconnect ${ displayName } ?` ;
272
323
const modalInfo = `Are you sure you want to disconnect your organization ${ displayName } ? This means that you will have to redo the backfill of historical data if you ever want to reconnect.` ;
273
324
const disconnectType = "org" ;
274
- const data = { modalData : gitHubInstallationId , appId } ;
325
+ const data = { modalData : { gitHubInstallationId, appId } } ;
275
326
handleModalDisplay ( modalTitle , modalInfo , disconnectType , data ) ;
276
327
} ) ;
277
328
}
@@ -281,7 +332,6 @@ if (genericModalClose != null) {
281
332
event . preventDefault ( ) ;
282
333
$ ( genericModal ) . hide ( ) ;
283
334
$ ( ".modal__footer__actionBtn" ) . removeAttr ( "data-disconnect-type" ) ;
284
- $ ( ".modal__additionalContent" ) . empty ( ) ;
285
335
} ) ;
286
336
}
287
337
0 commit comments