more typing
This commit is contained in:
parent
317ef26f1a
commit
28f02cc41d
|
@ -1507,7 +1507,12 @@ export const updateReferencesInObject = ({
|
||||||
|
|
||||||
// Migrate references
|
// Migrate references
|
||||||
// Switch all bindings to reference their ids
|
// Switch all bindings to reference their ids
|
||||||
export const migrateReferencesInObject = ({ obj, label = "steps", steps }) => {
|
export const migrateReferencesInObject = ({
|
||||||
|
obj,
|
||||||
|
label = "steps",
|
||||||
|
steps,
|
||||||
|
originalIndex,
|
||||||
|
}) => {
|
||||||
const stepIndexRegex = new RegExp(`{{\\s*${label}\\.(\\d+)\\.`, "g")
|
const stepIndexRegex = new RegExp(`{{\\s*${label}\\.(\\d+)\\.`, "g")
|
||||||
const updateActionStep = (str, index, replaceWith) =>
|
const updateActionStep = (str, index, replaceWith) =>
|
||||||
str.replace(`{{ ${label}.${index}.`, `{{ ${label}.${replaceWith}.`)
|
str.replace(`{{ ${label}.${index}.`, `{{ ${label}.${replaceWith}.`)
|
||||||
|
@ -1528,6 +1533,7 @@ export const migrateReferencesInObject = ({ obj, label = "steps", steps }) => {
|
||||||
migrateReferencesInObject({
|
migrateReferencesInObject({
|
||||||
obj: obj[key],
|
obj: obj[key],
|
||||||
steps,
|
steps,
|
||||||
|
originalIndex,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { derived, get, Writable } from "svelte/store"
|
import { derived, get } from "svelte/store"
|
||||||
import { API } from "api"
|
import { API } from "api"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { generate } from "shortid"
|
import { generate } from "shortid"
|
||||||
|
@ -23,6 +23,9 @@ import {
|
||||||
Branch,
|
Branch,
|
||||||
AutomationTrigger,
|
AutomationTrigger,
|
||||||
AutomationStatus,
|
AutomationStatus,
|
||||||
|
UILogicalOperator,
|
||||||
|
EmptyFilterOption,
|
||||||
|
AutomationIOType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { ActionStepID } from "constants/backend/automations"
|
import { ActionStepID } from "constants/backend/automations"
|
||||||
import { FIELDS } from "constants/backend"
|
import { FIELDS } from "constants/backend"
|
||||||
|
@ -31,6 +34,7 @@ import { rowActions } from "./rowActions"
|
||||||
import { getNewStepName } from "helpers/automations/nameHelpers"
|
import { getNewStepName } from "helpers/automations/nameHelpers"
|
||||||
import { QueryUtils } from "@budibase/frontend-core"
|
import { QueryUtils } from "@budibase/frontend-core"
|
||||||
import { BudiStore, DerivedBudiStore } from "stores/BudiStore"
|
import { BudiStore, DerivedBudiStore } from "stores/BudiStore"
|
||||||
|
import { appStore } from "stores/builder"
|
||||||
|
|
||||||
interface BlockDefinitions {
|
interface BlockDefinitions {
|
||||||
TRIGGER: Record<string, any>
|
TRIGGER: Record<string, any>
|
||||||
|
@ -248,7 +252,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
*/
|
*/
|
||||||
registerBlock: (
|
registerBlock: (
|
||||||
blocks: Record<string, any>,
|
blocks: Record<string, any>,
|
||||||
block: AutomationStep,
|
block: AutomationStep | AutomationTrigger,
|
||||||
pathTo: Array<any>,
|
pathTo: Array<any>,
|
||||||
terminating: boolean
|
terminating: boolean
|
||||||
) => {
|
) => {
|
||||||
|
@ -281,7 +285,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
...automation.definition.steps,
|
...automation.definition.steps,
|
||||||
]
|
]
|
||||||
|
|
||||||
let result: AutomationStep[]
|
let result: (AutomationStep | AutomationTrigger)[] = []
|
||||||
pathWay.forEach(path => {
|
pathWay.forEach(path => {
|
||||||
const { stepIdx, branchIdx } = path
|
const { stepIdx, branchIdx } = path
|
||||||
let last = result ? result[result.length - 1] : []
|
let last = result ? result[result.length - 1] : []
|
||||||
|
@ -290,13 +294,14 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
result = steps.slice(0, stepIdx + 1)
|
result = steps.slice(0, stepIdx + 1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (last && "inputs" in last) {
|
||||||
if (Number.isInteger(branchIdx)) {
|
if (Number.isInteger(branchIdx)) {
|
||||||
const branchId = last.inputs.branches[branchIdx].id
|
const branchId = last.inputs.branches[branchIdx].id
|
||||||
const children = last.inputs.children[branchId]
|
const children = last.inputs.children[branchId]
|
||||||
const stepChildren = children.slice(0, stepIdx + 1)
|
const stepChildren = children.slice(0, stepIdx + 1)
|
||||||
// Preceeding steps.
|
// Preceeding steps.
|
||||||
result = result.concat(stepChildren)
|
result = result.concat(stepChildren)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
|
@ -316,7 +321,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
updateStep: (
|
updateStep: (
|
||||||
pathWay: Array<any>,
|
pathWay: Array<any>,
|
||||||
automation: Automation,
|
automation: Automation,
|
||||||
update: AutomationStep | AutomationStep[],
|
update: AutomationStep | AutomationTrigger,
|
||||||
insert = false
|
insert = false
|
||||||
) => {
|
) => {
|
||||||
let newAutomation = cloneDeep(automation)
|
let newAutomation = cloneDeep(automation)
|
||||||
|
@ -324,7 +329,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
const finalise = (
|
const finalise = (
|
||||||
dest: AutomationStep[],
|
dest: AutomationStep[],
|
||||||
idx: number,
|
idx: number,
|
||||||
update: AutomationStep | AutomationStep[]
|
update: AutomationStep | AutomationTrigger
|
||||||
) => {
|
) => {
|
||||||
dest.splice(
|
dest.splice(
|
||||||
idx,
|
idx,
|
||||||
|
@ -441,7 +446,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
* @param {Object} automation
|
* @param {Object} automation
|
||||||
*/
|
*/
|
||||||
traverse: (blockRefs: Record<string, any>, automation: Automation) => {
|
traverse: (blockRefs: Record<string, any>, automation: Automation) => {
|
||||||
let blocks: AutomationStep[] = []
|
let blocks: (AutomationStep | AutomationTrigger)[] = []
|
||||||
if (!automation || !blockRefs) {
|
if (!automation || !blockRefs) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -451,7 +456,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
blocks = blocks.concat(automation.definition.steps || [])
|
blocks = blocks.concat(automation.definition.steps || [])
|
||||||
|
|
||||||
const treeTraverse = (
|
const treeTraverse = (
|
||||||
block: AutomationStep,
|
block: AutomationStep | AutomationTrigger,
|
||||||
pathTo: Array<any> | null,
|
pathTo: Array<any> | null,
|
||||||
stepIdx: number,
|
stepIdx: number,
|
||||||
branchIdx: number | null,
|
branchIdx: number | null,
|
||||||
|
@ -571,7 +576,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
if (isLoopBlock && loopBlockCount == 0) {
|
if (isLoopBlock && loopBlockCount == 0) {
|
||||||
schema = {
|
schema = {
|
||||||
currentItem: {
|
currentItem: {
|
||||||
type: "string",
|
type: AutomationIOType.STRING,
|
||||||
description: "the item currently being executed",
|
description: "the item currently being executed",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -588,9 +593,10 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
pathBlock.event === AutomationEventType.ROW_UPDATE ||
|
pathBlock.event === AutomationEventType.ROW_UPDATE ||
|
||||||
pathBlock.event === AutomationEventType.ROW_SAVE
|
pathBlock.event === AutomationEventType.ROW_SAVE
|
||||||
) {
|
) {
|
||||||
let table = get(tables).list.find(
|
let table: any = get(tables).list.find(
|
||||||
(table: Table) => table._id === pathBlock.inputs.tableId
|
(table: Table) => table._id === pathBlock.inputs.tableId
|
||||||
)
|
)
|
||||||
|
|
||||||
for (const key in table?.schema) {
|
for (const key in table?.schema) {
|
||||||
schema[key] = {
|
schema[key] = {
|
||||||
type: table.schema[key].type,
|
type: table.schema[key].type,
|
||||||
|
@ -638,8 +644,8 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
isLoopBlock: boolean,
|
isLoopBlock: boolean,
|
||||||
bindingName: string | undefined,
|
bindingName: string | undefined,
|
||||||
automation: Automation,
|
automation: Automation,
|
||||||
currentBlock: AutomationStep | undefined,
|
currentBlock: AutomationStep | AutomationTrigger | undefined,
|
||||||
pathSteps: AutomationStep[]
|
pathSteps: (AutomationStep | AutomationTrigger)[]
|
||||||
) => {
|
) => {
|
||||||
let runtimeName: string | null
|
let runtimeName: string | null
|
||||||
|
|
||||||
|
@ -710,7 +716,9 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
bindingName?: string
|
bindingName?: string
|
||||||
) => {
|
) => {
|
||||||
const field = Object.values(FIELDS).find(
|
const field = Object.values(FIELDS).find(
|
||||||
field => field.type === value.type && field.subtype === value.subtype
|
field =>
|
||||||
|
field.type === value.type &&
|
||||||
|
("subtype" in field ? field.subtype === value.subtype : true)
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
readableBinding:
|
readableBinding:
|
||||||
|
@ -735,7 +743,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
data: Record<string, any>
|
data: Record<string, any>
|
||||||
) => {
|
) => {
|
||||||
// Create new modified block
|
// Create new modified block
|
||||||
let newBlock = {
|
let newBlock: any = {
|
||||||
...block,
|
...block,
|
||||||
inputs: {
|
inputs: {
|
||||||
...block.inputs,
|
...block.inputs,
|
||||||
|
@ -953,8 +961,8 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
*/
|
*/
|
||||||
generateDefaultConditions: () => {
|
generateDefaultConditions: () => {
|
||||||
const baseConditionUI = {
|
const baseConditionUI = {
|
||||||
logicalOperator: "all",
|
logicalOperator: UILogicalOperator.ALL,
|
||||||
onEmptyFilter: "none",
|
onEmptyFilter: EmptyFilterOption.RETURN_NONE,
|
||||||
groups: [],
|
groups: [],
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
@ -1079,12 +1087,14 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
block: AutomationStep
|
block: AutomationStep
|
||||||
) => {
|
) => {
|
||||||
const update = store.actions.shiftBranch(pathTo, block)
|
const update = store.actions.shiftBranch(pathTo, block)
|
||||||
const updatedAuto = store.actions.updateStep(
|
if (update) {
|
||||||
pathTo.slice(0, -1),
|
const updatedAuto = store.actions.updateStep(
|
||||||
automation,
|
pathTo.slice(0, -1),
|
||||||
update
|
automation,
|
||||||
)
|
update
|
||||||
await store.actions.save(updatedAuto)
|
)
|
||||||
|
await store.actions.save(updatedAuto)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1100,12 +1110,14 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
block: AutomationStep
|
block: AutomationStep
|
||||||
) => {
|
) => {
|
||||||
const update = store.actions.shiftBranch(pathTo, block, 1)
|
const update = store.actions.shiftBranch(pathTo, block, 1)
|
||||||
const updatedAuto = store.actions.updateStep(
|
if (update) {
|
||||||
pathTo.slice(0, -1),
|
const updatedAuto = store.actions.updateStep(
|
||||||
automation,
|
pathTo.slice(0, -1),
|
||||||
update
|
automation,
|
||||||
)
|
update
|
||||||
await store.actions.save(updatedAuto)
|
)
|
||||||
|
await store.actions.save(updatedAuto)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1226,7 +1238,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
deleteAutomationName: async (blockId: string) => {
|
deleteAutomationName: async (blockId: string) => {
|
||||||
const automation = get(selectedAutomation)?.data
|
const automation = get(selectedAutomation)?.data
|
||||||
let newAutomation = cloneDeep(automation)
|
let newAutomation = cloneDeep(automation)
|
||||||
if (!automation) {
|
if (!automation || !newAutomation) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (newAutomation?.definition.stepNames) {
|
if (newAutomation?.definition.stepNames) {
|
||||||
|
@ -1291,6 +1303,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
const automation: Automation = {
|
const automation: Automation = {
|
||||||
name,
|
name,
|
||||||
type: "automation",
|
type: "automation",
|
||||||
|
appId: get(appStore).appId,
|
||||||
definition: {
|
definition: {
|
||||||
steps: [],
|
steps: [],
|
||||||
trigger,
|
trigger,
|
||||||
|
@ -1381,7 +1394,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
save: async (automation: Automation) => {
|
save: async (automation: Automation) => {
|
||||||
const response = await API.updateAutomation(automation)
|
const response = await API.updateAutomation(automation)
|
||||||
await store.actions.fetch()
|
await store.actions.fetch()
|
||||||
store.actions.select(response._id)
|
store.actions.select(response.automation._id!)
|
||||||
return response.automation
|
return response.automation
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1438,7 +1451,7 @@ export class SelectedAutomationStore extends DerivedBudiStore<
|
||||||
DerivedAutomationState
|
DerivedAutomationState
|
||||||
> {
|
> {
|
||||||
constructor(automationStore: AutomationStore) {
|
constructor(automationStore: AutomationStore) {
|
||||||
const makeDerivedStore = (store: Writable<AutomationState>) => {
|
const makeDerivedStore = () => {
|
||||||
return derived(automationStore, $store => {
|
return derived(automationStore, $store => {
|
||||||
if (!$store.selectedAutomationId) {
|
if (!$store.selectedAutomationId) {
|
||||||
return {
|
return {
|
||||||
|
@ -1490,10 +1503,7 @@ export class SelectedAutomationStore extends DerivedBudiStore<
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the DerivedBudiStore with automation state and derived logic
|
|
||||||
super(initialAutomationState, makeDerivedStore)
|
super(initialAutomationState, makeDerivedStore)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exporting an instance of the `SelectedAutomationStore`
|
|
||||||
export const selectedAutomation = new SelectedAutomationStore(automationStore)
|
export const selectedAutomation = new SelectedAutomationStore(automationStore)
|
||||||
|
|
|
@ -22,6 +22,7 @@ export const createLicensingStore = () => {
|
||||||
backupsEnabled: false,
|
backupsEnabled: false,
|
||||||
brandingEnabled: false,
|
brandingEnabled: false,
|
||||||
scimEnabled: false,
|
scimEnabled: false,
|
||||||
|
environmentVariablesEnabled: false,
|
||||||
budibaseAIEnabled: false,
|
budibaseAIEnabled: false,
|
||||||
customAIConfigsEnabled: false,
|
customAIConfigsEnabled: false,
|
||||||
auditLogsEnabled: false,
|
auditLogsEnabled: false,
|
||||||
|
|
|
@ -148,6 +148,7 @@ export interface Automation extends Document {
|
||||||
|
|
||||||
interface BaseIOStructure {
|
interface BaseIOStructure {
|
||||||
type?: AutomationIOType
|
type?: AutomationIOType
|
||||||
|
subtype?: AutomationIOType
|
||||||
customType?: AutomationCustomIOType
|
customType?: AutomationCustomIOType
|
||||||
title?: string
|
title?: string
|
||||||
description?: string
|
description?: string
|
||||||
|
|
Loading…
Reference in New Issue