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)
notifications.success("Automation deleted successfully")
} catch (error) {
console.error(error)
notifications.error("Error deleting automation")
}
}
@ -37,41 +38,7 @@
const getContextMenuItems = () => {
const isRowAction = sdk.automations.isRowAction(automation)
const result = []
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({
const pause = {
icon: automation.disabled ? "CheckmarkCircle" : "Cancel",
name: automation.disabled ? "Activate" : "Pause",
keyBind: null,
@ -83,8 +50,41 @@
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 => {

View File

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