Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions taskflow/renderer/zoneview/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down
19 changes: 16 additions & 3 deletions taskflow/renderer/zoneview/zoneview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading