fix issue with being able to select any automation to trigger
This commit is contained in:
parent
e99a7672a7
commit
78ef231e03
|
@ -28,6 +28,7 @@
|
|||
import CodeEditorModal from "./CodeEditorModal.svelte"
|
||||
import QuerySelector from "./QuerySelector.svelte"
|
||||
import QueryParamSelector from "./QueryParamSelector.svelte"
|
||||
import AutomationSelector from "./AutomationSelector.svelte"
|
||||
import CronBuilder from "./CronBuilder.svelte"
|
||||
import Editor from "components/integration/QueryEditor.svelte"
|
||||
import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte"
|
||||
|
@ -286,7 +287,8 @@
|
|||
value.customType !== "code" &&
|
||||
value.customType !== "queryParams" &&
|
||||
value.customType !== "cron" &&
|
||||
value.customType !== "triggerSchema"
|
||||
value.customType !== "triggerSchema" &&
|
||||
value.customType !== "automationFields"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -421,6 +423,12 @@
|
|||
on:change={e => onChange(e, key)}
|
||||
value={inputData[key]}
|
||||
/>
|
||||
{:else if value.customType === "automationFields"}
|
||||
<AutomationSelector
|
||||
on:change={e => onChange(e, key)}
|
||||
value={inputData[key]}
|
||||
{bindings}
|
||||
/>
|
||||
{:else if value.customType === "queryParams"}
|
||||
<QueryParamSelector
|
||||
on:change={e => onChange(e, key)}
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
<script>
|
||||
import { Select, Label } from "@budibase/bbui"
|
||||
import { createEventDispatcher } from "svelte"
|
||||
import { automationStore, selectedAutomation } from "builderStore"
|
||||
import { TriggerStepID } from "constants/backend/automations"
|
||||
import DrawerBindableInput from "../../common/bindings/DrawerBindableInput.svelte"
|
||||
import AutomationBindingPanel from "../../common/bindings/ServerBindingPanel.svelte"
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
export let value
|
||||
export let bindings = []
|
||||
const onChangeAutomation = e => {
|
||||
value.automationId = e.detail
|
||||
dispatch("change", value)
|
||||
}
|
||||
|
||||
const onChange = (e, field) => {
|
||||
value[field] = e.detail
|
||||
dispatch("change", value)
|
||||
}
|
||||
$: if (value?.automationId == null) value = { automationId: "" }
|
||||
|
||||
$: automationFields = $automationStore.automations.find(
|
||||
automation => automation._id === value?.automationId
|
||||
)?.definition?.trigger?.inputs?.fields
|
||||
|
||||
$: filteredAutomations = $automationStore.automations.filter(
|
||||
automation =>
|
||||
automation.definition.trigger.stepId === TriggerStepID.APP &&
|
||||
automation._id !== $selectedAutomation._id
|
||||
)
|
||||
</script>
|
||||
|
||||
<div class="schema-field">
|
||||
<Label>Automation</Label>
|
||||
<div class="field-width">
|
||||
<Select
|
||||
on:change={onChangeAutomation}
|
||||
value={value.automationId}
|
||||
options={filteredAutomations}
|
||||
getOptionValue={automation => automation._id}
|
||||
getOptionLabel={automation => automation.name}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if Object.keys(automationFields)}
|
||||
{#each Object.keys(automationFields) as field}
|
||||
<div class="schema-field">
|
||||
<Label>{field}</Label>
|
||||
<div class="field-width">
|
||||
<DrawerBindableInput
|
||||
panel={AutomationBindingPanel}
|
||||
extraThin
|
||||
value={value[field]}
|
||||
on:change={e => onChange(e, field)}
|
||||
type="string"
|
||||
{bindings}
|
||||
fillWidth={true}
|
||||
updateOnChange={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.field-width {
|
||||
width: 320px;
|
||||
}
|
||||
|
||||
.schema-field {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex: 1;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.schema-field :global(label) {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
</style>
|
|
@ -7,6 +7,7 @@ import {
|
|||
AutomationFeature,
|
||||
AutomationResults,
|
||||
Automation,
|
||||
AutomationCustomIOType,
|
||||
} from "@budibase/types"
|
||||
import * as triggers from "../triggers"
|
||||
import { db as dbCore, context } from "@budibase/backend-core"
|
||||
|
@ -24,9 +25,17 @@ export const definition: AutomationStepSchema = {
|
|||
schema: {
|
||||
inputs: {
|
||||
properties: {
|
||||
automationId: {
|
||||
type: AutomationIOType.STRING,
|
||||
title: "Automation ID",
|
||||
automation: {
|
||||
type: AutomationIOType.OBJECT,
|
||||
properties: {
|
||||
automationId: {
|
||||
type: AutomationIOType.STRING,
|
||||
customType: AutomationCustomIOType.AUTOMATION,
|
||||
},
|
||||
},
|
||||
customType: AutomationCustomIOType.AUTOMATION_FIELDS,
|
||||
title: "automatioFields",
|
||||
required: ["automationId"],
|
||||
},
|
||||
timeout: {
|
||||
type: AutomationIOType.NUMBER,
|
||||
|
@ -52,18 +61,20 @@ export const definition: AutomationStepSchema = {
|
|||
}
|
||||
|
||||
export async function run({ inputs }: AutomationStepInput) {
|
||||
if (!inputs.automationId) {
|
||||
const { automationId, ...fieldParams } = inputs.automation
|
||||
|
||||
if (!inputs.automation.automationId) {
|
||||
return {
|
||||
success: false,
|
||||
}
|
||||
} else {
|
||||
const db = context.getAppDB()
|
||||
let automation = await db.get<Automation>(inputs.automationId)
|
||||
let automation = await db.get<Automation>(inputs.automation.automationId)
|
||||
|
||||
const response: AutomationResults = await triggers.externalTrigger(
|
||||
automation,
|
||||
{
|
||||
fields: {},
|
||||
fields: { ...fieldParams },
|
||||
timeout: inputs.timeout * 1000 || 120000,
|
||||
},
|
||||
{ getResponses: true }
|
||||
|
|
|
@ -28,6 +28,8 @@ export enum AutomationCustomIOType {
|
|||
TRIGGER_SCHEMA = "triggerSchema",
|
||||
CRON = "cron",
|
||||
WEBHOOK_URL = "webhookUrl",
|
||||
AUTOMATION = "automation",
|
||||
AUTOMATION_FIELDS = "automationFields",
|
||||
}
|
||||
|
||||
export enum AutomationTriggerStepId {
|
||||
|
|
Loading…
Reference in New Issue