Display rowaction
This commit is contained in:
parent
3c9c988d8c
commit
a6f51caa46
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<string, TableRowActions> = {}
|
||||
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<string, AutomationBuilderData> = {}
|
||||
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`,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue