Merge pull request #14279 from Budibase/fix/hide-row-actions

Disallow adding row action automations
This commit is contained in:
Michael Drury 2024-07-30 16:17:36 +01:00 committed by GitHub
commit 3ddf801da6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 55 additions and 29 deletions

View File

@ -20,7 +20,7 @@
.map(automation => ({
...automation,
displayName:
$automationStore.automationDisplayData[automation._id].displayName ||
$automationStore.automationDisplayData[automation._id]?.displayName ||
automation.name,
}))
.sort((a, b) => {

View File

@ -21,7 +21,9 @@
$: nameError =
nameTouched && !name ? "Please specify a name for the automation." : null
$: triggers = Object.entries($automationStore.blockDefinitions.TRIGGER)
$: triggers = Object.entries(
$automationStore.blockDefinitions.CREATABLE_TRIGGER
)
async function createAutomation() {
try {

View File

@ -13,7 +13,7 @@
const { datasource } = getContext("grid")
$: triggers = $automationStore.blockDefinitions.TRIGGER
$: triggers = $automationStore.blockDefinitions.CREATABLE_TRIGGER
$: table = $tables.list.find(table => table._id === $datasource.tableId)

View File

@ -5,14 +5,16 @@ import { generate } from "shortid"
import { createHistoryStore } from "stores/builder/history"
import { notifications } from "@budibase/bbui"
import { updateReferencesInObject } from "dataBinding"
import { AutomationTriggerStepId } from "@budibase/types"
const initialAutomationState = {
automations: [],
testResults: null,
showTestPanel: false,
blockDefinitions: {
TRIGGER: [],
ACTION: [],
TRIGGER: {},
CREATABLE_TRIGGER: {},
ACTION: {},
},
selectedAutomationId: null,
automationDisplayData: {},
@ -46,14 +48,29 @@ const updateStepReferences = (steps, modifiedIndex, action) => {
})
}
const getFinalDefinitions = (triggers, actions) => {
const creatable = {}
Object.entries(triggers).forEach(entry => {
if (entry[0] === AutomationTriggerStepId.ROW_ACTION) {
return
}
creatable[entry[0]] = entry[1]
})
return {
TRIGGER: triggers,
CREATABLE_TRIGGER: creatable,
ACTION: actions,
}
}
const automationActions = store => ({
definitions: async () => {
const response = await API.getAutomationDefinitions()
store.update(state => {
state.blockDefinitions = {
TRIGGER: response.trigger,
ACTION: response.action,
}
state.blockDefinitions = getFinalDefinitions(
response.trigger,
response.action
)
return state
})
return response
@ -69,10 +86,10 @@ const automationActions = store => ({
return a.name < b.name ? -1 : 1
})
state.automationDisplayData = automationResponse.builderData
state.blockDefinitions = {
TRIGGER: definitions.trigger,
ACTION: definitions.action,
}
state.blockDefinitions = getFinalDefinitions(
definitions.trigger,
definitions.action
)
return state
})
},

View File

@ -14,6 +14,7 @@ import sdk from "../../../sdk"
import { Automation, FieldType, Table } from "@budibase/types"
import { mocks } from "@budibase/backend-core/tests"
import { FilterConditions } from "../../../automations/steps/filter"
import { removeDeprecated } from "../../../automations/utils"
const MAX_RETRIES = 4
let {
@ -69,14 +70,15 @@ describe("/automations", () => {
.expect("Content-Type", /json/)
.expect(200)
let definitionsLength = Object.keys(BUILTIN_ACTION_DEFINITIONS).length
definitionsLength-- // OUTGOING_WEBHOOK is deprecated
let definitionsLength = Object.keys(
removeDeprecated(BUILTIN_ACTION_DEFINITIONS)
).length
expect(Object.keys(res.body.action).length).toBeGreaterThanOrEqual(
definitionsLength
)
expect(Object.keys(res.body.trigger).length).toEqual(
Object.keys(TRIGGER_DEFINITIONS).length
Object.keys(removeDeprecated(TRIGGER_DEFINITIONS)).length
)
})
})

View File

@ -3,11 +3,15 @@ import { definitions } from "./triggerInfo"
import { automationQueue } from "./bullboard"
import { updateEntityMetadata } from "../utilities"
import { MetadataTypes } from "../constants"
import { db as dbCore, context, utils } from "@budibase/backend-core"
import { context, db as dbCore, utils } from "@budibase/backend-core"
import { getAutomationMetadataParams } from "../db/utils"
import { cloneDeep } from "lodash/fp"
import { quotas } from "@budibase/pro"
import { Automation, AutomationJob } from "@budibase/types"
import {
Automation,
AutomationJob,
AutomationStepSchema,
} from "@budibase/types"
import { automationsEnabled } from "../features"
import { helpers, REBOOT_CRON } from "@budibase/shared-core"
import tracer from "dd-trace"
@ -111,7 +115,9 @@ export async function updateTestHistory(
)
}
export function removeDeprecated(definitions: any) {
export function removeDeprecated(
definitions: Record<string, AutomationStepSchema>
) {
const base = cloneDeep(definitions)
for (let key of Object.keys(base)) {
if (base[key].deprecated) {

View File

@ -87,10 +87,10 @@ export async function fetch() {
include_docs: true,
})
)
return response.rows
.map(row => row.doc)
.filter(doc => !!doc)
.map(trimUnexpectedObjectFields)
const automations: PersistedAutomation[] = response.rows
.filter(row => !!row.doc)
.map(row => row.doc!)
return automations.map(trimUnexpectedObjectFields)
}
export async function get(automationId: string) {

View File

@ -29,8 +29,7 @@ export async function getBuilderData(
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
rowActionNameCache[tableId] = await sdk.rowActions.get(tableId)
}
return rowActionNameCache[tableId].actions[rowActionId]?.name
@ -45,9 +44,11 @@ export async function getBuilderData(
}
const { tableId, rowActionId } = automation.definition.trigger.inputs
if (!tableId || !rowActionId) {
continue
}
const tableName = await getTableName(tableId)
const rowActionName = await getRowActionName(tableId, rowActionId)
result[automation._id!] = {

View File

@ -174,9 +174,7 @@ export interface AutomationStepSchema {
deprecated?: boolean
stepId: AutomationTriggerStepId | AutomationActionStepId
blockToLoop?: string
inputs: {
[key: string]: any
}
inputs: Record<string, any>
schema: {
inputs: InputOutputBlock
outputs: InputOutputBlock