diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte
index f79b36b1ca..c263468f3b 100644
--- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte
+++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte
@@ -54,6 +54,7 @@
{
testDataModal.show()
}}
@@ -80,6 +81,7 @@
automation._id,
automation.disabled
)}
+ disabled={!$selectedAutomation?.definition?.trigger}
value={!automation.disabled}
/>
diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte
index df5ac3bd98..6e4d7c0099 100644
--- a/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte
+++ b/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte
@@ -54,7 +54,7 @@
name: "Edit",
keyBind: null,
visible: true,
- disabled: false,
+ disabled: !automation.definition.trigger,
callback: updateAutomationDialog.show,
},
{
@@ -62,7 +62,9 @@
name: "Duplicate",
keyBind: null,
visible: true,
- disabled: automation.definition.trigger.name === "Webhook",
+ disabled:
+ !automation.definition.trigger ||
+ automation.definition.trigger?.name === "Webhook",
callback: duplicateAutomation,
},
]
@@ -74,7 +76,7 @@
name: automation.disabled ? "Activate" : "Pause",
keyBind: null,
visible: true,
- disabled: false,
+ disabled: !automation.definition.trigger,
callback: () => {
automationStore.actions.toggleDisabled(
automation._id,
diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte
index 65a48a59f0..58eebfdd3e 100644
--- a/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte
+++ b/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte
@@ -30,12 +30,13 @@
})
$: groupedAutomations = filteredAutomations.reduce((acc, auto) => {
- acc[auto.definition.trigger.event] ??= {
- icon: auto.definition.trigger.icon,
- name: (auto.definition.trigger?.name || "").toUpperCase(),
+ const catName = auto.definition?.trigger?.event || "No Trigger"
+ acc[catName] ??= {
+ icon: auto.definition?.trigger?.icon || "AlertCircle",
+ name: (auto.definition?.trigger?.name || "No Trigger").toUpperCase(),
entries: [],
}
- acc[auto.definition.trigger.event].entries.push(auto)
+ acc[catName].entries.push(auto)
return acc
}, {})
diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js
index 57c823da9b..cab8090424 100644
--- a/packages/builder/src/stores/builder/automations.js
+++ b/packages/builder/src/stores/builder/automations.js
@@ -87,8 +87,6 @@ const automationActions = store => ({
disabled: false,
}
const response = await store.actions.save(automation)
- await store.actions.fetch()
- store.actions.select(response._id)
return response
},
duplicate: async automation => {
@@ -98,14 +96,13 @@ const automationActions = store => ({
_id: undefined,
_ref: undefined,
})
- await store.actions.fetch()
- store.actions.select(response._id)
return response
},
save: async automation => {
const response = await API.updateAutomation(automation)
await store.actions.fetch()
+ store.actions.select(response._id)
return response.automation
},
delete: async automation => {
@@ -113,18 +110,22 @@ const automationActions = store => ({
automationId: automation?._id,
automationRev: automation?._rev,
})
+
store.update(state => {
// Remove the automation
state.automations = state.automations.filter(
x => x._id !== automation._id
)
+
// Select a new automation if required
if (automation._id === state.selectedAutomationId) {
- store.actions.select(state.automations[0]?._id)
+ state.selectedAutomationId = state.automations[0]?._id || null
}
+
+ // Clear out automationDisplayData for the automation
+ delete state.automationDisplayData[automation._id]
return state
})
- await store.actions.fetch()
},
toggleDisabled: async automationId => {
let automation
@@ -381,7 +382,7 @@ export const selectedAutomation = derived(automationStore, $automationStore => {
export const selectedAutomationDisplayData = derived(
[automationStore, selectedAutomation],
([$automationStore, $selectedAutomation]) => {
- if (!$selectedAutomation._id) {
+ if (!$selectedAutomation?._id) {
return null
}
return $automationStore.automationDisplayData[$selectedAutomation._id]