Skip to content

Automation store builder updates #16065

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

Closed
wants to merge 6 commits into from
Closed
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 @@ -37,10 +37,7 @@
$: lastStep = blockRef?.terminating
$: pathSteps =
block.id && $selectedAutomation?.data
? automationStore.actions.getPathSteps(
blockRef.pathTo,
$selectedAutomation.data
)
? automationStore.getPathSteps(blockRef.pathTo, $selectedAutomation.data)
: []

$: collectBlockExists = pathSteps?.some(
Expand Down Expand Up @@ -123,20 +120,29 @@
selectedAction = action.name

try {
const newBlock = automationStore.actions.constructBlock(
const newBlock = automationStore.constructBlock(
BlockDefinitionTypes.ACTION,
action.stepId,
action
)
await automationStore.actions.addBlockToAutomation(
const updated = automationStore.addBlockToAutomation(
$selectedAutomation.data!,
newBlock,
blockRef ? blockRef.pathTo : block.pathTo
)

// Determine presence of the block before focusing
const createdBlock = $selectedAutomation.blockRefs[newBlock.id]
const createdBlockLoc = (createdBlock?.pathTo || []).at(-1)
await automationStore.actions.selectNode(createdBlockLoc?.id)
if (updated) {
try {
await automationStore.save(updated)
// Determine presence of the block before focusing
const createdBlock = $selectedAutomation.blockRefs[newBlock.id]
const createdBlockLoc = (createdBlock?.pathTo || []).at(-1)
automationStore.selectNode(createdBlockLoc?.id)
} catch (e) {
notifications.error("Error adding automation block")
console.error("Automation adding block ", e)
}
}

modal.hide()
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
if (branchSteps.length) {
confirmDeleteModal.show()
} else {
await automationStore.actions.deleteBranch(
await automationStore.deleteBranch(
branchBlockRef.pathTo,
$selectedAutomation.data
)
Expand All @@ -86,7 +86,7 @@
visible: true,
disabled: branchIdx == 0,
callback: async () => {
automationStore.actions.branchLeft(
automationStore.branchLeft(
branchBlockRef.pathTo,
$selectedAutomation.data,
step
Expand All @@ -100,7 +100,7 @@
visible: true,
disabled: isLast,
callback: async () => {
automationStore.actions.branchRight(
automationStore.branchRight(
branchBlockRef.pathTo,
$selectedAutomation.data,
step
Expand All @@ -125,7 +125,7 @@
title={"Are you sure you want to delete?"}
confirmText="Delete"
onConfirm={async () => {
await automationStore.actions.deleteBranch(
await automationStore.deleteBranch(
branchBlockRef.pathTo,
$selectedAutomation.data
)
Expand Down Expand Up @@ -198,12 +198,12 @@
)
branchUpdate.name = e.detail

const updatedAuto = automationStore.actions.updateStep(
const updatedAuto = automationStore.updateStep(
pathTo,
$selectedAutomation.data,
stepUpdate
)
await automationStore.actions.save(updatedAuto)
await automationStore.save(updatedAuto)
}}
/>
<div class="actions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@

const deleteAutomation = async () => {
try {
await automationStore.actions.delete(automation)
await automationStore.delete(automation)
} catch (error) {
notifications.error("Error deleting automation")
}
}

onMount(async () => {
try {
await automationStore.actions.initAppSelf()
await automationStore.initAppSelf()
await environment.loadVariables()
const response = await automationStore.actions.getLogs({
const response = await automationStore.getLogs({
automationId: automation._id,
status: "error",
})
Expand Down Expand Up @@ -134,7 +134,7 @@
<div class="toggle-active setting-spacing">
<Toggle
text={automation.disabled ? "Paused" : "Activated"}
on:change={automationStore.actions.toggleDisabled(
on:change={automationStore.toggleDisabled(
automation._id,
automation.disabled
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { automationStore, selectedAutomation, tables } from "@/stores/builder"
import { Modal } from "@budibase/bbui"
import { Modal, notifications } from "@budibase/bbui"
import { sdk } from "@budibase/shared-core"
import CreateWebhookModal from "@/components/automation/Shared/CreateWebhookModal.svelte"
import { ActionStepID } from "@/constants/backend/automations"
Expand Down Expand Up @@ -79,7 +79,7 @@

const loadSteps = blockRef => {
return blockRef
? automationStore.actions.getPathSteps(blockRef.pathTo, automation)
? automationStore.getPathSteps(blockRef.pathTo, automation)
: []
}

Expand Down Expand Up @@ -167,17 +167,16 @@
{/if}
<div
class="block-core"
on:click={async () => {
await automationStore.actions.selectNode(block.id)
on:click={() => {
automationStore.selectNode(block.id)
}}
>
<div class="blockSection block-info">
<BlockHeader
disabled
{automation}
{block}
on:update={e =>
automationStore.actions.updateBlockTitle(block, e.detail)}
on:update={e => automationStore.updateBlockTitle(block, e.detail)}
/>
</div>

Expand All @@ -201,11 +200,17 @@
{:else}
<FlowItemActions
{block}
on:branch={() => {
automationStore.actions.branchAutomation(
on:branch={async () => {
const updated = automationStore.branchAutomation(
$selectedAutomation.blockRefs[block.id].pathTo,
automation
)
try {
await automationStore.save(updated)
} catch (e) {
notifications.error("Error adding branch to automation")
console.error("Error adding automation branch", e)
}
}}
/>
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
$: isTriggerBlock = block ? isTrigger(block) : false

$: testResults = $automationStore.testResults as TestAutomationResponse
$: blockResult = automationStore.actions.processBlockResults(
testResults,
block
)
$: blockResult = automationStore.processBlockResults(testResults, block)
$: flowStatus = getFlowStatus(blockResult)

const getFlowStatus = (
Expand Down Expand Up @@ -111,7 +108,7 @@
if (branch || !block) {
return
}
await automationStore.actions.selectNode(
automationStore.selectNode(
block?.id,
flowStatus.type == FlowStatusType.SUCCESS
? DataMode.OUTPUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@
$: branches = step.inputs?.branches

// All bindings available to this point
$: availableBindings = automationStore.actions.getPathBindings(
step.id,
automation
)
$: availableBindings = automationStore.getPathBindings(step.id, automation)

// Fetch the env bindings
$: environmentBindings =
automationStore.actions.buildEnvironmentBindings($memoEnvVariables)
automationStore.buildEnvironmentBindings($memoEnvVariables)

$: userBindings = automationStore.actions.buildUserBindings()
$: settingBindings = automationStore.actions.buildSettingBindings()
$: userBindings = automationStore.buildUserBindings()
$: settingBindings = automationStore.buildSettingBindings()

// Combine all bindings for the step
$: bindings = [
Expand Down Expand Up @@ -75,8 +72,17 @@
<div class="split-branch-btn">
<ActionButton
icon="AddCircle"
on:click={() => {
automationStore.actions.branchAutomation(pathToCurrentNode, automation)
on:click={async () => {
const branched = automationStore.branchAutomation(
pathToCurrentNode,
automation
)
try {
await automationStore.save(branched)
} catch (e) {
notifications.error("Error adding branch to automation")
console.error("Error adding automation branch", e)
}
}}
>
Add branch
Expand Down Expand Up @@ -119,20 +125,20 @@
if (!Object.keys(branch.condition).length) {
branchArray[i] = {
...branch,
...automationStore.actions.generateDefaultConditions(),
...automationStore.generateDefaultConditions(),
}
}
}
)

const updated = automationStore.actions.updateStep(
const updated = automationStore.updateStep(
blockRef?.pathTo,
automation,
branchStepUpdate
)

try {
await automationStore.actions.save(updated)
await automationStore.save(updated)
} catch (e) {
notifications.error("Error saving branch update")
console.error("Error saving automation branch", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,18 @@
}
}

const updatedAuto =
automationStore.actions.addTestDataToAutomation(jsonUpdate)
await automationStore.actions.save(updatedAuto)
const updatedAuto = automationStore.addTestDataToAutomation(
$selectedAutomation.data,
jsonUpdate
)
await automationStore.save(updatedAuto)
}

const testAutomation = async () => {
// Ensure testData reactiveness is processed
await tick()
try {
await automationStore.actions.test($selectedAutomation.data, testData)
await automationStore.test($selectedAutomation.data, testData)
} catch (error) {
notifications.error(error)
}
Expand Down Expand Up @@ -162,6 +164,7 @@
isTestModal
{testData}
block={trigger}
automation={$selectedAutomation.data}
on:update={e => {
const { testData: updatedTestData } = e.detail
testData = parseTestData(updatedTestData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$: selectedNodeId = $automationStore.selectedNodeId
$: blockRefs = $selectedAutomation.blockRefs
$: blockRef = selectedNodeId ? blockRefs[selectedNodeId] : undefined
$: block = automationStore.actions.getBlockByRef($memoAutomation, blockRef)
$: block = automationStore.getBlockByRef($memoAutomation, blockRef)

$: memoBlock.set(block)

Expand All @@ -52,22 +52,21 @@

$: isAppAction = block?.stepId === AutomationTriggerStepId.APP
$: isAppAction && fetchPermissions($memoAutomation?._id)
$: isAppAction &&
automationStore.actions.setPermissions(role, $memoAutomation)
$: isAppAction && automationStore.setPermissions(role, $memoAutomation)

const fetchPermissions = async (automationId?: string) => {
if (!automationId) {
return
}
role = await automationStore.actions.getPermissions(automationId)
role = await automationStore.getPermissions(automationId)
}

const loadPathSteps = (
blockRef: BlockRef | undefined,
automation: Automation | undefined
) => {
return blockRef && automation
? automationStore.actions.getPathSteps(blockRef.pathTo, automation)
? automationStore.getPathSteps(blockRef.pathTo, automation)
: []
}
</script>
Expand All @@ -83,15 +82,15 @@
block={$memoBlock}
on:update={e => {
if ($memoBlock && !isTrigger($memoBlock)) {
automationStore.actions.updateBlockTitle($memoBlock, e.detail)
automationStore.updateBlockTitle($memoBlock, e.detail)
}
}}
/>
<Icon
name="Close"
hoverable
on:click={() => {
automationStore.actions.selectNode()
automationStore.selectNode()
}}
/>
</div>
Expand All @@ -104,9 +103,9 @@
icon="RotateCW"
on:click={async () => {
if (loopBlock) {
await automationStore.actions.removeLooping(blockRef)
await automationStore.removeLooping(blockRef)
} else {
await automationStore.actions.addLooping(blockRef)
await automationStore.addLooping(blockRef)
}
}}
>
Expand All @@ -121,7 +120,7 @@
if (!blockRef) {
return
}
await automationStore.actions.deleteAutomationBlock(blockRef.pathTo)
await automationStore.deleteAutomationBlock(blockRef.pathTo)
}}
>
Delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
const terminatingStep = filteredResults.at(-1)
const terminatingBlockRef = automationBlockRefs[terminatingStep.id]
if (terminatingBlockRef) {
const pathSteps = automationStore.actions.getPathSteps(
const pathSteps = automationStore.getPathSteps(
terminatingBlockRef.pathTo,
automation
)
Expand Down
Loading
Loading