From 2a67c0e09e8994225408ae01930168963c418f3e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Aug 2024 16:58:12 +0100 Subject: [PATCH] Allow deleting row actions from automations --- .../AutomationPanel/AutomationNavItem.svelte | 74 +++++++++---------- .../builder/src/stores/builder/automations.js | 17 ++++- 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte index 6e4d7c0099..ee5bf1af46 100644 --- a/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte @@ -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 => { diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index fdb0991911..69a340d340 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -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