Skip to content

Commit 10f460d

Browse files
committed
fix: OVERVIEW_PAGE value bug, datasource ordering, Caption validation
- Fix SetPropertyWithEntity for OVERVIEW_PAGE: pass entity value instead of empty string (was clearing AdminPage instead of setting it) - Split OVERVIEW_PAGE and PARAMETER handling in cmd_alter_workflow.go - Reorder Build(): auto-datasource before applyChildSlots so entityContext is available for child widgets - Validate slot.Operation in applyChildSlots (must be "widgets") - setWidgetCaption returns validation error when Caption missing (matching setWidgetContent behavior) - extractBinaryIDFromDoc handles []byte in addition to primitive.Binary
1 parent 0acd412 commit 10f460d

3 files changed

Lines changed: 29 additions & 11 deletions

File tree

mdl/executor/bson_helpers.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,14 @@ func dSetArray(doc bson.D, key string, elements []any) {
111111

112112
// extractBinaryIDFromDoc extracts a binary ID string from a bson.D field.
113113
func extractBinaryIDFromDoc(val any) string {
114-
if bin, ok := val.(primitive.Binary); ok {
114+
switch bin := val.(type) {
115+
case primitive.Binary:
115116
return types.BlobToUUID(bin.Data)
117+
case []byte:
118+
return types.BlobToUUID(bin)
119+
default:
120+
return ""
116121
}
117-
return ""
118122
}
119123

120124
// ============================================================================
@@ -352,8 +356,7 @@ func setRawWidgetProperty(widget bson.D, propName string, value interface{}) err
352356
func setWidgetCaption(widget bson.D, value interface{}) error {
353357
caption := dGetDoc(widget, "Caption")
354358
if caption == nil {
355-
setTranslatableText(widget, "Caption", value)
356-
return nil
359+
return mdlerrors.NewValidation("widget has no Caption property")
357360
}
358361
setTranslatableText(caption, "", value)
359362
return nil

mdl/executor/cmd_alter_workflow.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@ func execAlterWorkflow(ctx *ExecContext, s *ast.AlterWorkflowStmt) error {
6262
switch o := op.(type) {
6363
case *ast.SetWorkflowPropertyOp:
6464
switch o.Property {
65-
case "OVERVIEW_PAGE", "PARAMETER":
65+
case "OVERVIEW_PAGE":
66+
// OVERVIEW_PAGE uses Entity as the page qualified name (Value is unused).
67+
qn := o.Entity.Module + "." + o.Entity.Name
68+
if qn == "." {
69+
qn = ""
70+
}
71+
if err := mutator.SetPropertyWithEntity(o.Property, qn, qn); err != nil {
72+
return mdlerrors.NewBackend("SET "+o.Property, err)
73+
}
74+
case "PARAMETER":
75+
// PARAMETER uses Value as the variable name and Entity as the entity qualified name.
6676
qn := o.Entity.Module + "." + o.Entity.Name
6777
if qn == "." {
6878
qn = ""

mdl/executor/widget_engine.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,9 @@ func (e *PluggableWidgetEngine) Build(def *WidgetDefinition, w *ast.WidgetV3) (*
129129
}
130130
}
131131

132-
// 4. Apply child slots (.def.json)
133-
if err := e.applyChildSlots(builder, slots, w, propertyTypeIDs); err != nil {
134-
return nil, err
135-
}
136-
137-
// 4.1 Auto datasource: map AST DataSource to first DataSource-type property.
132+
// 4. Auto datasource: map AST DataSource to first DataSource-type property.
133+
// This must run before child slots so that entityContext is available
134+
// for child widgets that depend on the parent's data source.
138135
dsHandledByMapping := false
139136
for _, m := range mappings {
140137
if m.Source == "DataSource" {
@@ -160,6 +157,11 @@ func (e *PluggableWidgetEngine) Build(def *WidgetDefinition, w *ast.WidgetV3) (*
160157
}
161158
}
162159

160+
// 4.1 Apply child slots (.def.json)
161+
if err := e.applyChildSlots(builder, slots, w, propertyTypeIDs); err != nil {
162+
return nil, err
163+
}
164+
163165
// 4.3 Auto child slots: match AST children to Widgets-type template properties.
164166
handledSlotKeys := make(map[string]bool)
165167
for _, s := range slots {
@@ -525,6 +527,9 @@ func (e *PluggableWidgetEngine) applyChildSlots(builder backend.WidgetObjectBuil
525527
}
526528

527529
ctx := &BuildContext{}
530+
if slot.Operation != "widgets" {
531+
return mdlerrors.NewValidationf("childSlots operation must be %q, got %q for property %s", "widgets", slot.Operation, slot.PropertyKey)
532+
}
528533
if err := e.applyOperation(builder, slot.Operation, slot.PropertyKey, ctx); err != nil {
529534
return err
530535
}

0 commit comments

Comments
 (0)