This commit is contained in:
Adria Navarro 2024-07-19 12:24:45 +02:00
parent 1b2182a690
commit 6221b9320e
4 changed files with 35 additions and 6 deletions

View File

@ -59,7 +59,7 @@ const automationActions = store => ({
}, },
fetch: async () => { fetch: async () => {
const responses = await Promise.all([ const responses = await Promise.all([
API.getAutomations(), API.getAutomations({ enrich: true }),
API.getAutomationDefinitions(), API.getAutomationDefinitions(),
]) ])
store.update(state => { store.update(state => {

View File

@ -26,9 +26,13 @@ export const buildAutomationEndpoints = API => ({
/** /**
* Gets a list of all automations. * Gets a list of all automations.
*/ */
getAutomations: async () => { getAutomations: async ({ enrich }) => {
let url = "/api/automations?"
if (enrich) {
url += "enrich=true"
}
return await API.get({ return await API.get({
url: "/api/automations", url,
}) })
}, },

View File

@ -74,7 +74,14 @@ export async function update(ctx: UserCtx) {
} }
export async function fetch(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) { export async function find(ctx: UserCtx) {

View File

@ -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 { generateAutomationID, getAutomationParams } from "../../../db/utils"
import { deleteEntityMetadata } from "../../../utilities" import { deleteEntityMetadata } from "../../../utilities"
import { MetadataTypes } from "../../../constants" import { MetadataTypes } from "../../../constants"
@ -81,7 +86,7 @@ export async function fetch() {
include_docs: true, 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) { export async function get(automationId: string) {
@ -254,6 +259,7 @@ async function checkForWebhooks({ oldAuto, newAuto }: any) {
} }
return newAuto return newAuto
} }
function guardInvalidUpdatesAndThrow( function guardInvalidUpdatesAndThrow(
automation: Automation, automation: Automation,
oldAutomation: 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
}