feat(forms): preview the client's view from the builder #494
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/PMS-744-form-preview"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes PMS-744.
The ask
"After setting a form, is it possible to show a preview of what it looks like for the creator, easy to manage."
It makes sense, and the gap is real. The builder describes a form in editor terms (reference names, field types, conditional rules) and never showed the result. The only way to see what a client receives was to issue a real request link, which is single-use, expires in seven days, emails an actual client, and adds a row to that client's link history. So in practice nobody looked, and the third screenshot on the ticket, a client page with one field, is the first time anyone saw it.
What this adds
A Preview button beside Cancel and Save in the form editor, opening the client's view of the form.
Three decisions worth stating:
It renders through the real component. The first commit lifts the client page's title, description, field list and submit button into
RequestFormBody, and the preview calls that, on the client page's own background. A preview built from a second copy of the markup would drift from the page it claims to show, and a preview that lies is worse than none: it invites an operator to sign off on a form they have not actually seen.It reads the live editor state, not the saved definition. The question is asked while editing, so the answer covers unsaved changes.
It is live, not a picture. Typing into it exercises the
required_ifrules exactly as a client will hit them, which is the part of a definition hardest to hold in your head from the rule editor alone.Rows the client would never receive are dropped rather than drawn: a field with no reference name (the server rejects that save anyway) and a rule missing any of its three parts (it cannot fire). Options are carried only for a choice list, so stale values left behind by switching a field's type back to text do not show up. An unnamed draft previews as "Untitled form", and an unlabelled field shows its reference name, which is what the client would actually get.
The submit button renders but does nothing. Removing it would misrepresent the page, since the client sees one; wiring it would need a token this form does not have. The preview says so in one line above the card.
Verification
cargo check --all-targets,cargo clippy --all-targets(clean),cargo fmt --all --check(clean),cargo test --lib(267 passed).Three new unit tests cover the mapping: incomplete fields and rules are dropped, the fallbacks fire where a client would otherwise see a gap, and only a choice list carries options.
Considered and not done
A Preview action on each definition row, next to Edit and Send. It would be a third link in a narrow Actions column for a case already covered by Edit then Preview, and the row cannot preview unsaved work, which is the more useful moment. Easy to add later if the row turns out to be where people reach for it.