From 2e47410979899963333010da755b751ba75f2515 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 24 Jul 2024 17:11:03 +0200 Subject: [PATCH] Reuse trigger --- .../src/automations/triggerInfo/index.ts | 11 +++++- .../src/automations/triggerInfo/rowAction.ts | 35 +++++++++++++++++++ packages/server/src/sdk/app/rowActions.ts | 26 ++------------ 3 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 packages/server/src/automations/triggerInfo/rowAction.ts diff --git a/packages/server/src/automations/triggerInfo/index.ts b/packages/server/src/automations/triggerInfo/index.ts index b35d915ea8..58a6fea3ad 100644 --- a/packages/server/src/automations/triggerInfo/index.ts +++ b/packages/server/src/automations/triggerInfo/index.ts @@ -1,15 +1,24 @@ +import { + AutomationTriggerSchema, + AutomationTriggerStepId, +} from "@budibase/types" import * as app from "./app" import * as cron from "./cron" import * as rowDeleted from "./rowDeleted" import * as rowSaved from "./rowSaved" import * as rowUpdated from "./rowUpdated" import * as webhook from "./webhook" +import * as rowAction from "./rowAction" -export const definitions = { +export const definitions: Record< + keyof typeof AutomationTriggerStepId, + AutomationTriggerSchema +> = { ROW_SAVED: rowSaved.definition, ROW_UPDATED: rowUpdated.definition, ROW_DELETED: rowDeleted.definition, WEBHOOK: webhook.definition, APP: app.definition, CRON: cron.definition, + ROW_ACTION: rowAction.definition, } diff --git a/packages/server/src/automations/triggerInfo/rowAction.ts b/packages/server/src/automations/triggerInfo/rowAction.ts new file mode 100644 index 0000000000..a7454e8606 --- /dev/null +++ b/packages/server/src/automations/triggerInfo/rowAction.ts @@ -0,0 +1,35 @@ +import { + AutomationCustomIOType, + AutomationIOType, + AutomationStepType, + AutomationTriggerSchema, + AutomationTriggerStepId, + AutomationEventType, +} from "@budibase/types" + +export const definition: AutomationTriggerSchema = { + type: AutomationStepType.TRIGGER, + tagline: + "Row action triggered in {{inputs.enriched.table.name}} by {{inputs.enriched.row._id}}", + name: "Row Action", + description: "TODO description", + icon: "Workflow", + stepId: AutomationTriggerStepId.ROW_ACTION, + inputs: {}, + schema: { + inputs: { + properties: { + tableId: { + type: AutomationIOType.STRING, + customType: AutomationCustomIOType.TABLE, + title: "Table", + readonly: true, + }, + }, + required: ["tableId"], + }, + outputs: { properties: {} }, + }, + + event: AutomationEventType.ROW_SAVE, +} diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index 01716a55b4..70c031939f 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -2,15 +2,12 @@ import { context, HTTPError, utils } from "@budibase/backend-core" import { generateRowActionsID } from "../../db/utils" import { - AutomationCustomIOType, - AutomationIOType, - AutomationStepType, - AutomationTriggerStepId, SEPARATOR, TableRowActions, VirtualDocumentType, } from "@budibase/types" import automations from "./automations" +import { TRIGGER_DEFINITIONS } from "../../automations" function ensureUniqueAndThrow( doc: TableRowActions, @@ -60,31 +57,12 @@ export async function create(tableId: string, rowAction: { name: string }) { appId, definition: { trigger: { - type: AutomationStepType.TRIGGER, id: "trigger", - tagline: "TODO tagline", - name: "Row Action", - description: "TODO description", - icon: "Workflow", - stepId: AutomationTriggerStepId.ROW_ACTION, + ...TRIGGER_DEFINITIONS.ROW_ACTION, inputs: { tableId, rowActionId: newRowActionId, }, - schema: { - inputs: { - properties: { - tableId: { - type: AutomationIOType.STRING, - customType: AutomationCustomIOType.TABLE, - title: "Table", - readonly: true, - }, - }, - required: ["tableId"], - }, - outputs: { properties: {} }, - }, }, steps: [], },