From faf1d678fa70ae2d22e120d6ff277290d27ccdf1 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 18 Jul 2024 12:55:33 +0200 Subject: [PATCH] Create automation --- packages/server/src/sdk/app/rowActions.ts | 46 ++++++++++++++++++- .../types/src/documents/app/automation.ts | 1 + 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index 8bff216ab9..59c6d9bd40 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -2,10 +2,16 @@ 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 tables from "./tables" function ensureUniqueAndThrow( doc: TableRowActions, @@ -39,10 +45,48 @@ export async function create(tableId: string, rowAction: { name: string }) { doc = { _id: rowActionsId, actions: {} } } + const { name: tableName } = await tables.getTable(tableId) + ensureUniqueAndThrow(doc, action.name) + const automation = await automations.create({ + name: `${tableName}: ${action.name}`, + appId: context.getAppId()!, + definition: { + trigger: { + type: AutomationStepType.TRIGGER, + id: "TODO id", + tagline: "TODO tagline", + name: "Row Action", + description: "TODO description", + icon: "Workflow", + stepId: AutomationTriggerStepId.ROW_ACTION, + inputs: { + tableId, + }, + schema: { + inputs: { + properties: { + tableId: { + type: AutomationIOType.STRING, + customType: AutomationCustomIOType.TABLE, + title: "Table", + }, + }, + required: ["tableId"], + }, + outputs: { properties: {} }, + }, + }, + steps: [], + }, + }) + const newId = `${VirtualDocumentType.ROW_ACTION}${SEPARATOR}${utils.newid()}` - doc.actions[newId] = action + doc.actions[newId] = { + name: action.name, + automationId: automation._id!, + } await db.put(doc) return { diff --git a/packages/types/src/documents/app/automation.ts b/packages/types/src/documents/app/automation.ts index 0432c11851..3407b1a6fd 100644 --- a/packages/types/src/documents/app/automation.ts +++ b/packages/types/src/documents/app/automation.ts @@ -45,6 +45,7 @@ export enum AutomationTriggerStepId { WEBHOOK = "WEBHOOK", APP = "APP", CRON = "CRON", + ROW_ACTION = "ROW_ACTION", } export enum AutomationStepType {