1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

Moving logic to frontend - definitions are returned unless they are deprecated, frontend decides which it can use to create.

This commit is contained in:
mike12345567 2024-07-30 16:04:33 +01:00
parent 8badd7b83e
commit 8f7a88ce86
6 changed files with 39 additions and 27 deletions

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

@ -1,10 +1,7 @@
import * as triggers from "../../automations/triggers"
import { sdk as coreSdk } from "@budibase/shared-core"
import { DocumentType } from "../../db/utils"
import {
updateTestHistory,
removeInvalidDefinitions,
} from "../../automations/utils"
import { updateTestHistory, removeDeprecated } from "../../automations/utils"
import { setTestFlag, clearTestFlag } from "../../utilities/redis"
import { context, cache, events, db as dbCore } from "@budibase/backend-core"
import { automations, features } from "@budibase/pro"
@ -23,11 +20,11 @@ import { builderSocket } from "../../websockets"
import env from "../../environment"
async function getActionDefinitions() {
return removeInvalidDefinitions(await actionDefs())
return removeDeprecated(await actionDefs())
}
function getTriggerDefinitions() {
return removeInvalidDefinitions(triggers.TRIGGER_DEFINITIONS)
return removeDeprecated(triggers.TRIGGER_DEFINITIONS)
}
/*************************

View file

@ -14,7 +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 { removeInvalidDefinitions } from "../../../automations/utils"
import { removeDeprecated } from "../../../automations/utils"
const MAX_RETRIES = 4
let {
@ -71,14 +71,14 @@ describe("/automations", () => {
.expect(200)
let definitionsLength = Object.keys(
removeInvalidDefinitions(BUILTIN_ACTION_DEFINITIONS)
removeDeprecated(BUILTIN_ACTION_DEFINITIONS)
).length
expect(Object.keys(res.body.action).length).toBeGreaterThanOrEqual(
definitionsLength
)
expect(Object.keys(res.body.trigger).length).toEqual(
Object.keys(removeInvalidDefinitions(TRIGGER_DEFINITIONS)).length
Object.keys(removeDeprecated(TRIGGER_DEFINITIONS)).length
)
})
})

View file

@ -117,16 +117,12 @@ export async function updateTestHistory(
)
}
export function removeInvalidDefinitions(
export function removeDeprecated(
definitions: Record<string, AutomationStepSchema>
) {
const disallowedStepIds: (
| AutomationTriggerStepId
| AutomationActionStepId
)[] = [AutomationTriggerStepId.ROW_ACTION]
const base = cloneDeep(definitions)
for (let key of Object.keys(base)) {
if (base[key].deprecated || disallowedStepIds.includes(base[key].stepId)) {
if (base[key].deprecated) {
delete base[key]
}
}