Skip to content

Commit b71dd01

Browse files
authored
use jenkins buttons and dialog (#1597)
small UI update for the access tokens replace yui-button with jenkins-button to be synv with the overall jenkins styling Use a dialog to confirm revocation of access tokens
1 parent 2b86b58 commit b71dd01

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

src/main/resources/hudson/plugins/git/ApiTokenPropertyConfiguration/config.jelly

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
<div class="api-token-list-item-row api-token-list-existing-token">
1717
<f:textbox readonly="true" value="${apiToken.name}" />
1818
<!-- onclick handler for that button is defined in resources.js -->
19-
<a href="#" class="yui-button api-token-revoke-button"
19+
<button type="button" class="jenkins-button api-token-revoke-button"
2020
data-confirm="${%Are you sure you want to revoke this access token?}"
2121
data-target-url="${descriptor.descriptorFullUrl}/revoke">
2222
${%Revoke}
23-
</a>
23+
</button>
2424
</div>
2525
</j:when>
2626
<j:otherwise>
@@ -29,23 +29,21 @@
2929
<input type="hidden" class="api-token-uuid-input" name="apiTokenUuid" value="${apiToken.uuid}" />
3030
<f:textbox clazz="api-token-name-input" name="apiTokenName" placeholder="${%Access token name}"/>
3131
<span class="new-api-token-value hidden"><!-- to be filled by JS --></span>
32-
<span class="yui-button api-token-save-button">
33-
<!-- onclick handler for that button is defined in resources.js -->
34-
<button type="button" tabindex="0" data-target-url="${descriptor.descriptorFullUrl}/generate">
35-
${%Generate}
36-
</button>
37-
</span>
38-
<span class="api-token-cancel-button">
39-
<f:repeatableDeleteButton value="${%Cancel}" />
40-
</span>
32+
<!-- onclick handler for that button is defined in resources.js -->
33+
<button type="button" class="jenkins-button api-token-save-button" tabindex="0" data-target-url="${descriptor.descriptorFullUrl}/generate">
34+
${%Generate}
35+
</button>
4136
<l:copyButton message="${%Copied}" text="" clazz="hidden" tooltip="${%Copy to clipboard}" />
4237
<!-- onclick handler for that button is defined in resources.js -->
43-
<a href="#" class="yui-button api-token-revoke-button hidden"
38+
<button type="button" class="jenkins-button api-token-revoke-button hidden"
4439
data-confirm="${%Are you sure you want to revoke this access token?}"
4540
data-target-url="${descriptor.descriptorFullUrl}/revoke">
4641
${%Revoke}
47-
</a>
42+
</button>
4843
</div>
44+
<span class="api-token-cancel-button">
45+
<f:repeatableDeleteButton value="${%Cancel}" />
46+
</span>
4947
<span class="warning api-token-warning-message hidden">${%Access token will only be displayed once.}</span>
5048
</div>
5149
</j:otherwise>

src/main/resources/hudson/plugins/git/ApiTokenPropertyConfiguration/resources.css

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22
display: flex;
33
align-items: center;
44
max-width: 700px;
5-
}
6-
.api-token-list .api-token-list-item-row.api-token-list-existing-api-token {
7-
justify-content: space-between;
5+
gap: 10px;
86
}
97
.api-token-list .api-token-list-item .hidden, .api-token-list .api-token-list-empty-item.hidden {
108
display: none;
119
}
1210

13-
.api-token-list .api-token-revoke-button, .api-token-list .new-api-token-value {
14-
padding: 0 0.5rem;
15-
}
16-
.api-token-list .api-token-warning-message, .api-token-list .api-token-save-button {
17-
margin: 0.5rem 0;
18-
}

src/main/resources/hudson/plugins/git/ApiTokenPropertyConfiguration/resources.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function revokeApiToken(anchorRevoke) {
1919
const inputUuid = repeatedChunk.querySelector('.api-token-uuid-input');
2020
const apiTokenUuid = inputUuid.value;
2121

22-
if (confirm(confirmMessage)) {
22+
dialog.confirm(confirmMessage).then( () => {
2323
fetch(targetUrl, {
2424
headers: crumb.wrap({
2525
"Content-Type": "application/x-www-form-urlencoded",
@@ -32,21 +32,20 @@ function revokeApiToken(anchorRevoke) {
3232
adjustEmptyListMessage(apiTokenList);
3333
}
3434
});
35-
}
35+
});
3636

3737
return false;
3838
}
3939

4040
/**
4141
* Registering the onclick handler on all the "Generate" buttons for API Token.
4242
*/
43-
Behaviour.specify(".api-token-save-button", 'ApiTokenPropertyConfiguration', 0, function(buttonContainer) {
43+
Behaviour.specify(".api-token-save-button", 'ApiTokenPropertyConfiguration', 0, function(button) {
4444
// DEV MEMO:
4545
// While un-inlining the onclick handler, we are trying to avoid modifying the existing source code and functions.
4646
// In order to keep consistency with the existing code, we add our onclick handler on the button element which is contained in the
4747
// api-token-save-button that we identify. While this could be refactored to directly identify the button, this would need to be done in an other
4848
// contribution.
49-
const button = buttonContainer.getElementsByTagName('button')[0];
5049
button.onclick = (_) => saveApiToken(button);
5150
})
5251

0 commit comments

Comments
 (0)