From a6f51caa46c1a028677d6af284bdb4062f649d62 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 22 Jul 2024 11:05:46 +0200 Subject: [PATCH] Display rowaction --- .../server/src/sdk/app/automations/crud.ts | 2 +- .../server/src/sdk/app/automations/utils.ts | 19 +++++++++++++++++-- packages/server/src/sdk/app/rowActions.ts | 12 ++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/server/src/sdk/app/automations/crud.ts b/packages/server/src/sdk/app/automations/crud.ts index 8836677039..9765ecd2f2 100644 --- a/packages/server/src/sdk/app/automations/crud.ts +++ b/packages/server/src/sdk/app/automations/crud.ts @@ -17,7 +17,7 @@ import { import { definitions } from "../../../automations/triggerInfo" import automations from "." -interface PersistedAutomation extends Automation { +export interface PersistedAutomation extends Automation { _id: string _rev: string } diff --git a/packages/server/src/sdk/app/automations/utils.ts b/packages/server/src/sdk/app/automations/utils.ts index 63a7d37bc1..fbd0b5700c 100644 --- a/packages/server/src/sdk/app/automations/utils.ts +++ b/packages/server/src/sdk/app/automations/utils.ts @@ -3,6 +3,7 @@ import { AutomationActionStepId, AutomationBuilderData, AutomationTriggerStepId, + TableRowActions, } from "@budibase/types" import sdk from "src/sdk" @@ -25,6 +26,16 @@ export async function getBuilderData( return tableNameCache[tableId] } + const rowActionNameCache: Record = {} + async function getRowActionName(tableId: string, rowActionId: string) { + if (!rowActionNameCache[tableId]) { + const rowActions = await sdk.rowActions.get(tableId) + rowActionNameCache[tableId] = rowActions + } + + return rowActionNameCache[tableId].actions[rowActionId]?.name + } + const result: Record = {} for (const automation of automations) { const { trigger } = automation.definition @@ -34,13 +45,17 @@ export async function getBuilderData( continue } - const tableName = await getTableName(trigger.inputs.tableId) + const { tableId, rowActionId } = trigger.inputs + + const tableName = await getTableName(tableId) + + const rowActionName = await getRowActionName(tableId, rowActionId) result[automation._id!] = { displayName: `${tableName}: ${automation.name}`, triggerInfo: { title: "Automation trigger", - description: `This trigger is tied to the row action TODO on your ${tableName} table`, + description: `This trigger is tied to the row action ${rowActionName} on your ${tableName} table`, }, } } diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index df5625cce3..abfc0f1478 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -54,6 +54,10 @@ export async function create(tableId: string, rowAction: { name: string }) { throw new Error("Could not get the current appId") } + const newRowActionId = `${ + VirtualDocumentType.ROW_ACTION + }${SEPARATOR}${utils.newid()}` + const automation = await automations.create({ name: `${tableName}: ${action.name}`, appId, @@ -68,6 +72,7 @@ export async function create(tableId: string, rowAction: { name: string }) { stepId: AutomationTriggerStepId.ROW_ACTION, inputs: { tableId, + rowActionId: newRowActionId, }, schema: { inputs: { @@ -88,16 +93,15 @@ export async function create(tableId: string, rowAction: { name: string }) { }, }) - const newId = `${VirtualDocumentType.ROW_ACTION}${SEPARATOR}${utils.newid()}` - doc.actions[newId] = { + doc.actions[newRowActionId] = { name: action.name, automationId: automation._id!, } await db.put(doc) return { - id: newId, - ...doc.actions[newId], + id: newRowActionId, + ...doc.actions[newRowActionId], } }