Dont persist row action name
This commit is contained in:
parent
7781e75491
commit
015854f1a2
|
@ -30,6 +30,16 @@ export async function find(ctx: Ctx<void, RowActionsResponse>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { actions } = rowActions
|
const { actions } = rowActions
|
||||||
|
const automations = await sdk.automations.find(
|
||||||
|
Object.values(actions).map(({ automationId }) => automationId)
|
||||||
|
)
|
||||||
|
const automationNames = automations.reduce<Record<string, string>>(
|
||||||
|
(names, a) => {
|
||||||
|
names[a._id] = a.name
|
||||||
|
return names
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
const result: RowActionsResponse = {
|
const result: RowActionsResponse = {
|
||||||
actions: Object.entries(actions).reduce<Record<string, RowActionResponse>>(
|
actions: Object.entries(actions).reduce<Record<string, RowActionResponse>>(
|
||||||
(acc, [key, action]) => ({
|
(acc, [key, action]) => ({
|
||||||
|
@ -37,7 +47,7 @@ export async function find(ctx: Ctx<void, RowActionsResponse>) {
|
||||||
[key]: {
|
[key]: {
|
||||||
id: key,
|
id: key,
|
||||||
tableId,
|
tableId,
|
||||||
name: action.name,
|
name: automationNames[action.automationId],
|
||||||
automationId: action.automationId,
|
automationId: action.automationId,
|
||||||
allowedSources: flattenAllowedSources(tableId, action.permissions),
|
allowedSources: flattenAllowedSources(tableId, action.permissions),
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,7 +2,6 @@ import {
|
||||||
Automation,
|
Automation,
|
||||||
AutomationActionStepId,
|
AutomationActionStepId,
|
||||||
AutomationBuilderData,
|
AutomationBuilderData,
|
||||||
TableRowActions,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { sdk as coreSdk } from "@budibase/shared-core"
|
import { sdk as coreSdk } from "@budibase/shared-core"
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
|
@ -26,15 +25,6 @@ export async function getBuilderData(
|
||||||
return tableNameCache[tableId]
|
return tableNameCache[tableId]
|
||||||
}
|
}
|
||||||
|
|
||||||
const rowActionNameCache: Record<string, TableRowActions | undefined> = {}
|
|
||||||
async function getRowActionName(tableId: string, rowActionId: string) {
|
|
||||||
if (!rowActionNameCache[tableId]) {
|
|
||||||
rowActionNameCache[tableId] = await sdk.rowActions.getAll(tableId)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 isRowAction = coreSdk.automations.isRowAction(automation)
|
const isRowAction = coreSdk.automations.isRowAction(automation)
|
||||||
|
@ -49,12 +39,7 @@ export async function getBuilderData(
|
||||||
}
|
}
|
||||||
|
|
||||||
const tableName = await getTableName(tableId)
|
const tableName = await getTableName(tableId)
|
||||||
const rowActionName = await getRowActionName(tableId, rowActionId)
|
const rowActionName = automation.name
|
||||||
|
|
||||||
if (!rowActionName) {
|
|
||||||
throw new Error(`Row action not found: ${rowActionId}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
result[automation._id!] = {
|
result[automation._id!] = {
|
||||||
displayName: rowActionName,
|
displayName: rowActionName,
|
||||||
triggerInfo: {
|
triggerInfo: {
|
||||||
|
|
|
@ -13,16 +13,17 @@ import { definitions as TRIGGER_DEFINITIONS } from "../../automations/triggerInf
|
||||||
import * as triggers from "../../automations/triggers"
|
import * as triggers from "../../automations/triggers"
|
||||||
import sdk from ".."
|
import sdk from ".."
|
||||||
|
|
||||||
function ensureUniqueAndThrow(
|
async function ensureUniqueAndThrow(
|
||||||
doc: TableRowActions,
|
doc: TableRowActions,
|
||||||
name: string,
|
name: string,
|
||||||
existingRowActionId?: string
|
existingRowActionId?: string
|
||||||
) {
|
) {
|
||||||
|
const names = await getNames(doc)
|
||||||
|
name = name.toLowerCase()
|
||||||
|
|
||||||
if (
|
if (
|
||||||
Object.entries(doc.actions).find(
|
Object.entries(names).find(
|
||||||
([id, a]) =>
|
([id, name]) => name === name && id !== existingRowActionId
|
||||||
a.name.toLowerCase() === name.toLowerCase() &&
|
|
||||||
id !== existingRowActionId
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
throw new HTTPError("A row action with the same name already exists.", 409)
|
throw new HTTPError("A row action with the same name already exists.", 409)
|
||||||
|
@ -34,18 +35,12 @@ export async function create(tableId: string, rowAction: { name: string }) {
|
||||||
|
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
const rowActionsId = generateRowActionsID(tableId)
|
const rowActionsId = generateRowActionsID(tableId)
|
||||||
let doc: TableRowActions
|
let doc = await db.tryGet<TableRowActions>(rowActionsId)
|
||||||
try {
|
if (!doc) {
|
||||||
doc = await db.get<TableRowActions>(rowActionsId)
|
|
||||||
} catch (e: any) {
|
|
||||||
if (e.status !== 404) {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
|
|
||||||
doc = { _id: rowActionsId, actions: {} }
|
doc = { _id: rowActionsId, actions: {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureUniqueAndThrow(doc, action.name)
|
await ensureUniqueAndThrow(doc, action.name)
|
||||||
|
|
||||||
const appId = context.getAppId()
|
const appId = context.getAppId()
|
||||||
if (!appId) {
|
if (!appId) {
|
||||||
|
@ -74,7 +69,6 @@ export async function create(tableId: string, rowAction: { name: string }) {
|
||||||
})
|
})
|
||||||
|
|
||||||
doc.actions[newRowActionId] = {
|
doc.actions[newRowActionId] = {
|
||||||
name: action.name,
|
|
||||||
automationId: automation._id!,
|
automationId: automation._id!,
|
||||||
permissions: {
|
permissions: {
|
||||||
table: { runAllowed: true },
|
table: { runAllowed: true },
|
||||||
|
@ -85,6 +79,7 @@ export async function create(tableId: string, rowAction: { name: string }) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: newRowActionId,
|
id: newRowActionId,
|
||||||
|
name: automation.name,
|
||||||
...doc.actions[newRowActionId],
|
...doc.actions[newRowActionId],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,3 +248,17 @@ export async function run(
|
||||||
{ getResponses: true }
|
{ getResponses: true }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getNames(actions: TableRowActions) {
|
||||||
|
const automations = await sdk.automations.find(
|
||||||
|
Object.values(actions).map(({ automationId }) => automationId)
|
||||||
|
)
|
||||||
|
const automationNames = automations.reduce<Record<string, string>>(
|
||||||
|
(names, a) => {
|
||||||
|
names[a._id] = a.name
|
||||||
|
return names
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
return automationNames
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ export interface TableRowActions extends Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RowActionData {
|
export interface RowActionData {
|
||||||
name: string
|
|
||||||
automationId: string
|
automationId: string
|
||||||
permissions: RowActionPermissions
|
permissions: RowActionPermissions
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue