Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automation fixes #15081

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}
} else {
// Leave the core data as it is
return testData
return cloneDeep(testData)
}
}

Expand All @@ -63,7 +63,10 @@
return true
}

$: testData = testData || parseTestData($selectedAutomation.data.testData)
$: currentTestData = $selectedAutomation.data.testData

// Can be updated locally to avoid race condition when testing
$: testData = parseTestData(currentTestData)

$: {
// clone the trigger so we're not mutating the reference
Expand All @@ -85,7 +88,7 @@
required => testData?.[required] || required !== "row"
)

function parseTestJSON(e) {
async function parseTestJSON(e) {
let jsonUpdate

try {
Expand All @@ -105,7 +108,9 @@
}
}

automationStore.actions.addTestDataToAutomation(jsonUpdate)
const updatedAuto =
automationStore.actions.addTestDataToAutomation(jsonUpdate)
await automationStore.actions.save(updatedAuto)
}

const testAutomation = async () => {
Expand Down Expand Up @@ -150,10 +155,14 @@
{#if selectedValues}
<div class="tab-content-padding">
<AutomationBlockSetup
bind:testData
{schemaProperties}
isTestModal
{testData}
block={trigger}
on:update={e => {
const { testData: updatedTestData } = e.detail
testData = updatedTestData
}}
/>
</div>
{/if}
Expand All @@ -162,7 +171,7 @@
<TextArea
value={JSON.stringify($selectedAutomation.data.testData, null, 2)}
error={failedParse}
on:change={e => parseTestJSON(e)}
on:change={async e => await parseTestJSON(e)}
/>
</div>
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import { QueryUtils, Utils, search, memo } from "@budibase/frontend-core"
import { getSchemaForDatasourcePlus } from "dataBinding"
import { TriggerStepID, ActionStepID } from "constants/backend/automations"
import { onMount } from "svelte"
import { onMount, createEventDispatcher } from "svelte"
import { writable } from "svelte/store"
import { cloneDeep } from "lodash/fp"
import {
Expand All @@ -67,6 +67,8 @@
export let isTestModal = false
export let bindings = []

const dispatch = createEventDispatcher()

// Stop unnecessary rendering
const memoBlock = memo(block)

Expand Down Expand Up @@ -503,15 +505,7 @@
row: { "Active": true, "Order Id" : 14, ... }
})
*/
const onChange = async update => {
if (isTestModal) {
testData = update
}

updateAutomation(update)
}

const updateAutomation = Utils.sequential(async update => {
const onChange = Utils.sequential(async update => {
const request = cloneDeep(update)
// Process app trigger updates
if (isTrigger && !isTestModal) {
Expand Down Expand Up @@ -540,7 +534,9 @@
}
try {
if (isTestModal) {
let newTestData = { schema }
// Be sure to merge in the testData prop data, as it can contain custom
// default data
let newTestData = { schema, ...testData }

// Special case for webhook, as it requires a body, but the schema already brings back the body's contents
if (stepId === TriggerStepID.WEBHOOK) {
Expand All @@ -557,7 +553,13 @@
...request,
}

await automationStore.actions.addTestDataToAutomation(newTestData)
const updatedAuto =
automationStore.actions.addTestDataToAutomation(newTestData)

// Ensure the test request has the latest info.
dispatch("update", updatedAuto)

await automationStore.actions.save(updatedAuto)
} else {
const data = { schema, ...request }
await automationStore.actions.updateBlockInputs(block, data)
Expand Down
4 changes: 2 additions & 2 deletions packages/builder/src/stores/builder/automations.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,13 +880,13 @@ const automationActions = store => ({
appId,
})
},
addTestDataToAutomation: async data => {
addTestDataToAutomation: data => {
let newAutomation = cloneDeep(get(selectedAutomation).data)
newAutomation.testData = {
...newAutomation.testData,
...data,
}
await store.actions.save(newAutomation)
return newAutomation
},
constructBlock(type, stepId, blockDefinition) {
let newName
Expand Down
Loading