Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Commit 17f50cb

Browse files
author
Itay Neeman
committed
Move button actions into a dropdown rather than individual buttons
Previously, PRNFB would end up creating a separate button for each action, which in turn would cause wrapping of the buttons and overall not looking good, or being very usable if you had more than one or two buttons. This change moves them into a dropdown, making it a lot more compact and a lot easier to add multiple actions.
1 parent f016b29 commit 17f50cb

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

src/main/resources/pr-triggerbutton.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,54 @@ define('plugin/prnfb/pr-triggerbutton', [
88
return AJS.contextPath() + '/rest/prnfb-admin/1.0/manual/?repositoryId=' + pageState.getRepository().id + '&pullRequestId=' + pageState.getPullRequest().id;
99
};
1010

11-
var waiting = '<span class="aui-icon aui-icon-wait">Wait</span>';
11+
var waiting = '<span class="aui-icon aui-icon-wait aui-icon-small">Wait</span>';
1212

1313
var $buttonArea = $(".triggerManualNotification").parent();
1414
var $buttonTemplate = $(".triggerManualNotification");
1515
$buttonTemplate.empty().remove();
1616

17+
$buttonDropdownArea = $('<div id="triggerManualNotification-actions" class="aui-style-default aui-dropdown2"><ul class="aui-list-truncate"></ul></div>');
18+
$buttonDropdownItems = $buttonDropdownArea.find("ul");
19+
20+
var $buttonDropdownParent = $buttonTemplate.clone();
21+
$buttonDropdownParent.html("Actions");
22+
$buttonDropdownParent.attr("aria-owns", "triggerManualNotification-actions");
23+
$buttonDropdownParent.attr("aria-haspopup", "true");
24+
$buttonDropdownParent.addClass("aui-style-default aui-dropdown2-trigger");
25+
$buttonArea.append($buttonDropdownParent);
26+
$buttonDropdownParent.hide();
27+
28+
$("body").append($buttonDropdownArea)
29+
1730
function loadSettingsAndShowButtons() {
31+
var hasButtons = false;
32+
$buttonDropdownItems.empty();
1833
$.get(getResourceUrl(), function(settings) {
1934
settings.forEach(function(item) {
20-
var $button = $buttonTemplate.clone();
21-
$button.html(item.title);
22-
$button.click(function() {
35+
hasButtons = true;
36+
37+
var $buttonDropdownItem = $('<li><a class="aui-icon-container" href="#">' + item.title + '</a></li>');
38+
$buttonDropdownItem.find("a").click(function() {
2339
var $this = $(this);
24-
var text = $this.text();
25-
26-
$this.attr("disabled", "disabled").html(waiting + " " + text);
27-
40+
$this.attr("disabled", "disabled");
41+
$this.attr("aria-disabled", "true");
42+
$this.prepend(waiting);
43+
2844
$.post(getResourceUrl()+'&formIdentifier='+item.formIdentifier, function() {
2945
setTimeout(function() {
30-
$this.removeAttr("disabled").text(text);
46+
$this.removeAttr("disabled");
47+
$this.removeAttr("aria-disabled");
48+
$this.find("span").remove();
3149
}, 500);
3250
});
33-
34-
return false;
3551
});
3652

37-
$buttonArea.append($button);
53+
$buttonDropdownItems.append($buttonDropdownItem);
3854
});
55+
56+
if (hasButtons) {
57+
$buttonDropdownParent.show();
58+
}
3959
});
4060
}
4161

@@ -44,7 +64,7 @@ define('plugin/prnfb/pr-triggerbutton', [
4464
//If a reviewer approves the PR, then a button may become visible
4565
$('.aui-button.approve').click(function () {
4666
setTimeout(function(){
47-
$(".triggerManualNotification").remove();
67+
$buttonDropdownParent.hide();
4868
loadSettingsAndShowButtons();
4969
}, 1000);
5070
});

0 commit comments

Comments
 (0)