diff --git a/taskflow/renderer/zoneview/renderer_test.go b/taskflow/renderer/zoneview/renderer_test.go index 6979cb95..3b30648d 100644 --- a/taskflow/renderer/zoneview/renderer_test.go +++ b/taskflow/renderer/zoneview/renderer_test.go @@ -295,6 +295,45 @@ func TestRender_HandlesKeepDeclarationOrder(t *testing.T) { } } +// A handle's pre_confirm reaches the view as the section declares it; a handle +// without one carries none. +func TestRender_CarriesHandlePreConfirm(t *testing.T) { + r := newTestRenderer(t) + const config = `{ + "id": "test:render", + "sections": { + "form": { + "templateId": "t", + "projector": "MARKDOWN", + "handles": [ + { "command": "submit", "label": "Submit", + "pre_confirm": { "title": "Submit CusDec?", "description": "Customs receives it at once." } }, + { "command": "verify", "label": "Verify", "pre_confirm": { "skip": true } }, + { "command": "save_as_draft", "label": "Save as Draft" } + ] + } + }, + "states": { + "PENDING_USER": { "actions": [{ "command": "submit" }, { "command": "verify" }, { "command": "save_as_draft" }] } + } + }` + + view := decodeView(t, render(t, r, config, tfrenderer.Facts{State: "PENDING_USER"})) + if len(view) != 1 || len(view[0].Handles) != 3 { + t.Fatalf("got view %v, want one component with 3 handles", view) + } + want := []*HandlePreConfirm{ + {Title: "Submit CusDec?", Description: "Customs receives it at once."}, + {Skip: true}, + nil, + } + for i, h := range view[0].Handles { + if (h.PreConfirm == nil) != (want[i] == nil) || (want[i] != nil && *h.PreConfirm != *want[i]) { + t.Errorf("%s pre_confirm: got %+v, want %+v", h.Command, h.PreConfirm, want[i]) + } + } +} + func TestResolveLayout(t *testing.T) { cfg := TaskTemplateConfig{ Layouts: map[string][]string{"main": {"b", "a"}}, diff --git a/taskflow/renderer/zoneview/zoneview.go b/taskflow/renderer/zoneview/zoneview.go index 3d77c904..b8cbd4d1 100644 --- a/taskflow/renderer/zoneview/zoneview.go +++ b/taskflow/renderer/zoneview/zoneview.go @@ -25,10 +25,23 @@ type Action struct { // "Claim" here means a section laying claim to a command. It is unrelated to // the authorization claims in renderer.Facts.Claims, which decide whether a // section is rendered at all. +// +// PreConfirm optionally configures the dialog that asks the user before the +// handle is sent; the data layer carries it without interpreting it. type HandleClaim struct { - Command string `json:"command"` - Label string `json:"label"` - Element string `json:"element,omitempty"` + Command string `json:"command"` + Label string `json:"label"` + Element string `json:"element,omitempty"` + PreConfirm *HandlePreConfirm `json:"pre_confirm,omitempty"` +} + +// HandlePreConfirm configures the dialog that asks the user to confirm a +// handle before it is sent. Skip sends the handle without asking; an empty +// Title or Description leaves the renderer's own text. +type HandlePreConfirm struct { + Skip bool `json:"skip,omitempty"` + Title string `json:"title,omitempty"` + Description string `json:"description,omitempty"` } // SectionView is the per-zone trader-app metadata read from render.json