From 6221b9320e21a44222979765e6e26102577c39d0 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 19 Jul 2024 12:24:45 +0200 Subject: [PATCH] Enrich --- .../builder/src/stores/builder/automations.js | 2 +- packages/frontend-core/src/api/automations.js | 8 +++++-- .../server/src/api/controllers/automation.ts | 9 +++++++- .../server/src/sdk/app/automations/crud.ts | 22 +++++++++++++++++-- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index a2ee4b3ccc..b6af177442 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -59,7 +59,7 @@ const automationActions = store => ({ }, fetch: async () => { const responses = await Promise.all([ - API.getAutomations(), + API.getAutomations({ enrich: true }), API.getAutomationDefinitions(), ]) store.update(state => { diff --git a/packages/frontend-core/src/api/automations.js b/packages/frontend-core/src/api/automations.js index 37a834cf04..863f98f5b9 100644 --- a/packages/frontend-core/src/api/automations.js +++ b/packages/frontend-core/src/api/automations.js @@ -26,9 +26,13 @@ export const buildAutomationEndpoints = API => ({ /** * Gets a list of all automations. */ - getAutomations: async () => { + getAutomations: async ({ enrich }) => { + let url = "/api/automations?" + if (enrich) { + url += "enrich=true" + } return await API.get({ - url: "/api/automations", + url, }) }, diff --git a/packages/server/src/api/controllers/automation.ts b/packages/server/src/api/controllers/automation.ts index 7eca17e0e8..b9b1793425 100644 --- a/packages/server/src/api/controllers/automation.ts +++ b/packages/server/src/api/controllers/automation.ts @@ -74,7 +74,14 @@ export async function update(ctx: UserCtx) { } export async function fetch(ctx: UserCtx) { - ctx.body = await sdk.automations.fetch() + const enrich = ctx.request.query["enrich"] === "true" + + const automations = await sdk.automations.fetch() + if (enrich) { + ctx.body = await sdk.automations.enrichDisplayData(automations) + } else { + ctx.body = automations + } } export async function find(ctx: UserCtx) { diff --git a/packages/server/src/sdk/app/automations/crud.ts b/packages/server/src/sdk/app/automations/crud.ts index 59b6b5dc2a..95b9d5895f 100644 --- a/packages/server/src/sdk/app/automations/crud.ts +++ b/packages/server/src/sdk/app/automations/crud.ts @@ -1,4 +1,9 @@ -import { Automation, Webhook, WebhookActionType } from "@budibase/types" +import { + Automation, + AutomationTriggerStepId, + Webhook, + WebhookActionType, +} from "@budibase/types" import { generateAutomationID, getAutomationParams } from "../../../db/utils" import { deleteEntityMetadata } from "../../../utilities" import { MetadataTypes } from "../../../constants" @@ -81,7 +86,7 @@ export async function fetch() { include_docs: true, }) ) - return response.rows.map(row => row.doc) + return response.rows.map(row => row.doc).filter(doc => !!doc) } export async function get(automationId: string) { @@ -254,6 +259,7 @@ async function checkForWebhooks({ oldAuto, newAuto }: any) { } return newAuto } + function guardInvalidUpdatesAndThrow( automation: Automation, oldAutomation: Automation @@ -281,3 +287,15 @@ function guardInvalidUpdatesAndThrow( }) } } + +export async function enrichDisplayData(automations: Automation[]) { + const rowActionAutomations = automations.filter( + ({ definition }) => + definition.trigger.stepId === AutomationTriggerStepId.ROW_ACTION + ) + + for (const automation of rowActionAutomations) { + automation.name = `TODO: ${automation.name}` + } + return automations +}