diff --git a/packages/builder/src/builderStore/store/automation/index.js b/packages/builder/src/builderStore/store/automation/index.js index e1db07053e..b6a1941996 100644 --- a/packages/builder/src/builderStore/store/automation/index.js +++ b/packages/builder/src/builderStore/store/automation/index.js @@ -11,12 +11,18 @@ const automationActions = store => ({ ]) const jsonResponses = await Promise.all(responses.map(x => x.json())) store.update(state => { + let selected = state.selectedAutomation?.automation state.automations = jsonResponses[0] state.blockDefinitions = { TRIGGER: jsonResponses[1].trigger, ACTION: jsonResponses[1].action, LOGIC: jsonResponses[1].logic, } + // if previously selected find the new obj and select it + if (selected) { + selected = jsonResponses[0].filter(automation => automation._id === selected._id) + state.selectedAutomation = new Automation(selected[0]) + } return state }) }, diff --git a/packages/builder/src/components/automation/AutomationPanel/BlockList/AutomationBlock.svelte b/packages/builder/src/components/automation/AutomationPanel/BlockList/AutomationBlock.svelte index 45d3b17940..f2a52088ad 100644 --- a/packages/builder/src/components/automation/AutomationPanel/BlockList/AutomationBlock.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/BlockList/AutomationBlock.svelte @@ -1,11 +1,15 @@ + + +

To configure a webhook we need to create a schema for your webhook to validate against. + Use the URL shown below and send a POST request to it with a JSON body in the format that + your webhook should use!

+ +
Schema
+ + {schema} + +
+ + + Learn about webhooks + +
+
+ + diff --git a/packages/builder/src/components/automation/AutomationPanel/BlockList/WebhookDisplay.svelte b/packages/builder/src/components/automation/AutomationPanel/BlockList/WebhookDisplay.svelte new file mode 100644 index 0000000000..d8c0283aff --- /dev/null +++ b/packages/builder/src/components/automation/AutomationPanel/BlockList/WebhookDisplay.svelte @@ -0,0 +1,57 @@ + + +
+ + copyToClipboard()}> + + +
+ + \ No newline at end of file diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 5cb74d6bff..d308cf10ab 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -3,7 +3,7 @@ import RowSelector from "./ParamInputs/RowSelector.svelte" import { Button, Input, TextArea, Select, Label } from "@budibase/bbui" import { automationStore } from "builderStore" - import { notifier } from "builderStore/store/notifications" + import WebhookDisplay from "../AutomationPanel/BlockList/WebhookDisplay.svelte" import BindableInput from "../../userInterface/BindableInput.svelte" export let block @@ -43,20 +43,6 @@ } return bindings } - - function fullWebhookURL(uri) { - return `http://localhost:4001/${uri}` - } - - function copyToClipboard(input) { - const dummy = document.createElement("textarea") - document.body.appendChild(dummy) - dummy.value = input - dummy.select() - document.execCommand("copy") - document.body.removeChild(dummy) - notifier.success(`URL copied to clipboard`) - }
@@ -80,17 +66,7 @@ {:else if value.customType === 'row'} {:else if value.customType === 'webhookUrl'} -
- - copyToClipboard(fullWebhookURL(block.inputs[key]))}> - - -
+ {:else if value.type === 'string' || value.type === 'number'} diff --git a/packages/server/src/api/controllers/automation.js b/packages/server/src/api/controllers/automation.js index 1647d59413..2127c0a661 100644 --- a/packages/server/src/api/controllers/automation.js +++ b/packages/server/src/api/controllers/automation.js @@ -41,6 +41,8 @@ function cleanAutomationInputs(automation) { * written to DB (this does not write to DB as it would be wasteful to repeat). */ async function checkForWebhooks({ user, oldAuto, newAuto }) { + const oldTrigger = oldAuto ? oldAuto.definition.trigger : null + const newTrigger = newAuto ? newAuto.definition.trigger : null function isWebhookTrigger(auto) { return ( auto && @@ -52,21 +54,19 @@ async function checkForWebhooks({ user, oldAuto, newAuto }) { if ( isWebhookTrigger(oldAuto) && !isWebhookTrigger(newAuto) && - oldAuto.definition.trigger.webhook + oldTrigger.webhookId ) { + let db = new CouchDB(user.instanceId) + // need to get the webhook to get the rev + const webhook = await db.get(oldTrigger.webhookId) const ctx = { user, - params: { - id: oldAuto.definition.trigger.webhook.id, - rev: oldAuto.definition.trigger.webhook.rev, - }, + params: { id: webhook._id, rev: webhook._rev }, } - // reset the inputs to remove the URLs - if (newAuto && newAuto.definition.trigger) { - const trigger = newAuto.definition.trigger - delete trigger.webhook - delete trigger.inputs.schemaUrl - delete trigger.inputs.triggerUrl + // might be updating - reset the inputs to remove the URLs + if (newTrigger) { + delete newTrigger.webhookId + newTrigger.inputs = {} } await webhooks.destroy(ctx) } @@ -83,10 +83,9 @@ async function checkForWebhooks({ user, oldAuto, newAuto }) { }, } await webhooks.save(ctx) - const id = ctx.body.webhook._id, - rev = ctx.body.webhook._rev - newAuto.definition.trigger.webhook = { id, rev } - newAuto.definition.trigger.inputs = { + const id = ctx.body.webhook._id + newTrigger.webhookId = id + newTrigger.inputs = { schemaUrl: `api/webhooks/schema/${user.instanceId}/${id}`, triggerUrl: `api/webhooks/trigger/${user.instanceId}/${id}`, }