Skip to content

Commit 1e5043d

Browse files
ARC-1634 - [GHE] When removing the app from dashboard, give them link to delete app in Github (#2478)
* - Added GH links to delete GHE apps * - Added GH links to delete GHE apps * - Changing according to the UI * - Cleanup * - Text changes * - Minor tweaks * - Revert * - Revert * - CSS fixes --------- Co-authored-by: joshkay10 <josh.kay@outlook.com>
1 parent 8307217 commit 1e5043d

File tree

4 files changed

+90
-27
lines changed

4 files changed

+90
-27
lines changed

static/css/global.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ a:focus {
210210
position: absolute;
211211
transform: translateX(-50%);
212212
z-index: 1000;
213+
max-width: 600px;
213214
}
214215

215216
.jiraConfiguration__syncRetryModalContent,
@@ -263,6 +264,12 @@ a:focus {
263264
margin-top: 1em;
264265
}
265266

267+
.modal__spinner {
268+
display: flex;
269+
justify-content: center;
270+
vertical-align: middle;
271+
}
272+
266273
.modal__footer__actionBtn {
267274
--aui-btn-bg: #FFAB00;
268275
--aui-btn-text: #172B4D;
@@ -274,8 +281,12 @@ a:focus {
274281
margin-bottom: 1em;
275282
}
276283

284+
.modal__header__icon {
285+
margin-right: 6px;
286+
}
287+
277288
.modal__header__title {
278-
margin: 0 0 0 0.5em;
289+
margin: 0;
279290
}
280291

281292
/* Navigation */

static/js/jira-configuration.js

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,61 @@ if (syncStatusCloseBtn != null) {
172172
};
173173
}
174174

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+
176181
$.ajax({
177182
type: "DELETE",
178183
url: path,
179184
data,
180185
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+
}
182196
},
183197
error: function (error) {
184198
// 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">&#8226;</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();
186230
});
187231
}
188232

@@ -192,19 +236,26 @@ const mapDisconnectRequest = (disconnectType, data) => {
192236
jwt: token,
193237
jiraHost
194238
}
239+
// Replacing single quotes by double in order to parse the JSON properly
240+
const parsedData = JSON.parse(data.replace(/'/g, '"'));
195241

196242
switch (disconnectType) {
197243
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+
});
200248
return;
201249
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);
204255
return;
205256
default:
206-
payload.gitHubInstallationId = data.disconnectData;
207-
payload.appId = data.optionalDisconnectData;
257+
payload.gitHubInstallationId = parsedData.gitHubInstallationId;
258+
payload.appId = parsedData.appId;
208259
handleDisconnectRequest("/jira/configuration", payload);
209260
return;
210261
}
@@ -215,9 +266,7 @@ if (genericModalAction != null) {
215266
$(genericModalAction).click((event) => {
216267
event.preventDefault();
217268
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");
221270
mapDisconnectRequest(disconnectType, data);
222271
});
223272
}
@@ -227,24 +276,25 @@ const handleModalDisplay = (title, info, type, data) => {
227276
$(".modal__header__icon").addClass("aui-iconfont-warning").empty().append("Warning icon");
228277
$(".modal__header__title").empty().append(title);
229278
$(".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, "'");
230282
$(".modal__footer__actionBtn")
231283
.empty()
232284
.append("Disconnect")
233285
.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);
236287
}
237288

238289
if (disconnectServerBtn != null) {
239290
$(disconnectServerBtn).click((event) => {
240291
event.preventDefault();
241292
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."
244295
const disconnectType = "server";
245-
const data = { modalData: serverUrl }
296+
const data = { modalData: { serverUrl } }
246297
handleModalDisplay(modalTitle, modalInfo, disconnectType, data);
247-
$(".modal__additionalContent").append(serverUrl).css('font-weight', 'bold');
248298
});
249299
}
250300

@@ -253,10 +303,11 @@ if (disconnectAppBtn != null) {
253303
event.preventDefault();
254304
const appName = $(event.target).data("app-name");
255305
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.`;
258309
const disconnectType = "app";
259-
const data = { modalData: uuid }
310+
const data = { modalData: { uuid, appName, serverUrl } }
260311
handleModalDisplay(modalTitle, modalInfo, disconnectType, data);
261312
});
262313
}
@@ -271,7 +322,7 @@ if (disconnectOrgBtn != null) {
271322
const modalTitle = `Disconnect ${displayName}?`;
272323
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.`;
273324
const disconnectType = "org";
274-
const data = { modalData: gitHubInstallationId, appId };
325+
const data = { modalData: { gitHubInstallationId, appId } };
275326
handleModalDisplay(modalTitle, modalInfo, disconnectType, data);
276327
});
277328
}
@@ -281,7 +332,6 @@ if (genericModalClose != null) {
281332
event.preventDefault();
282333
$(genericModal).hide();
283334
$(".modal__footer__actionBtn").removeAttr("data-disconnect-type");
284-
$(".modal__additionalContent").empty();
285335
});
286336
}
287337

views/jira-configuration.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
<button
252252
class="jiraConfiguration__deleteGitHubApp disconnect-app-btn"
253253
data-app-uuid="{{app.uuid}}"
254+
data-app-server-url="{{server.gitHubBaseUrl}}"
254255
data-app-name="{{app.gitHubAppName}}"
255256
>
256257
Disconnect

views/partials/modal.hbs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
<p class="modal__information"></p>
99

10-
<p class="modal__additionalContent"></p>
11-
1210
<div class="modal__footer">
1311
<button class="aui-button aui-button-subtle modal__footer__close" id="modal-close-btn">Cancel</button>
1412
<button class="aui-button aui-button-subtle modal__footer__actionBtn" id="modal-action-btn"></button>
1513
</div>
16-
</div>
1714

15+
<div class="modal__spinner hidden">
16+
<aui-spinner size="medium"></aui-spinner>
17+
</div>
18+
</div>
1819
<div class="modal__modalOverlay"></div>
1920
</div>

0 commit comments

Comments
 (0)