Save checks, copies and renames
How the editor asks the backend what a save would change, handles a refused save with Save as a copy, and follows renamed inputs and outputs.
Before it saves an existing workflow, the editor can ask the backend what the save would change for the things that use the workflow. The answer is the impact report. When the report says something needs attention, the editor shows a dialog before saving.
The check runs through the workflows.impact endpoint. A backend without it simply leaves the save unasked.
The impact report
The editor sends POST to the impact path (default /workflow/{id}/impact) with the workflow as it would save it, and reads { success, data }:
interface ImpactReport {
/** The editor asks before saving when this is set. */
confirm: boolean;
/** The level of the interface change, as the backend names it. */
interfaceLevel: string;
interfaceBreaking: boolean;
items: ImpactItem[];
/** The save is refused while things use the workflow. Absent: false. */
refused?: boolean;
/** The backend's own words for the refusal, when it gives them. */
refusedMessage?: string | null;
/** Where to POST the draft to save it as a new workflow instead. */
copyUrl?: string | null;
/** Renamed inputs and outputs, with the places that follow when the person agrees. */
renames?: ImpactRename[];
}
interface ImpactItem {
kind: string;
severity: 'breaks' | 'changes' | 'info';
label: string;
message: string;
/** Where to look at the affected thing. */
url: string | null;
}On the wire, the interface level is data.interface.level and data.interface.breaking. Items without a label and a message are skipped, and an unknown severity reads as info.
refused, refusedMessage, copyUrl and renames are optional, so code that builds a report keeps compiling, and a backend that sends none of them behaves as it did without them. The types ImpactReport, ImpactItem, ImpactRename, ImpactRenamePlace and SavedCopy are exported from @flowdrop/flowdrop.
A 401, 403, 404 or 405 answer means the check is unavailable, and the save goes on without asking.
A refused save
When the report has refused: true, the save dialog says the change can't be saved. It names how many places use the workflow and lists them. The count includes only the places with severity breaks. With none, it says "while other things use this workflow". If you send refusedMessage, the dialog shows it.
The dialog offers up to three choices:
- Save as a copy — when the report has a usable
copyUrl. - Discard my changes — when the workflow has an id. It throws away every unsaved edit, including the undo history and the stored draft, loads the saved version again and calls
onWorkflowLoad. - Keep editing — closes the dialog.
The copy URL rule
The editor sends the draft and your auth headers to copyUrl, so it only accepts one of these:
- a path from the site root that starts with a single
/(not//and not/\), such as/api/flowdrop/workflows/42/copy. It is resolved against the page, not the API base URL, so write it the way Drupal'sUrl::toString()does, API prefix included, or - a full
http(s)URL on the same origin as the page or as the API base URL.
Anything else, including a path without the leading /, hides Save as a copy.
The copy endpoint
Request: POST to copyUrl, with the draft workflow as the JSON body.
Response:
{
"success": true,
"data": {
"id": "wf-copy-123",
"editorUrl": "/admin/flowdrop/workflows/wf-copy-123/edit"
}
}Both id and editorUrl are optional. The editor also reads editor_url. A non-2xx answer, or success: false, is shown to the person as "Could not save a copy" with the backend's error text. An editorUrl is only used when it is a site path or an http(s) address.
onSavedAsCopy
After the copy is saved, the editor calls onSavedAsCopy(copy, workflow):
interface SavedCopy {
id: string | null;
editorUrl: string | null;
}
const app = await mountFlowDropApp(container, {
eventHandlers: {
onSavedAsCopy: async (copy, workflow) => {
// The original is unchanged. The editor still holds the draft.
if (copy.editorUrl) window.location.assign(copy.editorUrl);
}
}
});On <App> it is the flat prop onSavedAsCopy. See the event handlers reference.
- With the handler, you decide what happens next and the editor does nothing else.
- Without it, and with an
editorUrl, the editor marks the workflow as saved (so no "Leave site?" prompt appears and the original's stored draft is dropped), then goes to the copy. - Without it and without a URL, the editor shows a "Saved a copy" toast and stays as it is.
An error thrown by your handler is logged and never reported as a failed save.
A refusal from the save itself
The backend may refuse the PUT instead of (or after) the check. The editor reads a refusal as an in-use refusal when the error body carries error_code: "WORKFLOW_IN_USE_BREAKING", and then opens the same refused dialog instead of an error toast.
{
"success": false,
"error": "Three live workflows use this workflow.",
"error_code": "WORKFLOW_IN_USE_BREAKING",
"copyUrl": "/api/flowdrop/workflows/42/copy",
"details": {
"items": [
{
"kind": "workflow",
"severity": "breaks",
"label": "Order intake",
"message": "Uses the input 'customer'.",
"url": "/admin/flowdrop/workflows/7"
}
]
}
}The library reads these places:
| What | Where it looks |
|---|---|
| Code | error_code |
| Message | error |
| Items | details as a list, else details.items, else items |
| Copy URL | copyUrl, else copy_url |
Whatever the refusal does not carry (the items, the copy URL) comes from the earlier impact check.
Renames
When the draft renames an interface input or output, the report lists it in renames:
interface ImpactRename {
direction: 'input' | 'output';
from: string;
to: string;
/** What uses the old name and is updated when the rename is followed. */
places: ImpactRenamePlace[];
}
interface ImpactRenamePlace {
kind: string;
label: string;
url: string | null;
/** What the rename does to it, when the backend says. */
message?: string;
/** false when the place is switched off. */
enabled?: boolean;
}A place needs only a label; places without one are skipped. If two entries share a direction and a from name, the first one wins.
The dialog lists each rename with its places, and offers a box, Also update these N places, unticked by default. The box only shows when some place uses a rename.
- A rename that nothing uses does not interrupt saving: there is no dialog, and autosave goes on.
- When the box was offered, the update request carries a top-level boolean
followRenames,trueif the person ticked it andfalseif not. When the box was not offered, the field is not sent.
{
"id": "wf-abc123",
"name": "Order intake",
"nodes": [],
"edges": [],
"followRenames": true
}Your backend decides what following a rename means. The editor only asks and passes on the answer.
Messages
The dialogs read the impact.refused.* and impact.renames.* message groups. See Internationalization.