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 CodeEditorModal from "./CodeEditorModal.svelte"
|
||||||
import QuerySelector from "./QuerySelector.svelte"
|
import QuerySelector from "./QuerySelector.svelte"
|
||||||
import QueryParamSelector from "./QueryParamSelector.svelte"
|
import QueryParamSelector from "./QueryParamSelector.svelte"
|
||||||
|
import AutomationSelector from "./AutomationSelector.svelte"
|
||||||
import CronBuilder from "./CronBuilder.svelte"
|
import CronBuilder from "./CronBuilder.svelte"
|
||||||
import Editor from "components/integration/QueryEditor.svelte"
|
import Editor from "components/integration/QueryEditor.svelte"
|
||||||
import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte"
|
import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte"
|
||||||
|
@ -286,7 +287,8 @@
|
||||||
value.customType !== "code" &&
|
value.customType !== "code" &&
|
||||||
value.customType !== "queryParams" &&
|
value.customType !== "queryParams" &&
|
||||||
value.customType !== "cron" &&
|
value.customType !== "cron" &&
|
||||||
value.customType !== "triggerSchema"
|
value.customType !== "triggerSchema" &&
|
||||||
|
value.customType !== "automationFields"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,6 +423,12 @@
|
||||||
on:change={e => onChange(e, key)}
|
on:change={e => onChange(e, key)}
|
||||||
value={inputData[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"}
|
{:else if value.customType === "queryParams"}
|
||||||
<QueryParamSelector
|
<QueryParamSelector
|
||||||
on:change={e => onChange(e, key)}
|
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,
|
AutomationFeature,
|
||||||
AutomationResults,
|
AutomationResults,
|
||||||
Automation,
|
Automation,
|
||||||
|
AutomationCustomIOType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import * as triggers from "../triggers"
|
import * as triggers from "../triggers"
|
||||||
import { db as dbCore, context } from "@budibase/backend-core"
|
import { db as dbCore, context } from "@budibase/backend-core"
|
||||||
|
@ -24,9 +25,17 @@ export const definition: AutomationStepSchema = {
|
||||||
schema: {
|
schema: {
|
||||||
inputs: {
|
inputs: {
|
||||||
properties: {
|
properties: {
|
||||||
automationId: {
|
automation: {
|
||||||
type: AutomationIOType.STRING,
|
type: AutomationIOType.OBJECT,
|
||||||
title: "Automation ID",
|
properties: {
|
||||||
|
automationId: {
|
||||||
|
type: AutomationIOType.STRING,
|
||||||
|
customType: AutomationCustomIOType.AUTOMATION,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
customType: AutomationCustomIOType.AUTOMATION_FIELDS,
|
||||||
|
title: "automatioFields",
|
||||||
|
required: ["automationId"],
|
||||||
},
|
},
|
||||||
timeout: {
|
timeout: {
|
||||||
type: AutomationIOType.NUMBER,
|
type: AutomationIOType.NUMBER,
|
||||||
|
@ -52,18 +61,20 @@ export const definition: AutomationStepSchema = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function run({ inputs }: AutomationStepInput) {
|
export async function run({ inputs }: AutomationStepInput) {
|
||||||
if (!inputs.automationId) {
|
const { automationId, ...fieldParams } = inputs.automation
|
||||||
|
|
||||||
|
if (!inputs.automation.automationId) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const db = context.getAppDB()
|
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(
|
const response: AutomationResults = await triggers.externalTrigger(
|
||||||
automation,
|
automation,
|
||||||
{
|
{
|
||||||
fields: {},
|
fields: { ...fieldParams },
|
||||||
timeout: inputs.timeout * 1000 || 120000,
|
timeout: inputs.timeout * 1000 || 120000,
|
||||||
},
|
},
|
||||||
{ getResponses: true }
|
{ getResponses: true }
|
||||||
|
|
|
@ -28,6 +28,8 @@ export enum AutomationCustomIOType {
|
||||||
TRIGGER_SCHEMA = "triggerSchema",
|
TRIGGER_SCHEMA = "triggerSchema",
|
||||||
CRON = "cron",
|
CRON = "cron",
|
||||||
WEBHOOK_URL = "webhookUrl",
|
WEBHOOK_URL = "webhookUrl",
|
||||||
|
AUTOMATION = "automation",
|
||||||
|
AUTOMATION_FIELDS = "automationFields",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AutomationTriggerStepId {
|
export enum AutomationTriggerStepId {
|
||||||
|
|
Loading…
Reference in New Issue