Skip to content

Commit deafb0d

Browse files
dkulpclaude
andcommitted
fix(ui): show a settings child listed under more than one parent value
The generated Update<setting>Children() emitted one independent if/else per parent value, so a child appearing under two values (Compile Hosts, under both 'distcc' and 'nocc') was marked hidden by whichever branch did not match: if (val == 'distcc') { ...show... } else { hide; hiddenChildren.DistccHosts = 1; } if (val == 'nocc') { if (mode == 0 || hiddenChildren.DistccHosts != 1) show } else { hide; hiddenChildren.DistccHosts = 1; } On page load UpdateChildSettingsVisibility() runs a hide pass then a show pass, and the show pass is gated on that flag, so the row never came back. On the onChange path (mode 0) the gate is skipped and the last emitted block won, which is why one value appeared to work when the dropdown was changed but neither survived a reload. Replace the three copies of the emitter (checkbox, select, text) with one shared PrintSettingChildrenFunction() that builds the show set for the current value first and only hides children that are not in it. Cross-parent behaviour is unchanged: a child claimed by two parents is still hidden if either hides it. Also index hiddenChildren with brackets and escape dots in the row selector so a plugin setting with a dotted child name cannot break the generated code. Verified by rendering every setting that declares children through the real generators, before and after, and simulating both passes: 115 child/value combos on the load path and 115 on the onChange path differ only for the affected setting, and 8 cross-parent combos are identical. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 174a546 commit deafb0d

1 file changed

Lines changed: 58 additions & 61 deletions

File tree

www/common.php

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,50 @@ function PrintSettingGroupTable($group, $appendData = "", $prependData = "", $in
12891289
echo "</div>\n";
12901290
}
12911291

1292+
// Emits the Update<setting>Children(mode) JS function.
1293+
//
1294+
// $conditions is an ordered map of JS boolean expression => array of child
1295+
// setting names to show when that expression is true. A child may appear
1296+
// under more than one condition (e.g. Compile Hosts under both 'distcc' and
1297+
// 'nocc'); the show set is computed first and only children not in it are
1298+
// hidden, otherwise a non-matching branch would mark a child hidden and the
1299+
// two-pass UpdateChildSettingsVisibility() would never show it again.
1300+
//
1301+
// mode: 0 = show/hide immediately, 1 = show pass only, 2 = hide pass only
1302+
function PrintSettingChildrenFunction($setting, $conditions, $preamble = "")
1303+
{
1304+
$names = array();
1305+
foreach ($conditions as $v) {
1306+
foreach ($v as $name) {
1307+
$names[$name] = 1;
1308+
}
1309+
}
1310+
1311+
echo "function Update$setting" . "Children(mode) {\n";
1312+
echo $preamble;
1313+
echo " var show = {};\n";
1314+
foreach ($conditions as $cond => $v) {
1315+
echo " if ($cond) {\n";
1316+
foreach ($v as $name) {
1317+
echo " show['$name'] = 1;\n";
1318+
}
1319+
echo " }\n";
1320+
}
1321+
echo " var kids = " . json_encode(array_keys($names)) . ";\n";
1322+
echo " for (var i = 0; i < kids.length; i++) {\n";
1323+
echo " var kid = kids[i];\n";
1324+
echo " var row = \$('#' + kid.replace(/\\./g, '\\\\.') + 'Row');\n";
1325+
echo " if (show[kid]) {\n";
1326+
echo " if ((mode != 2) && ((mode == 0) || (hiddenChildren[kid] != 1)))\n";
1327+
echo " row.show();\n";
1328+
echo " } else if (mode != 1) {\n";
1329+
echo " row.hide();\n";
1330+
echo " hiddenChildren[kid] = 1;\n";
1331+
echo " }\n";
1332+
echo " }\n";
1333+
echo "}\n\n";
1334+
}
1335+
12921336
function PrintSettingCheckbox($title, $setting, $restart, $reboot, $checkedValue, $uncheckedValue, $pluginName = "", $callbackName = "", $defaultValue = 0, $desc = "", $sData = array())
12931337
{
12941338
global $settings;
@@ -1312,10 +1356,9 @@ function PrintSettingCheckbox($title, $setting, $restart, $reboot, $checkedValue
13121356

13131357
echo "<script>\n";
13141358
if (isset($sData['children'])) {
1315-
echo "function Update$setting" . "Children(mode) {
1316-
var checked = 0;
1317-
if ($('#$escSetting').is(':checked')) {
1318-
checked = 1;
1359+
$preamble = " var checked = 0;
1360+
if ($('#$escSetting').is(':checked')) {
1361+
checked = 1;
13191362
}
13201363
13211364
if (checked)
@@ -1324,27 +1367,13 @@ function PrintSettingCheckbox($title, $setting, $restart, $reboot, $checkedValue
13241367
$('.$escSetting' + 'Child').hide();
13251368
13261369
";
1370+
$conditions = array();
13271371
foreach ($sData['children'] as $k => $v) {
13281372
if ($k == "1") {
1329-
echo "if (checked) {\n";
1330-
echo " if (mode != 2) {\n";
1331-
foreach ($v as $name) {
1332-
echo " if ((mode == 0) || (hiddenChildren.$name != 1))\n";
1333-
echo " $('#" . $name . "Row').show();\n";
1334-
}
1335-
echo " }\n";
1336-
echo "} else {\n";
1337-
echo " if (mode != 1) {\n";
1338-
foreach ($v as $name) {
1339-
echo "$('#" . $name . "Row').hide();\n";
1340-
echo "hiddenChildren.$name = 1;\n";
1341-
}
1342-
echo " }\n";
1343-
echo "}\n";
1373+
$conditions["checked"] = $v;
13441374
}
13451375
}
1346-
1347-
echo "}\n\n";
1376+
PrintSettingChildrenFunction($setting, $conditions, $preamble);
13481377
}
13491378

13501379
echo "
@@ -1435,28 +1464,12 @@ function PrintSettingSelectInternal($title, $setting, $restart, $reboot, $defaul
14351464
echo "<script>\n";
14361465

14371466
if (isset($sData['children'])) {
1438-
echo "function Update$setting" . "Children(mode) {
1439-
var val = $('#$escSetting').val();
1440-
";
1467+
$preamble = " var val = $('#$escSetting').val();\n";
1468+
$conditions = array();
14411469
foreach ($sData['children'] as $k => $v) {
1442-
echo "if (val == '$k') {\n";
1443-
echo " if (mode != 2) {\n";
1444-
foreach ($v as $name) {
1445-
echo " if ((mode == 0) || (hiddenChildren.$name != 1))\n";
1446-
echo " $('#" . $name . "Row').show();\n";
1447-
}
1448-
echo " }\n";
1449-
echo "} else {\n";
1450-
echo " if (mode != 1) {\n";
1451-
foreach ($v as $name) {
1452-
echo "$('#" . $name . "Row').hide();\n";
1453-
echo "hiddenChildren.$name = 1;\n";
1454-
}
1455-
echo " }\n";
1456-
echo "}\n";
1470+
$conditions["val == '" . $k . "'"] = $v;
14571471
}
1458-
1459-
echo "}\n\n";
1472+
PrintSettingChildrenFunction($setting, $conditions, $preamble);
14601473
}
14611474

14621475
if (isset($sData['reloadOther'])) {
@@ -1670,28 +1683,12 @@ function PrintSettingTextSaved($setting, $restart = 1, $reboot = 0, $maxlength =
16701683

16711684
echo "<script>\n";
16721685
if (isset($sData['children'])) {
1673-
echo "function Update$setting" . "Children(mode) {
1674-
var val = $('#$escSetting').val();
1675-
";
1686+
$preamble = " var val = $('#$escSetting').val();\n";
1687+
$conditions = array();
16761688
foreach ($sData['children'] as $k => $v) {
1677-
echo "if (val != '') {\n";
1678-
echo " if (mode != 2) {\n";
1679-
foreach ($v as $name) {
1680-
echo " if ((mode == 0) || (hiddenChildren.$name != 1))\n";
1681-
echo " $('#" . $name . "Row').show();\n";
1682-
}
1683-
echo " }\n";
1684-
echo "} else {\n";
1685-
echo " if (mode != 1) {\n";
1686-
foreach ($v as $name) {
1687-
echo "$('#" . $name . "Row').hide();\n";
1688-
echo "hiddenChildren.$name = 1;\n";
1689-
}
1690-
echo " }\n";
1691-
echo "}\n";
1689+
$conditions["val != ''"] = array_merge(isset($conditions["val != ''"]) ? $conditions["val != ''"] : array(), $v);
16921690
}
1693-
1694-
echo "}\n\n";
1691+
PrintSettingChildrenFunction($setting, $conditions, $preamble);
16951692
}
16961693

16971694
echo "

0 commit comments

Comments
 (0)