fix: dont save if state or transition is empty and is_active is set
This commit is contained in:
parent
a6ce4736f7
commit
35f1c0213d
2 changed files with 13 additions and 4 deletions
|
|
@ -77,6 +77,7 @@ export const useStore = defineStore("workflow-builder-store", () => {
|
|||
let doc = workflow_doc.value;
|
||||
doc.states = get_updated_states();
|
||||
doc.transitions = get_updated_transitions();
|
||||
validate_workflow(doc);
|
||||
clean_workflow_data();
|
||||
doc.workflow_data = JSON.stringify(workflow.value.elements);
|
||||
await frappe.call("frappe.client.save", { doc });
|
||||
|
|
@ -89,6 +90,17 @@ export const useStore = defineStore("workflow-builder-store", () => {
|
|||
}
|
||||
}
|
||||
|
||||
function validate_workflow(doc) {
|
||||
if (doc.is_active && (!doc.states.length || !doc.transitions.length)) {
|
||||
let message = "Workflow must have atleast one state and transition";
|
||||
frappe.throw({
|
||||
message: __(message),
|
||||
title: __("Missing Values Required"),
|
||||
indicator: "orange",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function clean_workflow_data() {
|
||||
workflow.value.elements.forEach((el) => (el.selected = false));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,10 +55,7 @@ frappe.ui.form.on("Workflow", {
|
|||
});
|
||||
},
|
||||
validate: (frm) => {
|
||||
if (
|
||||
frm.doc.is_active &&
|
||||
(frm.doc.states.length === 0 || frm.doc.transitions.length === 0)
|
||||
) {
|
||||
if (frm.doc.is_active && (!frm.doc.states.length || !frm.doc.transitions.length)) {
|
||||
let message = "Workflow must have atleast one state and transition";
|
||||
frappe.throw({
|
||||
message: __(message),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue