Skip to content

Commit b8944fa

Browse files
authored
Backporting LTS 2.541.2 (#26220)
2 parents fef3af0 + 25bc490 commit b8944fa

File tree

3 files changed

+59
-26
lines changed

3 files changed

+59
-26
lines changed

core/src/main/java/hudson/model/Computer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,9 @@ public void doConfigSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOE
15031503
throw new FormException(Messages.Slave_InvalidConfig_Executors(nodeName), "numExecutors");
15041504
}
15051505

1506+
OfflineCause offlineCause = node.getTemporaryOfflineCause();
15061507
Node result = node.reconfigure(req, req.getSubmittedForm());
1508+
result.setTemporaryOfflineCause(offlineCause);
15071509
Jenkins.get().getNodesObject().replaceNode(this.getNode(), result);
15081510

15091511
if (result.getNodeProperty(DiskSpaceMonitorNodeProperty.class) != null) {

test/src/test/java/hudson/model/ComputerTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ void computerIconDependsOnOfflineCause() throws Exception {
160160
assertThat(computer.getIcon(), equalTo(cause.getComputerIcon()));
161161
}
162162

163+
@Test
164+
@Issue("#26146")
165+
void computerTemporaryOfflineCauseStaysOnConfigRound() throws Exception {
166+
var agent = j.createSlave();
167+
var computer = agent.toComputer();
168+
var offlineCause = new OfflineCause.UserCause(User.getOrCreateByIdOrFullName("username"), "Initial cause");
169+
computer.setTemporaryOfflineCause(offlineCause);
170+
j.configRoundtrip(agent);
171+
agent = (DumbSlave) j.jenkins.getNode(agent.getNodeName());
172+
assertThat(agent.getTemporaryOfflineCause(), equalTo(offlineCause));
173+
}
174+
163175
@Test
164176
@LocalData
165177
void removeUserDetailsFromOfflineCause() throws Exception {

war/src/main/webapp/scripts/hudson-behavior.js

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,47 +1683,66 @@ function rowvgStartEachRow(recursive, f) {
16831683
return;
16841684
}
16851685

1686-
var subForms = [];
1687-
var start = findInFollowingTR(e, "dropdownList-container");
1686+
function buildSubForms(e) {
1687+
var subForms = [];
1688+
var start = findInFollowingTR(e, "dropdownList-container");
16881689

1689-
do {
1690-
start = start.firstElementChild;
1691-
} while (start && !isTR(start));
1690+
do {
1691+
start = start.firstElementChild;
1692+
} while (start && !isTR(start));
16921693

1693-
if (start && !start.classList.contains("dropdownList-start")) {
1694-
start = findFollowingTR(start, "dropdownList-start");
1695-
}
1696-
while (start != null) {
1697-
subForms.push(start);
1698-
start = findFollowingTR(start, "dropdownList-start");
1694+
if (start && !start.classList.contains("dropdownList-start")) {
1695+
start = findFollowingTR(start, "dropdownList-start");
1696+
}
1697+
while (start != null) {
1698+
subForms.push(start);
1699+
start = findFollowingTR(start, "dropdownList-start");
1700+
}
1701+
return subForms;
16991702
}
17001703

1704+
var subForms = buildSubForms(e);
17011705
// control visibility
17021706
function updateDropDownList() {
17031707
for (var i = 0; i < subForms.length; i++) {
17041708
var show = e.selectedIndex == i;
17051709
var f = subForms[i];
17061710

17071711
if (show) {
1708-
renderOnDemand(f.nextElementSibling);
1712+
const idx = i; // capture the index so that it is not mutated in the loop
1713+
renderOnDemand(f.nextElementSibling, function () {
1714+
const current = e.selectedIndex == idx;
1715+
if (!current) {
1716+
console.warn(
1717+
"renderOnDemandCallback: selection is no longer valid, rebuilding correct DOM",
1718+
);
1719+
// our form div has changed (but the index is stable) so go and re-get the new domtree
1720+
const subForm = buildSubForms(e)[idx];
1721+
updateDropDownFormRowVisibility(subForm, false);
1722+
}
1723+
});
17091724
}
1710-
f.rowVisibilityGroup.makeInnerVisible(show);
1711-
1712-
// TODO: this is actually incorrect in the general case if nested vg uses field-disabled
1713-
// so far dropdownList doesn't create such a situation.
1714-
f.rowVisibilityGroup.eachRow(
1715-
true,
1716-
show
1717-
? function (e) {
1718-
e.removeAttribute("field-disabled");
1719-
}
1720-
: function (e) {
1721-
e.setAttribute("field-disabled", "true");
1722-
},
1723-
);
1725+
updateDropDownFormRowVisibility(f, show);
17241726
}
17251727
}
17261728

1729+
function updateDropDownFormRowVisibility(f, show) {
1730+
f.rowVisibilityGroup.makeInnerVisible(show);
1731+
1732+
// TODO: this is actually incorrect in the general case if nested vg uses field-disabled
1733+
// so far dropdownList doesn't create such a situation.
1734+
f.rowVisibilityGroup.eachRow(
1735+
true,
1736+
show
1737+
? function (e) {
1738+
e.removeAttribute("field-disabled");
1739+
}
1740+
: function (e) {
1741+
e.setAttribute("field-disabled", "true");
1742+
},
1743+
);
1744+
}
1745+
17271746
e.onchange = updateDropDownList;
17281747

17291748
updateDropDownList();

0 commit comments

Comments
 (0)