fix(workflows, frontend): align Flow DAG schema contract, resolve diamond joins, enforce atomic rollback, wire UI modals and live metrics

This commit is contained in:
Goose 2026-09-26 18:22:26 +00:00
parent b970c53f54
commit af8556597a
10 changed files with 739 additions and 218 deletions

View file

@ -3,7 +3,7 @@ import api from '../api'
export const useCrmStore = defineStore('crm', {
state: () => ({
activeTab: 'leads', // 'leads' | 'opportunities' | 'contacts' | 'accounts' | 'custom_objects' | 'flows' | 'outreach' | 'tasks'
activeTab: 'leads',
currentRecord: null,
leads: [],
opportunities: [],
@ -11,6 +11,7 @@ export const useCrmStore = defineStore('crm', {
accounts: [],
activities: [],
customObjects: [],
customFields: [],
customRecords: {},
flows: [],
campaigns: [],
@ -30,6 +31,11 @@ export const useCrmStore = defineStore('crm', {
console.error(err)
}
},
async createLead(leadData) {
const res = await api.post('/leads/', leadData)
await this.fetchLeads()
return res.data
},
async fetchOpportunities() {
try {
const res = await api.get('/opportunities/')
@ -38,6 +44,11 @@ export const useCrmStore = defineStore('crm', {
console.error(err)
}
},
async createOpportunity(oppData) {
const res = await api.post('/opportunities/', oppData)
await this.fetchOpportunities()
return res.data
},
async fetchContacts() {
try {
const res = await api.get('/contacts/')
@ -46,6 +57,11 @@ export const useCrmStore = defineStore('crm', {
console.error(err)
}
},
async createContact(contactData) {
const res = await api.post('/contacts/', contactData)
await this.fetchContacts()
return res.data
},
async fetchAccounts() {
try {
const res = await api.get('/accounts/')
@ -54,6 +70,11 @@ export const useCrmStore = defineStore('crm', {
console.error(err)
}
},
async createAccount(accountData) {
const res = await api.post('/accounts/', accountData)
await this.fetchAccounts()
return res.data
},
async fetchActivities() {
try {
const res = await api.get('/activities/')
@ -62,6 +83,16 @@ export const useCrmStore = defineStore('crm', {
console.error(err)
}
},
async createActivity(activityData) {
const res = await api.post('/activities/', activityData)
await this.fetchActivities()
return res.data
},
async updateActivityStatus(activityId, status) {
const res = await api.patch(`/activities/${activityId}/`, { status })
await this.fetchActivities()
return res.data
},
async fetchCustomObjects() {
try {
const res = await api.get('/custom-objects/')
@ -70,6 +101,31 @@ export const useCrmStore = defineStore('crm', {
console.error(err)
}
},
async createCustomObject(objData) {
const res = await api.post('/custom-objects/', objData)
await this.fetchCustomObjects()
return res.data
},
async createCustomField(fieldData) {
const res = await api.post('/custom-fields/', fieldData)
await this.fetchCustomObjects()
return res.data
},
async fetchCustomRecords(objectName) {
try {
const res = await api.get(`/custom/${objectName}/`)
this.customRecords[objectName] = res.data.results || res.data
return this.customRecords[objectName]
} catch (err) {
console.error(err)
return []
}
},
async insertCustomRecord(objectName, data) {
const res = await api.post(`/custom/${objectName}/`, { data })
await this.fetchCustomRecords(objectName)
return res.data
},
async fetchFlows() {
try {
const res = await api.get('/flows/')
@ -86,6 +142,16 @@ export const useCrmStore = defineStore('crm', {
console.error(err)
}
},
async createCampaign(campaignData) {
const res = await api.post('/campaigns/', campaignData)
await this.fetchCampaigns()
return res.data
},
async dispatchCampaign(campaignId) {
const res = await api.post(`/campaigns/${campaignId}/dispatch/`)
await this.fetchCampaigns()
return res.data
},
async convertLead(leadId, payload) {
const res = await api.post(`/leads/${leadId}/convert/`, payload)
await this.fetchLeads()

View file

@ -1,151 +1,235 @@
<template>
<div class="h-full flex flex-col p-4 bg-slate-50 overflow-auto">
<!-- Header -->
<div class="flex items-center justify-between pb-4 mb-4 border-b border-slate-200">
<div>
<h1 class="text-xl font-bold text-slate-900 flex items-center gap-2">
<span>🧩</span> Custom Objects Schema Engine
</h1>
<p class="text-xs text-slate-500">Define dynamic schema models (like Salesforce Object Manager) with JSONB & GIN storage</p>
<div class="h-full flex p-4 gap-4 bg-slate-50 overflow-hidden font-sans">
<!-- Left Sidebar: Object List -->
<div class="w-1/3 bg-white rounded-lg shadow-sm border border-slate-200 flex flex-col overflow-hidden">
<div class="p-3.5 border-b border-slate-200 bg-slate-100 flex items-center justify-between">
<div>
<h2 class="font-bold text-sm text-slate-800">Custom Objects (__c)</h2>
<p class="text-[11px] text-slate-500">Salesforce-style Metamodel</p>
</div>
<button
@click="showCreateObjectModal = true"
class="bg-brand-500 hover:bg-brand-600 text-white text-xs font-semibold px-2.5 py-1.5 rounded transition shadow-xs"
>
+ New Object
</button>
</div>
<button
@click="showCreateObjectModal = true"
class="bg-brand-500 hover:bg-brand-600 text-white text-xs font-semibold px-4 py-2 rounded shadow-sm transition"
>
+ New Custom Object (__c)
</button>
</div>
<!-- Layout: Left side Objects, Right side Fields & Data Records -->
<div class="grid grid-cols-3 gap-4 flex-1">
<!-- Objects Column -->
<div class="bg-white rounded-lg shadow-sm border border-slate-200 p-4 flex flex-col">
<h2 class="font-bold text-xs text-slate-800 uppercase tracking-wider mb-3">Custom Objects</h2>
<div class="space-y-2 flex-1 overflow-y-auto">
<div
v-for="obj in crmStore.customObjects"
:key="obj.id"
@click="selectObject(obj)"
:class="[
'p-3 rounded border text-xs cursor-pointer transition',
selectedObj?.id === obj.id
? 'bg-blue-50/70 border-brand-500 text-brand-700 font-semibold'
: 'border-slate-200 hover:border-slate-300 text-slate-800'
]"
>
<div class="flex items-center justify-between">
<span class="font-bold">{{ obj.label }}</span>
<code class="text-[10px] text-brand-600 bg-brand-50 px-1 py-0.5 rounded">{{ obj.name }}</code>
</div>
<div class="text-[10px] text-slate-500 mt-1">Plural: {{ obj.plural_label }}</div>
</div>
<div v-if="crmStore.customObjects.length === 0" class="py-8 text-center text-slate-400 italic text-xs">
No custom objects yet.
<div class="flex-1 overflow-y-auto divide-y divide-slate-100">
<div
v-for="obj in crmStore.customObjects"
:key="obj.id"
@click="selectObject(obj)"
:class="[
'p-3 cursor-pointer transition flex items-center justify-between text-xs',
selectedObj?.id === obj.id ? 'bg-brand-50 border-l-4 border-brand-500 font-semibold' : 'hover:bg-slate-50'
]"
>
<div>
<div class="text-slate-900">{{ obj.label }}</div>
<div class="text-[11px] text-slate-400 font-mono">{{ obj.name }}</div>
</div>
<span class="text-[10px] bg-slate-100 text-slate-600 px-1.5 py-0.5 rounded font-mono">__c</span>
</div>
<div v-if="crmStore.customObjects.length === 0" class="p-6 text-center text-slate-400 text-xs">
No custom objects found. Create one to get started!
</div>
</div>
</div>
<!-- Detail & Dynamic Record Inspector -->
<div class="col-span-2 bg-white rounded-lg shadow-sm border border-slate-200 p-4 flex flex-col">
<div v-if="selectedObj" class="flex-1 flex flex-col space-y-4">
<div class="flex items-center justify-between pb-3 border-b border-slate-200">
<div>
<h2 class="font-bold text-sm text-slate-900">{{ selectedObj.label }} ({{ selectedObj.name }})</h2>
<span class="text-[11px] text-slate-500">API Endpoint: <code>/api/custom/{{ selectedObj.name }}/</code></span>
</div>
<!-- Right Pane: Fields & Record Browser -->
<div class="flex-1 bg-white rounded-lg shadow-sm border border-slate-200 flex flex-col overflow-hidden">
<div v-if="selectedObj" class="flex-1 flex flex-col p-4 overflow-y-auto space-y-4">
<!-- Object Header -->
<div class="flex items-center justify-between pb-3 border-b border-slate-200">
<div>
<h2 class="text-lg font-bold text-slate-900 flex items-center gap-2">
<span>📦</span> {{ selectedObj.label }}
<code class="text-xs bg-slate-100 text-slate-700 px-2 py-0.5 rounded font-mono font-normal">{{ selectedObj.name }}</code>
</h2>
<p class="text-xs text-slate-500">{{ selectedObj.description || 'Custom data model with dynamic JSONB schema & GIN indexing' }}</p>
</div>
<button
@click="showAddFieldModal = true"
class="border border-slate-300 hover:bg-slate-50 text-slate-700 text-xs px-3 py-1.5 rounded font-medium transition"
>
+ Add Custom Field
</button>
</div>
<!-- Fields Table -->
<div>
<h3 class="font-semibold text-xs text-slate-800 mb-2">Object Fields & Meta-Schema</h3>
<div class="border border-slate-200 rounded overflow-hidden">
<table class="w-full text-left text-xs">
<thead class="bg-slate-100 text-slate-600 border-b border-slate-200">
<tr>
<th class="py-2 px-3">Field Label</th>
<th class="py-2 px-3">API Name</th>
<th class="py-2 px-3">Data Type</th>
<th class="py-2 px-3">Required</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
<tr v-for="field in crmStore.customFields" :key="field.id">
<td class="py-2 px-3 font-medium text-slate-900">{{ field.label }}</td>
<td class="py-2 px-3"><code class="text-brand-600">{{ field.name }}</code></td>
<td class="py-2 px-3 text-slate-600 uppercase text-[10px]">{{ field.field_type }}</td>
<td class="py-2 px-3 text-slate-600">{{ field.is_required ? 'Yes' : 'No' }}</td>
</tr>
<tr v-if="crmStore.customFields.length === 0">
<td colspan="4" class="py-4 text-center text-slate-400 italic">No custom fields defined on this object yet.</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Dynamic JSONB Record Creator & Feed -->
<div class="flex-1 flex flex-col pt-2">
<div class="flex items-center justify-between mb-2">
<h3 class="font-semibold text-xs text-slate-800">Dynamic Records (JSONB + GIN Index)</h3>
<button
@click="showAddFieldModal = true"
class="border border-slate-300 hover:bg-slate-50 text-slate-700 text-xs px-3 py-1.5 rounded font-medium transition"
@click="showCreateRecordModal = true"
class="bg-emerald-600 hover:bg-emerald-700 text-white text-[11px] font-semibold px-2.5 py-1 rounded transition"
>
+ Add Custom Field
+ Insert Record
</button>
</div>
<!-- Fields Table -->
<div>
<h3 class="font-semibold text-xs text-slate-800 mb-2">Object Fields & Meta-Schema</h3>
<div class="border border-slate-200 rounded overflow-hidden">
<table class="w-full text-left text-xs">
<thead class="bg-slate-100 text-slate-600 border-b border-slate-200">
<tr>
<th class="py-2 px-3">Field Label</th>
<th class="py-2 px-3">API Name</th>
<th class="py-2 px-3">Data Type</th>
<th class="py-2 px-3">Required</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
<tr v-for="field in crmStore.customFields" :key="field.id">
<td class="py-2 px-3 font-medium text-slate-900">{{ field.label }}</td>
<td class="py-2 px-3"><code class="text-brand-600">{{ field.name }}</code></td>
<td class="py-2 px-3 text-slate-600 uppercase text-[10px]">{{ field.field_type }}</td>
<td class="py-2 px-3 text-slate-600">{{ field.is_required ? 'Yes' : 'No' }}</td>
</tr>
<tr v-if="crmStore.customFields.length === 0">
<td colspan="4" class="py-4 text-center text-slate-400 italic">No custom fields defined on this object yet.</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Dynamic JSONB Record Creator & Feed -->
<div class="flex-1 flex flex-col pt-2">
<div class="flex items-center justify-between mb-2">
<h3 class="font-semibold text-xs text-slate-800">Dynamic Records (JSONB + GIN Index)</h3>
<button
@click="showCreateRecordModal = true"
class="bg-emerald-600 hover:bg-emerald-700 text-white text-[11px] font-semibold px-2.5 py-1 rounded transition"
>
+ Insert Record
</button>
</div>
<div class="border border-slate-200 rounded flex-1 overflow-y-auto p-2 bg-slate-50/50 space-y-2">
<div
v-for="rec in crmStore.customRecords"
:key="rec.id"
class="bg-white p-3 rounded border border-slate-200 shadow-xs text-xs font-mono"
>
<div class="flex items-center justify-between text-slate-400 text-[10px] mb-1">
<span>Record ID #{{ rec.id }}</span>
<span>Created: {{ new Date(rec.created_at).toLocaleTimeString() }}</span>
</div>
<pre class="text-[11px] text-slate-800 overflow-x-auto">{{ JSON.stringify(rec.data, null, 2) }}</pre>
</div>
<div v-if="crmStore.customRecords.length === 0" class="py-6 text-center text-slate-400 text-xs italic">
No records created for {{ selectedObj.name }} yet.
<div class="border border-slate-200 rounded flex-1 overflow-y-auto p-2 bg-slate-50/50 space-y-2">
<div
v-for="rec in crmStore.customRecords"
:key="rec.id"
class="bg-white p-3 rounded border border-slate-200 shadow-xs text-xs font-mono"
>
<div class="flex items-center justify-between text-slate-400 text-[10px] mb-1">
<span>Record ID #{{ rec.id }}</span>
<span>Created: {{ new Date(rec.created_at).toLocaleTimeString() }}</span>
</div>
<pre class="text-[11px] text-slate-800 overflow-x-auto">{{ JSON.stringify(rec.data, null, 2) }}</pre>
</div>
<div v-if="crmStore.customRecords.length === 0" class="py-6 text-center text-slate-400 text-xs italic">
No records created for {{ selectedObj.name }} yet.
</div>
</div>
</div>
</div>
<div v-else class="h-full flex items-center justify-center text-slate-400 text-xs italic">
Select a Custom Object on the left to inspect its fields and records.
</div>
<div v-else class="flex-1 flex flex-col items-center justify-center text-slate-400 text-xs">
<span>Select an object on the left to inspect its schema and data records.</span>
</div>
</div>
<!-- Create Custom Object Modal -->
<div v-if="showCreateObjectModal" class="fixed inset-0 bg-slate-900/40 backdrop-blur-xs flex items-center justify-center p-4 z-50">
<div class="bg-white rounded-xl shadow-2xl border border-slate-200 w-full max-w-sm p-5 space-y-3 text-xs">
<h2 class="font-bold text-slate-900 text-sm">New Custom Object</h2>
<div>
<label class="block font-medium text-slate-700 mb-1">Label</label>
<input v-model="newObj.label" type="text" placeholder="e.g. Invoice" class="w-full border border-slate-300 rounded px-2.5 py-1.5 outline-none focus:border-brand-500" />
<div v-if="showCreateObjectModal" class="fixed inset-0 bg-slate-900/50 backdrop-blur-xs flex items-center justify-center z-50 p-4">
<div class="bg-white rounded-lg shadow-xl border border-slate-200 max-w-sm w-full overflow-hidden">
<div class="px-4 py-3 border-b border-slate-200 bg-slate-50 flex items-center justify-between">
<h3 class="text-xs font-bold text-slate-800">New Custom Object</h3>
<button @click="showCreateObjectModal = false" class="text-slate-400 hover:text-slate-600">&times;</button>
</div>
<div>
<label class="block font-medium text-slate-700 mb-1">Plural Label</label>
<input v-model="newObj.plural_label" type="text" placeholder="e.g. Invoices" class="w-full border border-slate-300 rounded px-2.5 py-1.5 outline-none focus:border-brand-500" />
<div class="p-4 space-y-3">
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Label</label>
<input v-model="newObj.label" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs" placeholder="Warehouse" />
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Plural Label</label>
<input v-model="newObj.plural_label" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs" placeholder="Warehouses" />
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Object Name (API)</label>
<input v-model="newObj.name" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs font-mono" placeholder="warehouse__c" />
</div>
</div>
<div>
<label class="block font-medium text-slate-700 mb-1">API Name</label>
<input v-model="newObj.name" type="text" placeholder="e.g. invoice__c" class="w-full border border-slate-300 rounded px-2.5 py-1.5 outline-none focus:border-brand-500 font-mono" />
<div class="px-4 py-2.5 bg-slate-50 border-t border-slate-200 flex justify-end gap-2">
<button @click="showCreateObjectModal = false" class="px-3 py-1 border border-slate-300 rounded text-slate-700 hover:bg-slate-100 text-xs">Cancel</button>
<button @click="saveNewObject" class="px-3 py-1 bg-brand-600 hover:bg-brand-700 text-white rounded text-xs font-medium">Create Object</button>
</div>
<div class="flex justify-end gap-2 pt-2">
<button @click="showCreateObjectModal = false" class="px-3 py-1.5 border border-slate-300 rounded text-slate-700">Cancel</button>
<button @click="saveNewObject" class="px-4 py-1.5 bg-brand-500 hover:bg-brand-600 text-white font-medium rounded">Save Object</button>
</div>
</div>
<!-- Add Custom Field Modal -->
<div v-if="showAddFieldModal" class="fixed inset-0 bg-slate-900/50 backdrop-blur-xs flex items-center justify-center z-50 p-4">
<div class="bg-white rounded-lg shadow-xl border border-slate-200 max-w-sm w-full overflow-hidden">
<div class="px-4 py-3 border-b border-slate-200 bg-slate-50 flex items-center justify-between">
<h3 class="text-xs font-bold text-slate-800">Add Field to {{ selectedObj?.label }}</h3>
<button @click="showAddFieldModal = false" class="text-slate-400 hover:text-slate-600">&times;</button>
</div>
<div class="p-4 space-y-3">
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Field Label</label>
<input v-model="newField.label" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs" placeholder="Square Footage" />
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Field API Name</label>
<input v-model="newField.name" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs font-mono" placeholder="square_footage__c" />
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Data Type</label>
<select v-model="newField.field_type" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs">
<option value="text">Text</option>
<option value="number">Number</option>
<option value="boolean">Boolean</option>
<option value="date">Date</option>
<option value="email">Email</option>
<option value="url">URL</option>
</select>
</div>
<div class="flex items-center gap-2">
<input type="checkbox" v-model="newField.is_required" id="is_req" class="rounded text-brand-600 focus:ring-brand-500" />
<label for="is_req" class="text-xs font-semibold text-slate-700 cursor-pointer">Required Field</label>
</div>
</div>
<div class="px-4 py-2.5 bg-slate-50 border-t border-slate-200 flex justify-end gap-2">
<button @click="showAddFieldModal = false" class="px-3 py-1 border border-slate-300 rounded text-slate-700 hover:bg-slate-100 text-xs">Cancel</button>
<button @click="saveNewField" class="px-3 py-1 bg-brand-600 hover:bg-brand-700 text-white rounded text-xs font-medium">Save Field</button>
</div>
</div>
</div>
<!-- Insert Dynamic Record Modal -->
<div v-if="showCreateRecordModal" class="fixed inset-0 bg-slate-900/50 backdrop-blur-xs flex items-center justify-center z-50 p-4">
<div class="bg-white rounded-lg shadow-xl border border-slate-200 max-w-md w-full overflow-hidden">
<div class="px-4 py-3 border-b border-slate-200 bg-slate-50 flex items-center justify-between">
<h3 class="text-xs font-bold text-slate-800">Insert Record: {{ selectedObj?.label }}</h3>
<button @click="showCreateRecordModal = false" class="text-slate-400 hover:text-slate-600">&times;</button>
</div>
<div class="p-4 space-y-3">
<p class="text-xs text-slate-500">Enter field values dynamically according to the object's schema:</p>
<div v-for="field in crmStore.customFields" :key="field.id" class="space-y-1">
<label class="block text-xs font-semibold text-slate-700">
{{ field.label }} <code class="text-[10px] text-brand-600 font-mono">({{ field.name }})</code>
<span v-if="field.is_required" class="text-rose-500">*</span>
</label>
<input
v-if="field.field_type === 'number'"
v-model.number="recordFormData[field.name]"
type="number"
class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs"
:placeholder="`Enter ${field.label}`"
/>
<input
v-else-if="field.field_type === 'boolean'"
v-model="recordFormData[field.name]"
type="checkbox"
class="rounded text-brand-600 focus:ring-brand-500"
/>
<input
v-else
v-model="recordFormData[field.name]"
type="text"
class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs"
:placeholder="`Enter ${field.label}`"
/>
</div>
<div v-if="crmStore.customFields.length === 0" class="text-xs text-slate-400 italic">
This object has no custom fields defined yet.
</div>
</div>
<div class="px-4 py-2.5 bg-slate-50 border-t border-slate-200 flex justify-end gap-2">
<button @click="showCreateRecordModal = false" class="px-3 py-1 border border-slate-300 rounded text-slate-700 hover:bg-slate-100 text-xs">Cancel</button>
<button @click="saveNewRecord" class="px-3 py-1 bg-emerald-600 hover:bg-emerald-700 text-white rounded text-xs font-medium">Save Record</button>
</div>
</div>
</div>
@ -169,10 +253,20 @@ const newObj = ref({
name: ''
})
const newField = ref({
label: '',
name: '',
field_type: 'text',
is_required: false
})
const recordFormData = ref({})
async function selectObject(obj) {
selectedObj.value = obj
await crmStore.fetchCustomFields(obj.id)
await crmStore.fetchCustomRecords(obj.name)
recordFormData.value = {}
}
async function saveNewObject() {
@ -184,4 +278,21 @@ async function saveNewObject() {
showCreateObjectModal.value = false
newObj.value = { label: '', plural_label: '', name: '' }
}
async function saveNewField() {
if (!selectedObj.value || !newField.value.label) return
if (!newField.value.name.endsWith('__c')) {
newField.value.name = newField.value.name + '__c'
}
await crmStore.createCustomField(selectedObj.value.id, newField.value)
showAddFieldModal.value = false
newField.value = { label: '', name: '', field_type: 'text', is_required: false }
}
async function saveNewRecord() {
if (!selectedObj.value) return
await crmStore.createCustomRecord(selectedObj.value.name, recordFormData.value)
showCreateRecordModal.value = false
recordFormData.value = {}
}
</script>

View file

@ -259,18 +259,12 @@ async function runFlow() {
})
executionResult.value = res.data
} catch (err) {
// If flow 1 doesn't exist, execute inline fallback simulation
console.warn('Execute API call fallback:', err)
console.error('Execute API error:', err)
executionResult.value = {
status: 'completed',
steps_executed: ['start-trigger', 'decision-tier', 'assign-vip', 'subflow-sync'],
context_data: {
record: { id: 101, name: 'Acme Corp', amount: 75000 },
amount: 75000,
account_tier: 'VIP',
priority_score: 100,
sync_status: 'success'
}
status: 'failed',
error: err.response?.data?.detail || err.message || 'Execution failed',
steps_executed: [],
context_data: {}
}
} finally {
isRunning.value = false

View file

@ -31,69 +31,109 @@
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
<tr v-for="lead in crmStore.leads" :key="lead.id" class="hover:bg-slate-50/80 transition">
<td class="py-3 px-4 font-medium text-slate-900">
{{ lead.first_name }} {{ lead.last_name }}
<tr v-for="lead in crmStore.leads" :key="lead.id" class="hover:bg-slate-50 transition-colors">
<td class="py-2.5 px-4 font-semibold text-slate-800">{{ lead.first_name }} {{ lead.last_name }}</td>
<td class="py-2.5 px-4 text-slate-600">{{ lead.company }}</td>
<td class="py-2.5 px-4 text-slate-600">{{ lead.email }}</td>
<td class="py-2.5 px-4">
<span :class="getStatusBadgeClass(lead.status)">{{ lead.status }}</span>
</td>
<td class="py-3 px-4 text-slate-700">{{ lead.company }}</td>
<td class="py-3 px-4 text-slate-600">{{ lead.email || '—' }}</td>
<td class="py-3 px-4">
<span :class="getStatusBadgeClass(lead.status)">
{{ lead.status }}
</span>
<td class="py-2.5 px-4">
<div class="flex items-center gap-1.5">
<div class="w-12 bg-slate-200 h-1.5 rounded-full overflow-hidden">
<div class="bg-brand-500 h-full rounded-full" :style="{ width: `${lead.score || 40}%` }"></div>
</div>
<span class="text-[11px] text-slate-500 font-mono">{{ lead.score || 40 }}</span>
</div>
</td>
<td class="py-3 px-4">
<span class="inline-flex items-center px-2 py-0.5 rounded text-[11px] font-medium bg-amber-50 text-amber-700 border border-amber-200">
⚡ {{ lead.score || 0 }}
</span>
</td>
<td class="py-3 px-4 text-right space-x-2">
<td class="py-2.5 px-4 text-right">
<button
v-if="!lead.is_converted"
@click="openConvertModal(lead)"
class="bg-emerald-600 hover:bg-emerald-700 text-white font-medium text-[11px] px-2.5 py-1 rounded shadow-xs transition"
class="bg-emerald-50 text-emerald-700 hover:bg-emerald-100 border border-emerald-200 font-medium px-2 py-1 rounded text-[11px] transition shadow-2xs"
>
Convert
</button>
<span v-else class="text-xs text-slate-400 font-medium italic">
Converted ✓
</span>
<span v-else class="text-slate-400 text-[11px] italic">Converted</span>
</td>
</tr>
<tr v-if="crmStore.leads.length === 0">
<td colspan="6" class="py-8 text-center text-slate-400 italic">No leads found. Create your first lead above!</td>
<td colspan="6" class="text-center py-8 text-slate-400">No leads found. Click "+ New Lead" to create one.</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Convert Lead Modal -->
<div v-if="showConvertModal" class="fixed inset-0 bg-slate-900/40 backdrop-blur-xs flex items-center justify-center p-4 z-50">
<div class="bg-white rounded-xl shadow-2xl border border-slate-200 w-full max-w-md overflow-hidden animate-in fade-in zoom-in-95 duration-150">
<div class="px-5 py-4 bg-slate-50 border-b border-slate-200 flex items-center justify-between">
<h2 class="font-bold text-slate-900 text-sm flex items-center gap-2">
<span>🔄</span> Convert Lead: {{ selectedLead?.first_name }} {{ selectedLead?.last_name }}
</h2>
<button @click="showConvertModal = false" class="text-slate-400 hover:text-slate-600">✕</button>
<!-- Create Lead Modal -->
<div v-if="showCreateModal" class="fixed inset-0 bg-slate-900/50 backdrop-blur-xs flex items-center justify-center z-50 p-4">
<div class="bg-white rounded-lg shadow-xl border border-slate-200 max-w-md w-full overflow-hidden">
<div class="px-5 py-3.5 border-b border-slate-200 bg-slate-50 flex items-center justify-between">
<h3 class="text-sm font-bold text-slate-800">Create New Lead</h3>
<button @click="showCreateModal = false" class="text-slate-400 hover:text-slate-600 text-lg leading-none">&times;</button>
</div>
<div class="p-5 space-y-4 text-xs">
<div>
<label class="block font-medium text-slate-700 mb-1">Account Name</label>
<input v-model="convertForm.account_name" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 focus:border-brand-500 outline-none" />
</div>
<div class="flex items-center gap-2 pt-2">
<input v-model="convertForm.create_opportunity" type="checkbox" id="createOpp" class="rounded text-brand-500" />
<label for="createOpp" class="font-medium text-slate-800">Create Opportunity upon conversion</label>
</div>
<div v-if="convertForm.create_opportunity" class="space-y-3 pl-4 border-l-2 border-brand-500">
<div class="p-5 space-y-3">
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block font-medium text-slate-700 mb-1">Opportunity Name</label>
<input v-model="convertForm.opportunity_name" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 focus:border-brand-500 outline-none" />
<label class="block text-xs font-semibold text-slate-700 mb-1">First Name</label>
<input v-model="newLeadForm.first_name" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs focus:ring-1 focus:ring-brand-500" placeholder="Jane" />
</div>
<div>
<label class="block font-medium text-slate-700 mb-1">Expected Amount ($)</label>
<input v-model="convertForm.opportunity_amount" type="number" class="w-full border border-slate-300 rounded px-2.5 py-1.5 focus:border-brand-500 outline-none" />
<label class="block text-xs font-semibold text-slate-700 mb-1">Last Name *</label>
<input v-model="newLeadForm.last_name" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs focus:ring-1 focus:ring-brand-500" placeholder="Doe" required />
</div>
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Company *</label>
<input v-model="newLeadForm.company" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs focus:ring-1 focus:ring-brand-500" placeholder="Acme Inc." required />
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Email</label>
<input v-model="newLeadForm.email" type="email" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs focus:ring-1 focus:ring-brand-500" placeholder="jane@acme.com" />
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Status</label>
<select v-model="newLeadForm.status" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs">
<option value="New">New</option>
<option value="Contacted">Contacted</option>
<option value="Qualified">Qualified</option>
<option value="Unqualified">Unqualified</option>
</select>
</div>
</div>
<div class="px-5 py-3 bg-slate-50 border-t border-slate-200 flex justify-end gap-2">
<button @click="showCreateModal = false" class="px-3 py-1.5 border border-slate-300 rounded text-slate-700 hover:bg-slate-100 text-xs">Cancel</button>
<button @click="handleCreateLead" class="px-4 py-1.5 bg-brand-600 hover:bg-brand-700 text-white font-medium rounded text-xs shadow-xs">Save Lead</button>
</div>
</div>
</div>
<!-- Convert Lead Modal -->
<div v-if="showConvertModal" class="fixed inset-0 bg-slate-900/50 backdrop-blur-xs flex items-center justify-center z-50 p-4">
<div class="bg-white rounded-lg shadow-xl border border-slate-200 max-w-md w-full overflow-hidden">
<div class="px-5 py-3.5 border-b border-slate-200 bg-slate-50 flex items-center justify-between">
<h3 class="text-sm font-bold text-slate-800">Convert Lead: {{ selectedLead?.first_name }} {{ selectedLead?.last_name }}</h3>
<button @click="showConvertModal = false" class="text-slate-400 hover:text-slate-600 text-lg leading-none">&times;</button>
</div>
<div class="p-5 space-y-3">
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Account Name</label>
<input v-model="convertForm.account_name" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs focus:ring-1 focus:ring-brand-500" />
</div>
<div class="pt-2">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" v-model="convertForm.create_opportunity" class="rounded text-brand-600 focus:ring-brand-500" />
<span class="text-xs font-semibold text-slate-700">Create Opportunity</span>
</label>
</div>
<div v-if="convertForm.create_opportunity" class="space-y-3 pl-4 border-l-2 border-brand-200 mt-2">
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Opportunity Name</label>
<input v-model="convertForm.opportunity_name" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs focus:ring-1 focus:ring-brand-500" />
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Amount ($)</label>
<input v-model="convertForm.opportunity_amount" type="number" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs focus:ring-1 focus:ring-brand-500" />
</div>
</div>
</div>
@ -116,6 +156,14 @@ const showCreateModal = ref(false)
const showConvertModal = ref(false)
const selectedLead = ref(null)
const newLeadForm = ref({
first_name: '',
last_name: '',
company: '',
email: '',
status: 'New'
})
const convertForm = ref({
account_name: '',
create_opportunity: true,
@ -133,6 +181,13 @@ function getStatusBadgeClass(status) {
return map[status] || 'bg-slate-100 text-slate-700 px-2 py-0.5 rounded text-[11px]'
}
async function handleCreateLead() {
if (!newLeadForm.value.last_name || !newLeadForm.value.company) return
await crmStore.createLead(newLeadForm.value)
newLeadForm.value = { first_name: '', last_name: '', company: '', email: '', status: 'New' }
showCreateModal.value = false
}
function openConvertModal(lead) {
selectedLead.value = lead
convertForm.value.account_name = lead.company || `${lead.last_name} Household`

View file

@ -33,19 +33,19 @@
</span>
</div>
<!-- Metrics Grid -->
<!-- Metrics Grid (Live Data Only, No Fabricated Fallbacks) -->
<div class="grid grid-cols-4 gap-4 mt-4 pt-4 border-t border-slate-100 text-center">
<div class="bg-slate-50 p-2.5 rounded">
<div class="text-lg font-bold text-slate-800">{{ campaign.sent_count || 120 }}</div>
<div class="text-lg font-bold text-slate-800">{{ campaign.sent_count ?? 0 }}</div>
<div class="text-[10px] text-slate-500 uppercase font-semibold">Total Sent</div>
</div>
<div class="bg-emerald-50 p-2.5 rounded">
<div class="text-lg font-bold text-emerald-600">{{ campaign.open_count || 68 }}</div>
<div class="text-[10px] text-emerald-700 uppercase font-semibold">Opened (56.6%)</div>
<div class="text-lg font-bold text-emerald-600">{{ campaign.open_count ?? 0 }}</div>
<div class="text-[10px] text-emerald-700 uppercase font-semibold">Opened</div>
</div>
<div class="bg-blue-50 p-2.5 rounded">
<div class="text-lg font-bold text-blue-600">{{ campaign.click_count || 24 }}</div>
<div class="text-[10px] text-blue-700 uppercase font-semibold">Clicked (20.0%)</div>
<div class="text-lg font-bold text-blue-600">{{ campaign.click_count ?? 0 }}</div>
<div class="text-[10px] text-blue-700 uppercase font-semibold">Clicked</div>
</div>
<div class="bg-purple-50 p-2.5 rounded">
<div class="text-lg font-bold text-purple-600">1x1 Pixel</div>
@ -58,6 +58,37 @@
No campaigns launched yet. Click "+ Launch Campaign" above!
</div>
</div>
<!-- Launch Campaign Modal -->
<div v-if="showDispatchModal" class="fixed inset-0 bg-slate-900/50 backdrop-blur-xs flex items-center justify-center z-50 p-4">
<div class="bg-white rounded-lg shadow-xl border border-slate-200 max-w-md w-full overflow-hidden">
<div class="px-4 py-3 border-b border-slate-200 bg-slate-50 flex items-center justify-between">
<h3 class="text-xs font-bold text-slate-800">Launch New Outreach Campaign</h3>
<button @click="showDispatchModal = false" class="text-slate-400 hover:text-slate-600">&times;</button>
</div>
<div class="p-4 space-y-3">
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Campaign Name</label>
<input v-model="newCampaign.name" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs" placeholder="Q4 Enterprise Outreach" />
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Email Subject</label>
<input v-model="newCampaign.subject" type="text" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs" placeholder="Personalized demo for {{first_name}}" />
</div>
<div>
<label class="block text-xs font-semibold text-slate-700 mb-1">Target Object</label>
<select v-model="newCampaign.target_object" class="w-full border border-slate-300 rounded px-2.5 py-1.5 text-xs">
<option value="Lead">Leads</option>
<option value="Contact">Contacts</option>
</select>
</div>
</div>
<div class="px-4 py-2.5 bg-slate-50 border-t border-slate-200 flex justify-end gap-2">
<button @click="showDispatchModal = false" class="px-3 py-1 border border-slate-300 rounded text-slate-700 hover:bg-slate-100 text-xs">Cancel</button>
<button @click="handleLaunchCampaign" class="px-3 py-1 bg-brand-600 hover:bg-brand-700 text-white rounded text-xs font-medium">Create & Launch</button>
</div>
</div>
</div>
</div>
</template>
@ -68,9 +99,22 @@ import { useCrmStore } from '../stores/crm'
const crmStore = useCrmStore()
const showDispatchModal = ref(false)
const newCampaign = ref({
name: '',
subject: '',
target_object: 'Lead'
})
function getStatusClass(status) {
if (status === 'Sent') return 'bg-emerald-50 text-emerald-700 border border-emerald-200 px-2 py-0.5 rounded text-[11px] font-medium'
if (status === 'Sending') return 'bg-blue-50 text-blue-700 border border-blue-200 px-2 py-0.5 rounded text-[11px] font-medium animate-pulse'
return 'bg-slate-100 text-slate-700 px-2 py-0.5 rounded text-[11px] font-medium'
}
async function handleLaunchCampaign() {
if (!newCampaign.value.name || !newCampaign.value.subject) return
await crmStore.createCampaign(newCampaign.value)
showDispatchModal.value = false
newCampaign.value = { name: '', subject: '', target_object: 'Lead' }
}
</script>

View file

@ -0,0 +1,62 @@
import pytest
from workflows.engine import execute_flow_dag
def test_diamond_rejoin_execution():
"""
Graph Topology:
start -> decision
decision -> (winning handle) -> node_a -> join_node
decision -> (losing handle) -> node_b -> join_node
Both node_a and node_b connect to join_node.
join_node must execute when branch A is chosen.
node_b must NOT execute.
"""
graph = {
"nodes": [
{"id": "start", "type": "trigger", "data": {}},
{
"id": "decision",
"type": "decision",
"data": {
"outcomes": [
{
"id": "path_a",
"rules": [{"field": "status", "operator": "equals", "value": "A"}]
},
{
"id": "path_b",
"rules": [{"field": "status", "operator": "equals", "value": "B"}]
}
]
}
},
{
"id": "node_a",
"type": "assignment",
"data": {"variable": "executed_a", "operator": "equals", "value": True}
},
{
"id": "node_b",
"type": "assignment",
"data": {"variable": "executed_b", "operator": "equals", "value": True}
},
{
"id": "join_node",
"type": "assignment",
"data": {"variable": "executed_join", "operator": "equals", "value": True}
}
],
"edges": [
{"source": "start", "target": "decision"},
{"source": "decision", "target": "node_a", "sourceHandle": "path_a"},
{"source": "decision", "target": "node_b", "sourceHandle": "path_b"},
{"source": "node_a", "target": "join_node"},
{"source": "node_b", "target": "join_node"}
]
}
result = execute_flow_dag(graph, initial_context={"status": "A"})
ctx = result if isinstance(result, dict) else result.context
assert ctx.get("executed_a") is True, "Branch A should have executed"
assert ctx.get("executed_b") is not True, "Branch B must NEVER execute"
assert ctx.get("executed_join") is True, "Diamond join node MUST execute when reached via Branch A"

View file

@ -0,0 +1,38 @@
import pytest
from django.db import transaction
from crm_core.models import Account
from workflows.models import FlowDefinition
@pytest.mark.django_db(transaction=True)
def test_flow_failure_rolls_back_triggering_record():
"""
Test that an active record-triggered flow failure rolls back the triggering record
outside of implicit test transactions.
"""
# Create an active flow that intentionally fails
failing_dag = {
"nodes": [
{"id": "start", "type": "trigger", "data": {}},
{"id": "step_fail", "type": "subflow", "data": {"flow_id": 999999}} # Will raise ValidationError
],
"edges": [
{"source": "start", "target": "step_fail"}
]
}
FlowDefinition.objects.create(
name="Failing Trigger Flow",
trigger_type="record_created",
trigger_object="Account",
is_active=True,
graph=failing_dag
)
account_name = "Doomed Transaction Account"
# Attempt to create Account in an atomic block
with pytest.raises(Exception):
with transaction.atomic():
Account.objects.create(name=account_name)
# Verify that the Account was rolled back and does not exist in the database
exists = Account.objects.filter(name=account_name).exists()
assert not exists, "Account creation MUST be rolled back when record-triggered flow fails!"

View file

@ -0,0 +1,70 @@
import pytest
from workflows.engine import execute_flow_dag
from workflows.models import FlowDefinition
@pytest.mark.django_db
def test_vue_flow_initial_graph_executes_successfully():
subflow = FlowDefinition.objects.create(
name="Child Sync Subflow",
graph={"nodes": [{"id": "sub_start", "type": "trigger", "data": {}}], "edges": []}
)
vue_graph = {
"nodes": [
{
"id": "start-trigger",
"type": "input",
"data": {"type": "trigger"}
},
{
"id": "decision-tier",
"type": "decision",
"data": {
"conditions": [
{"field": "amount", "op": "gte", "value": 50000, "target_node": "assign-vip"},
{"field": "amount", "op": "gte", "value": 10000, "target_node": "assign-standard"}
],
"default_target": "assign-standard"
}
},
{
"id": "assign-vip",
"type": "assignment",
"data": {
"assignments": [
{"variable": "account_tier", "op": "equals", "value": "VIP"},
{"variable": "priority_score", "op": "add", "value": 100}
]
}
},
{
"id": "assign-standard",
"type": "assignment",
"data": {
"assignments": [
{"variable": "account_tier", "op": "equals", "value": "Standard"},
{"variable": "priority_score", "op": "add", "value": 10}
]
}
},
{
"id": "subflow-sync",
"type": "subflow",
"data": {
"subflow_id": subflow.id
}
}
],
"edges": [
{"id": "e1-2", "source": "start-trigger", "target": "decision-tier"},
{"id": "e2-3", "source": "decision-tier", "target": "assign-vip"},
{"id": "e2-4", "source": "decision-tier", "target": "assign-standard"},
{"id": "e3-5", "source": "assign-vip", "target": "subflow-sync"},
{"id": "e4-5", "source": "assign-standard", "target": "subflow-sync"}
]
}
res = execute_flow_dag(vue_graph, initial_context={"amount": 75000})
ctx = res if isinstance(res, dict) else res.context
assert ctx.get("account_tier") == "VIP", f"Expected VIP, got {ctx.get('account_tier')}"
assert ctx.get("priority_score") == 100, f"Expected 100, got {ctx.get('priority_score')}"

View file

@ -104,9 +104,9 @@ def on_record_post_save(sender, instance, created, **kwargs):
_set_active_flow_depth(depth + 1)
try:
for flow in flows:
try:
dispatch_flow(flow, context=context)
except Exception as e:
logger.error(f"Error executing flow {flow.id} on {trigger_type}: {e}")
# Under Salesforce transactional contract (docs/SALESFORCE_FLOW_ENGINE_SPEC.md:108),
# an unhandled failure in a synchronous record-triggered flow must fail
# the transaction and roll back the triggering record modification.
dispatch_flow(flow, context=context)
finally:
_set_active_flow_depth(depth)

View file

@ -123,6 +123,34 @@ def evaluate_outcome(outcome, context):
return False
def _evaluate_decision_node(node_data, context):
"""
Evaluates a Decision node either using outcomes list or conditions list.
Returns (matched_handle, target_node_id).
"""
outcomes = node_data.get('outcomes', [])
if outcomes:
for outcome in outcomes:
conds = outcome.get('conditions', [])
logic = outcome.get('logic', 'ALL')
if _evaluate_condition(conds, logic, context):
return outcome.get('handle', 'default'), outcome.get('target_node')
return 'default', node_data.get('default_target_node')
conditions = node_data.get('conditions', [])
if conditions:
for cond in conditions:
field = cond.get('field')
op = cond.get('op') or cond.get('operator')
val = cond.get('value')
target = cond.get('target_node')
if _evaluate_single_condition(field, op, val, context):
return 'match', target
return 'default', node_data.get('default_target_node')
return 'default', node_data.get('default_target_node')
def execute_flow_dag(flow_or_graph, initial_context=None, idempotency_key=None, depth=0):
from .models import FlowDefinition, FlowExecutionLog
@ -192,7 +220,7 @@ def execute_flow_dag(flow_or_graph, initial_context=None, idempotency_key=None,
continue
node = node_map.get(node_id, {})
node_type = node.get('type')
node_type = node.get('type') or node_data.get('type')
node_data = node.get('data', {})
step_record = {
@ -233,46 +261,99 @@ def execute_flow_dag(flow_or_graph, initial_context=None, idempotency_key=None,
inst.save()
elif node_type == 'assignment':
var_name = node_data.get('variable')
op = node_data.get('operator', 'equals')
val = node_data.get('value')
if var_name:
if op in ('equals', '=', None):
context[var_name] = val
elif op in ('add', '+='):
curr = context.get(var_name, 0)
context[var_name] = curr + val
elif op in ('subtract', '-='):
curr = context.get(var_name, 0)
context[var_name] = curr - val
# Handle single assignment fields or assignments array
assignments = node_data.get('assignments')
if assignments and isinstance(assignments, list):
for item in assignments:
var_name = item.get('variable')
op = item.get('op') or item.get('operator', 'equals')
val = item.get('value')
if var_name:
if op in ('equals', '=', None):
context[var_name] = val
elif op in ('add', '+='):
curr = context.get(var_name, 0)
context[var_name] = curr + val
elif op in ('subtract', '-='):
curr = context.get(var_name, 0)
context[var_name] = curr - val
else:
var_name = node_data.get('variable')
op = node_data.get('operator', 'equals')
val = node_data.get('value')
if var_name:
if op in ('equals', '=', None):
context[var_name] = val
elif op in ('add', '+='):
curr = context.get(var_name, 0)
context[var_name] = curr + val
elif op in ('subtract', '-='):
curr = context.get(var_name, 0)
context[var_name] = curr - val
elif node_type == 'decision':
outcomes = node_data.get('outcomes', [])
conditions = node_data.get('conditions', [])
winning_handle = None
for outcome in outcomes:
if evaluate_outcome(outcome, context):
winning_handle = outcome.get('id')
break
direct_target = None
# Disable paths from unchosen handles
if outcomes:
for outcome in outcomes:
if evaluate_outcome(outcome, context):
winning_handle = outcome.get('id')
break
elif conditions:
for cond in conditions:
field = cond.get('field')
op = cond.get('op') or cond.get('operator')
val = cond.get('value')
tgt = cond.get('target_node')
if evaluate_condition({'field': field, 'operator': op, 'value': val}, context):
direct_target = tgt
break
if not direct_target:
direct_target = node_data.get('default_target_node') or node_data.get('default_target')
# The decision routes only down the winning outcome handle or direct target
node_edges = outgoing_edges.get(node_id, [])
chosen_targets = set()
unchosen_targets = set()
for e in node_edges:
handle = e.get('sourceHandle')
target = e.get('target')
if handle != winning_handle:
# Disable target and all downstream exclusively reached nodes
downstream = [target]
visited_sub = set()
while downstream:
d = downstream.pop()
if d not in visited_sub:
visited_sub.add(d)
disabled_nodes.add(d)
for nxt_edge in outgoing_edges.get(d, []):
downstream.append(nxt_edge.get('target'))
if direct_target:
if target == direct_target:
chosen_targets.add(target)
else:
unchosen_targets.add(target)
elif winning_handle:
if handle == winning_handle:
chosen_targets.add(target)
else:
unchosen_targets.add(target)
else:
unchosen_targets.add(target)
# For every unchosen target branch, disable it ONLY if it is not reachable
# from any chosen branch (handles diamond join topologies)
def get_all_reachable(starts):
reachable = set()
queue = list(starts)
while queue:
curr = queue.pop()
if curr not in reachable:
reachable.add(curr)
for nxt_edge in outgoing_edges.get(curr, []):
queue.append(nxt_edge.get('target'))
return reachable
chosen_reachable = get_all_reachable(chosen_targets)
unchosen_exclusive = get_all_reachable(unchosen_targets) - chosen_reachable
for d in unchosen_exclusive:
disabled_nodes.add(d)
elif node_type == 'subflow':
child_flow_id = node_data.get('flow_id')
child_flow_id = node_data.get('flow_id') or node_data.get('subflow_id')
if not child_flow_id:
raise ValidationError("Subflow node requires flow_id.")
child_flow = FlowDefinition.objects.filter(pk=child_flow_id).first()