Skip to content

Commit d6e2c7c

Browse files
authored
Refine Add button for repeatable lists (#10913)
* Refine repeatable list Add button * Update hetero-list.js * Update HeteroListTest.java * Update RepeatableTest.java * Trigger Build * Update ath.sh
1 parent 0a1261d commit d6e2c7c

File tree

7 files changed

+28
-10
lines changed

7 files changed

+28
-10
lines changed

core/src/main/resources/lib/form/hetero-list.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ THE SOFTWARE.
154154

155155
<j:if test="${!readOnlyMode}">
156156
<div>
157-
<button type="button" class="jenkins-button hetero-list-add" menualign="${attrs.menuAlign}" suffix="${attrs.name}">${attrs.addCaption?:'%Add'}<l:icon src="symbol-chevron-down"/>
157+
<button type="button" class="jenkins-button hetero-list-add" menualign="${attrs.menuAlign}" suffix="${attrs.name}"><l:icon src="symbol-add"/>${attrs.addCaption?:'%Add'}
158158
</button>
159159
</div>
160160
</j:if>

core/src/main/resources/lib/form/repeatable.jelly

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ THE SOFTWARE.
2323
-->
2424

2525
<?jelly escape-by-default='true'?>
26-
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
26+
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout">
2727
<st:documentation> <![CDATA[
2828
Repeatable blocks used to present UI where the user can configure multiple entries
2929
of the same kind (see the Java installations configuration in the system config.)
@@ -143,6 +143,7 @@ THE SOFTWARE.
143143
</div>
144144
<j:if test="${!empty(items) and !attrs.noAddButton and attrs.enableTopButton}">
145145
<button type="button" class="jenkins-button repeatable-add repeatable-add-top">
146+
<l:icon src="symbol-add"/>
146147
${attrs.add?:'%Add'}
147148
</button>
148149
</j:if>
@@ -173,6 +174,7 @@ THE SOFTWARE.
173174
<div class="repeatable-insertion-point" />
174175
<j:if test="${!attrs.noAddButton}">
175176
<button type="button" class="jenkins-button repeatable-add">
177+
<l:icon src="symbol-add"/>
176178
${attrs.add?:'%Add'}
177179
</button>
178180
</j:if>

src/main/js/components/dropdowns/hetero-list.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ function generateButtons() {
167167

168168
let oneEach = e.classList.contains("one-each");
169169

170+
/**
171+
* Disable the Add button if there are no more items to add
172+
*/
173+
function toggleButtonState() {
174+
const templateCount = templates.length;
175+
const selectedCount = Array.from(e.children).filter((e) =>
176+
e.classList.contains("repeated-chunk"),
177+
).length;
178+
179+
btn.disabled = oneEach && selectedCount === templateCount;
180+
}
181+
const observer = new MutationObserver(() => {
182+
toggleButtonState();
183+
});
184+
observer.observe(e, { childList: true });
185+
toggleButtonState();
186+
170187
generateDropDown(btn, (instance) => {
171188
let menuItems = [];
172189
for (let i = 0; i < templates.length; i++) {

src/main/scss/components/_buttons.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@
230230
}
231231
}
232232

233-
.advanced-button,
234-
.hetero-list-add {
233+
.advanced-button {
235234
svg {
236235
width: 0.875rem;
237236
height: 0.875rem;

src/main/scss/components/_dropdowns.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ $dropdown-padding: 0.375rem;
117117
&__disabled {
118118
color: var(--text-color-secondary) !important;
119119
font-size: 0.8125rem;
120-
opacity: 0.8;
120+
opacity: 0.5;
121121
display: inline-flex;
122122
align-items: center;
123123
margin: 0;
124-
cursor: default;
124+
cursor: not-allowed;
125125
}
126126

127127
&__item {

test/src/test/java/lib/form/HeteroListTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void xssPrevented_heteroList_usingDescriptorDisplayName() throws Exception {
8686
assertThat(result, instanceOf(HTMLButtonElement.class));
8787
HTMLButtonElement menuItem = (HTMLButtonElement) result;
8888
String menuItemContent = menuItem.getInnerHTML();
89-
assertThat(menuItemContent, not(containsString("<")));
89+
assertThat(menuItemContent, not(containsString("<img")));
9090
}
9191

9292
@Test
@@ -100,7 +100,7 @@ void xssPrevented_usingToolInstallation_repeatableAddExisting() throws Exception
100100
Object result = page.executeJavaScript("Array.from(document.querySelectorAll('button')).filter(b => b.textContent.indexOf('Add XSS') !== -1)[0].innerHTML").getJavaScriptResult();
101101
assertThat(result, instanceOf(String.class));
102102
String resultString = (String) result;
103-
assertThat(resultString, not(containsString("<")));
103+
assertThat(resultString, not(containsString("<img")));
104104
}
105105

106106
// only possible after a partial fix
@@ -121,7 +121,7 @@ void xssPrevented_usingToolInstallation_repeatableAddAfterClick() throws Excepti
121121
Object result = page.executeJavaScript("Array.from(document.querySelectorAll('button')).filter(b => b.textContent.indexOf('Add XSS') !== -1)[0].innerHTML").getJavaScriptResult();
122122
assertThat(result, instanceOf(String.class));
123123
String resultString = (String) result;
124-
assertThat(resultString, not(containsString("<")));
124+
assertThat(resultString, not(containsString("<img")));
125125
}
126126

127127
@Test

test/src/test/java/lib/form/RepeatableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ private static HtmlButton getHtmlButton(HtmlForm form, String buttonCaption, boo
647647
*/
648648
private static List<?> getButtonsList(HtmlForm form, String buttonCaption) {
649649
return form.getByXPath(
650-
String.format("//button[text() = '%s'] | //button[@tooltip = '%s']", buttonCaption, buttonCaption)
650+
String.format("//button[normalize-space(string(.)) = '%s'] | //button[@tooltip = '%s']", buttonCaption, buttonCaption)
651651
);
652652
}
653653

0 commit comments

Comments
 (0)