Skip to content

Commit ab9c996

Browse files
committed
fix: inconsistent validation errors
1 parent 855077c commit ab9c996

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

branching_xblock/branching_xblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ def _validate_references(
992992
node_client_id=node_client_id,
993993
field_name="choiceDestinationByIndex",
994994
index=choice_index,
995-
message="Selected destination is invalid.",
995+
message="Selected destination is pending deletion.",
996996
)
997997
self._add_node_error(
998998
validation_errors,

branching_xblock/static/css/studio_editor.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@
576576
display: inline-flex;
577577
align-items: center;
578578
gap: 6px;
579-
font-size: 11px;
579+
font-size: 13px;
580580
line-height: 1.2;
581581
color: #7c5e00;
582582
padding: 0;
@@ -595,7 +595,7 @@
595595
display: inline-flex;
596596
align-items: center;
597597
gap: 6px;
598-
font-size: 11px;
598+
font-size: 13px;
599599
line-height: 1.2;
600600
color: #d23228;
601601
}

branching_xblock/static/js/src/studio_editor.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ function BranchingStudioEditor(runtime, element, data) {
242242
.text(`${pendingCount} ${nodeWord} will be deleted when you save.`);
243243
}
244244

245+
function firstErroredNodeId() {
246+
return editorState.draftNodes.find(
247+
(node) => editorState.validationNodeErrorIds?.has(node.id)
248+
)?.id || null;
249+
}
250+
245251
// Map backend structured errors into the editor's view model. This is the
246252
// canonical validation bridge from API contract -> per-field/per-node UI state.
247253
function applyServerValidation(res) {
@@ -483,6 +489,10 @@ function BranchingStudioEditor(runtime, element, data) {
483489
// Apply backend validation and move user to the most relevant step.
484490
function showErrors(res) {
485491
applyServerValidation(res);
492+
const erroredNodeId = firstErroredNodeId();
493+
if (erroredNodeId && !editorState.validationNodeErrorIds?.has(editorState.selectedNodeId)) {
494+
editorState.selectedNodeId = erroredNodeId;
495+
}
486496
renderSettings();
487497
renderNodeList();
488498
renderNodeEditor();
@@ -709,7 +719,6 @@ function BranchingStudioEditor(runtime, element, data) {
709719
}
710720
syncCurrentNodeFromDom();
711721
editorState.selectedNodeId = nodeId;
712-
clearValidationState();
713722
renderNodeList();
714723
renderNodeEditor();
715724
updateFooterUi();

tests/test_branching_xblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def test_studio_submit_rejects_deleting_referenced_node_with_node_action_errors(
563563
assert result["result"] == "error"
564564
assert (
565565
result["field_errors"]["node_input_errors"]["temp-1"]["choiceDestinationByIndex"]["0"]
566-
== "Selected destination is invalid."
566+
== "Selected destination is pending deletion."
567567
)
568568
node_errors = result["field_errors"]["node_action_errors"]
569569
assert node_errors["temp-2"]["title"] == "You can't delete this node"

0 commit comments

Comments
 (0)