Display rowaction
This commit is contained in:
parent
3c9c988d8c
commit
a6f51caa46
|
@ -17,7 +17,7 @@ import {
|
||||||
import { definitions } from "../../../automations/triggerInfo"
|
import { definitions } from "../../../automations/triggerInfo"
|
||||||
import automations from "."
|
import automations from "."
|
||||||
|
|
||||||
interface PersistedAutomation extends Automation {
|
export interface PersistedAutomation extends Automation {
|
||||||
_id: string
|
_id: string
|
||||||
_rev: string
|
_rev: string
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
AutomationActionStepId,
|
AutomationActionStepId,
|
||||||
AutomationBuilderData,
|
AutomationBuilderData,
|
||||||
AutomationTriggerStepId,
|
AutomationTriggerStepId,
|
||||||
|
TableRowActions,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import sdk from "src/sdk"
|
import sdk from "src/sdk"
|
||||||
|
|
||||||
|
@ -25,6 +26,16 @@ export async function getBuilderData(
|
||||||
return tableNameCache[tableId]
|
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> = {}
|
const result: Record<string, AutomationBuilderData> = {}
|
||||||
for (const automation of automations) {
|
for (const automation of automations) {
|
||||||
const { trigger } = automation.definition
|
const { trigger } = automation.definition
|
||||||
|
@ -34,13 +45,17 @@ export async function getBuilderData(
|
||||||
continue
|
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!] = {
|
result[automation._id!] = {
|
||||||
displayName: `${tableName}: ${automation.name}`,
|
displayName: `${tableName}: ${automation.name}`,
|
||||||
triggerInfo: {
|
triggerInfo: {
|
||||||
title: "Automation trigger",
|
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")
|
throw new Error("Could not get the current appId")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const newRowActionId = `${
|
||||||
|
VirtualDocumentType.ROW_ACTION
|
||||||
|
}${SEPARATOR}${utils.newid()}`
|
||||||
|
|
||||||
const automation = await automations.create({
|
const automation = await automations.create({
|
||||||
name: `${tableName}: ${action.name}`,
|
name: `${tableName}: ${action.name}`,
|
||||||
appId,
|
appId,
|
||||||
|
@ -68,6 +72,7 @@ export async function create(tableId: string, rowAction: { name: string }) {
|
||||||
stepId: AutomationTriggerStepId.ROW_ACTION,
|
stepId: AutomationTriggerStepId.ROW_ACTION,
|
||||||
inputs: {
|
inputs: {
|
||||||
tableId,
|
tableId,
|
||||||
|
rowActionId: newRowActionId,
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
inputs: {
|
inputs: {
|
||||||
|
@ -88,16 +93,15 @@ export async function create(tableId: string, rowAction: { name: string }) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const newId = `${VirtualDocumentType.ROW_ACTION}${SEPARATOR}${utils.newid()}`
|
doc.actions[newRowActionId] = {
|
||||||
doc.actions[newId] = {
|
|
||||||
name: action.name,
|
name: action.name,
|
||||||
automationId: automation._id!,
|
automationId: automation._id!,
|
||||||
}
|
}
|
||||||
await db.put(doc)
|
await db.put(doc)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: newId,
|
id: newRowActionId,
|
||||||
...doc.actions[newId],
|
...doc.actions[newRowActionId],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue