Flow
Where an edit can end up
1Always create (my old button)
Easy to write, but every edit makes a copy and the original keeps running.
2Add a version, move the pointer (what I do now)
No copies and old versions kept. It takes more storage over time.
3Same, plus a version check
Also refuses a save made from a stale screen. I haven't built this part.
The save button on my workflow editor didn't save anything. It made a new workflow every time.
A workflow in the ordering system says what happens after a report finishes: which report, a few conditions, and where a summary goes in the task tracker. You open one, change it, press save, and a banner says it worked.
The screen knew which workflow was open, but the save button ignored that. It always sent the form to the create route. So every edit made a near-copy, and the original kept running the old way. I'd guess a report could get sent twice when both copies match it, but I didn't see that happen.
Same form, same banner, different row
Creating and editing send the same form and get the same kind of reply. The only difference is which row changed. A check that only asks "did save work?" passes either way.
Now the screen asks one question first.
With nothing open the save creates a workflow, and with one open it updates that workflow's own address.
The id is encoded so odd characters can't change the address. The button label comes from the same answer, so it says create or save changes.
Edits stack up instead of overwriting
The server had no update route, so I added one. Each workflow is a header plus a list of versions, and the header points at the current one. An edit adds the next version and moves the pointer, both in one transaction, so you never get half a save. Old versions stay.
Before writing, the server checks three things. Is the workflow there? Does it have a version? And if it runs on one person's own tracker login, is that person the one saving? I think the handoff posts as that person, so nobody else should rewrite it.
Create and edit now build their records with the same helpers. Refresh also got fixed: it used to keep a stale form, and now it reloads the open workflow.
A slash in an id, and no stale-screen check
The tests check both kinds of request, using an id with a slash and a space. They also check that an edit makes version two and moves the pointer. They use a fake database, so they say nothing about two people saving at once. I haven't built a check that would refuse a save made from a stale screen.