Allow deleting row actions from automations

This commit is contained in:
Andrew Kingston 2024-08-22 16:58:12 +01:00
parent c7a4fddd11
commit 2a67c0e09e
No known key found for this signature in database
2 changed files with 50 additions and 41 deletions

View File

@ -22,6 +22,7 @@
await automationStore.actions.delete(automation) await automationStore.actions.delete(automation)
notifications.success("Automation deleted successfully") notifications.success("Automation deleted successfully")
} catch (error) { } catch (error) {
console.error(error)
notifications.error("Error deleting automation") notifications.error("Error deleting automation")
} }
} }
@ -37,41 +38,7 @@
const getContextMenuItems = () => { const getContextMenuItems = () => {
const isRowAction = sdk.automations.isRowAction(automation) const isRowAction = sdk.automations.isRowAction(automation)
const result = [] const pause = {
if (!isRowAction) {
result.push(
...[
{
icon: "Delete",
name: "Delete",
keyBind: null,
visible: true,
disabled: false,
callback: confirmDeleteDialog.show,
},
{
icon: "Edit",
name: "Edit",
keyBind: null,
visible: true,
disabled: !automation.definition.trigger,
callback: updateAutomationDialog.show,
},
{
icon: "Duplicate",
name: "Duplicate",
keyBind: null,
visible: true,
disabled:
!automation.definition.trigger ||
automation.definition.trigger?.name === "Webhook",
callback: duplicateAutomation,
},
]
)
}
result.push({
icon: automation.disabled ? "CheckmarkCircle" : "Cancel", icon: automation.disabled ? "CheckmarkCircle" : "Cancel",
name: automation.disabled ? "Activate" : "Pause", name: automation.disabled ? "Activate" : "Pause",
keyBind: null, keyBind: null,
@ -83,8 +50,41 @@
automation.disabled automation.disabled
) )
}, },
}) }
return result const del = {
icon: "Delete",
name: "Delete",
keyBind: null,
visible: true,
disabled: false,
callback: confirmDeleteDialog.show,
}
if (!isRowAction) {
return [
{
icon: "Edit",
name: "Edit",
keyBind: null,
visible: true,
disabled: !automation.definition.trigger,
callback: updateAutomationDialog.show,
},
{
icon: "Duplicate",
name: "Duplicate",
keyBind: null,
visible: true,
disabled:
!automation.definition.trigger ||
automation.definition.trigger?.name === "Webhook",
callback: duplicateAutomation,
},
pause,
del,
]
} else {
return [pause, del]
}
} }
const openContextMenu = e => { const openContextMenu = e => {

View File

@ -6,6 +6,7 @@ import { createHistoryStore } from "stores/builder/history"
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
import { updateReferencesInObject } from "dataBinding" import { updateReferencesInObject } from "dataBinding"
import { AutomationTriggerStepId } from "@budibase/types" import { AutomationTriggerStepId } from "@budibase/types"
import { sdk } from "@budibase/shared-core"
const initialAutomationState = { const initialAutomationState = {
automations: [], automations: [],
@ -123,10 +124,18 @@ const automationActions = store => ({
return response.automation return response.automation
}, },
delete: async automation => { delete: async automation => {
await API.deleteAutomation({ const isRowAction = sdk.automations.isRowAction(automation)
automationId: automation?._id, if (isRowAction) {
automationRev: automation?._rev, await API.rowActions.delete({
}) tableId: automation.definition.trigger.inputs.tableId,
rowActionId: automation.definition.trigger.inputs.rowActionId,
})
} else {
await API.deleteAutomation({
automationId: automation?._id,
automationRev: automation?._rev,
})
}
store.update(state => { store.update(state => {
// Remove the automation // Remove the automation