Moving logic to frontend - definitions are returned unless they are deprecated, frontend decides which it can use to create.
This commit is contained in:
parent
8badd7b83e
commit
8f7a88ce86
|
@ -21,7 +21,9 @@
|
||||||
|
|
||||||
$: nameError =
|
$: nameError =
|
||||||
nameTouched && !name ? "Please specify a name for the automation." : null
|
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() {
|
async function createAutomation() {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
const { datasource } = getContext("grid")
|
const { datasource } = getContext("grid")
|
||||||
|
|
||||||
$: triggers = $automationStore.blockDefinitions.TRIGGER
|
$: triggers = $automationStore.blockDefinitions.CREATABLE_TRIGGER
|
||||||
|
|
||||||
$: table = $tables.list.find(table => table._id === $datasource.tableId)
|
$: table = $tables.list.find(table => table._id === $datasource.tableId)
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,16 @@ import { generate } from "shortid"
|
||||||
import { createHistoryStore } from "stores/builder/history"
|
import { createHistoryStore } from "stores/builder/history"
|
||||||
import { notifications } from "@budibase/bbui"
|
import { notifications } from "@budibase/bbui"
|
||||||
import { updateReferencesInObject } from "dataBinding"
|
import { updateReferencesInObject } from "dataBinding"
|
||||||
|
import { AutomationTriggerStepId } from "@budibase/types"
|
||||||
|
|
||||||
const initialAutomationState = {
|
const initialAutomationState = {
|
||||||
automations: [],
|
automations: [],
|
||||||
testResults: null,
|
testResults: null,
|
||||||
showTestPanel: false,
|
showTestPanel: false,
|
||||||
blockDefinitions: {
|
blockDefinitions: {
|
||||||
TRIGGER: [],
|
TRIGGER: {},
|
||||||
ACTION: [],
|
CREATABLE_TRIGGER: {},
|
||||||
|
ACTION: {},
|
||||||
},
|
},
|
||||||
selectedAutomationId: null,
|
selectedAutomationId: null,
|
||||||
automationDisplayData: {},
|
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 => ({
|
const automationActions = store => ({
|
||||||
definitions: async () => {
|
definitions: async () => {
|
||||||
const response = await API.getAutomationDefinitions()
|
const response = await API.getAutomationDefinitions()
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
state.blockDefinitions = {
|
state.blockDefinitions = getFinalDefinitions(
|
||||||
TRIGGER: response.trigger,
|
response.trigger,
|
||||||
ACTION: response.action,
|
response.action
|
||||||
}
|
)
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
return response
|
return response
|
||||||
|
@ -69,10 +86,10 @@ const automationActions = store => ({
|
||||||
return a.name < b.name ? -1 : 1
|
return a.name < b.name ? -1 : 1
|
||||||
})
|
})
|
||||||
state.automationDisplayData = automationResponse.builderData
|
state.automationDisplayData = automationResponse.builderData
|
||||||
state.blockDefinitions = {
|
state.blockDefinitions = getFinalDefinitions(
|
||||||
TRIGGER: definitions.trigger,
|
definitions.trigger,
|
||||||
ACTION: definitions.action,
|
definitions.action
|
||||||
}
|
)
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import * as triggers from "../../automations/triggers"
|
import * as triggers from "../../automations/triggers"
|
||||||
import { sdk as coreSdk } from "@budibase/shared-core"
|
import { sdk as coreSdk } from "@budibase/shared-core"
|
||||||
import { DocumentType } from "../../db/utils"
|
import { DocumentType } from "../../db/utils"
|
||||||
import {
|
import { updateTestHistory, removeDeprecated } from "../../automations/utils"
|
||||||
updateTestHistory,
|
|
||||||
removeInvalidDefinitions,
|
|
||||||
} from "../../automations/utils"
|
|
||||||
import { setTestFlag, clearTestFlag } from "../../utilities/redis"
|
import { setTestFlag, clearTestFlag } from "../../utilities/redis"
|
||||||
import { context, cache, events, db as dbCore } from "@budibase/backend-core"
|
import { context, cache, events, db as dbCore } from "@budibase/backend-core"
|
||||||
import { automations, features } from "@budibase/pro"
|
import { automations, features } from "@budibase/pro"
|
||||||
|
@ -23,11 +20,11 @@ import { builderSocket } from "../../websockets"
|
||||||
import env from "../../environment"
|
import env from "../../environment"
|
||||||
|
|
||||||
async function getActionDefinitions() {
|
async function getActionDefinitions() {
|
||||||
return removeInvalidDefinitions(await actionDefs())
|
return removeDeprecated(await actionDefs())
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTriggerDefinitions() {
|
function getTriggerDefinitions() {
|
||||||
return removeInvalidDefinitions(triggers.TRIGGER_DEFINITIONS)
|
return removeDeprecated(triggers.TRIGGER_DEFINITIONS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
|
|
|
@ -14,7 +14,7 @@ import sdk from "../../../sdk"
|
||||||
import { Automation, FieldType, Table } from "@budibase/types"
|
import { Automation, FieldType, Table } from "@budibase/types"
|
||||||
import { mocks } from "@budibase/backend-core/tests"
|
import { mocks } from "@budibase/backend-core/tests"
|
||||||
import { FilterConditions } from "../../../automations/steps/filter"
|
import { FilterConditions } from "../../../automations/steps/filter"
|
||||||
import { removeInvalidDefinitions } from "../../../automations/utils"
|
import { removeDeprecated } from "../../../automations/utils"
|
||||||
|
|
||||||
const MAX_RETRIES = 4
|
const MAX_RETRIES = 4
|
||||||
let {
|
let {
|
||||||
|
@ -71,14 +71,14 @@ describe("/automations", () => {
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
let definitionsLength = Object.keys(
|
let definitionsLength = Object.keys(
|
||||||
removeInvalidDefinitions(BUILTIN_ACTION_DEFINITIONS)
|
removeDeprecated(BUILTIN_ACTION_DEFINITIONS)
|
||||||
).length
|
).length
|
||||||
|
|
||||||
expect(Object.keys(res.body.action).length).toBeGreaterThanOrEqual(
|
expect(Object.keys(res.body.action).length).toBeGreaterThanOrEqual(
|
||||||
definitionsLength
|
definitionsLength
|
||||||
)
|
)
|
||||||
expect(Object.keys(res.body.trigger).length).toEqual(
|
expect(Object.keys(res.body.trigger).length).toEqual(
|
||||||
Object.keys(removeInvalidDefinitions(TRIGGER_DEFINITIONS)).length
|
Object.keys(removeDeprecated(TRIGGER_DEFINITIONS)).length
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -117,16 +117,12 @@ export async function updateTestHistory(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeInvalidDefinitions(
|
export function removeDeprecated(
|
||||||
definitions: Record<string, AutomationStepSchema>
|
definitions: Record<string, AutomationStepSchema>
|
||||||
) {
|
) {
|
||||||
const disallowedStepIds: (
|
|
||||||
| AutomationTriggerStepId
|
|
||||||
| AutomationActionStepId
|
|
||||||
)[] = [AutomationTriggerStepId.ROW_ACTION]
|
|
||||||
const base = cloneDeep(definitions)
|
const base = cloneDeep(definitions)
|
||||||
for (let key of Object.keys(base)) {
|
for (let key of Object.keys(base)) {
|
||||||
if (base[key].deprecated || disallowedStepIds.includes(base[key].stepId)) {
|
if (base[key].deprecated) {
|
||||||
delete base[key]
|
delete base[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue