simplify parsing of internal / external actions

This commit is contained in:
Peter Clement 2021-09-15 12:58:20 +01:00
parent 97c546107e
commit f75f0fc1d4
3 changed files with 10 additions and 25 deletions

View File

@ -1,39 +1,26 @@
<script> <script>
import { ModalContent, Layout, Detail, Body, Icon } from "@budibase/bbui" import { ModalContent, Layout, Detail, Body, Icon } from "@budibase/bbui"
import { automationStore } from "builderStore" import { automationStore } from "builderStore"
import DiscordLogo from "assets/discord.svg"
import ZapierLogo from "assets/zapier.png"
import IntegromatLogo from "assets/integromat.png"
import SlackLogo from "assets/slack.svg"
import n8nlogo from "assets/n8n.png"
import { database } from "stores/backend" import { database } from "stores/backend"
import { externalActions } from "./ExternalActions"
$: instanceId = $database._id $: instanceId = $database._id
let selectedAction let selectedAction
let actionVal let actionVal
let actions = Object.entries($automationStore.blockDefinitions.ACTION)
export let blockComplete export let blockComplete
let externalActionsPredicate = [ const external = actions.reduce((acc, elm) => {
{ name: "zapier", logo: ZapierLogo },
{ name: "discord", logo: DiscordLogo },
{ name: "slack", logo: SlackLogo },
{ name: "integromat", logo: IntegromatLogo },
{ name: "n8n", logo: n8nlogo },
]
let actions = Object.entries($automationStore.blockDefinitions.ACTION)
const externalActions = actions.reduce((acc, elm) => {
const [k, v] = elm const [k, v] = elm
if (externalActionsPredicate.some(pred => pred.name === k)) { if (!v.internal) {
acc[k] = v acc[k] = v
} }
return acc return acc
}, {}) }, {})
const internalActions = actions.reduce((acc, elm) => { const internal = actions.reduce((acc, elm) => {
const [k, v] = elm const [k, v] = elm
if (!externalActionsPredicate.some(pred => pred.name === k)) { if (v.internal) {
acc[k] = v acc[k] = v
} }
return acc return acc
@ -73,7 +60,7 @@
<Body size="S">Apps</Body> <Body size="S">Apps</Body>
<div class="item-list"> <div class="item-list">
{#each Object.entries(externalActions) as [idx, action]} {#each Object.entries(external) as [idx, action]}
<div <div
class="item" class="item"
class:selected={selectedAction === action.name} class:selected={selectedAction === action.name}
@ -83,7 +70,7 @@
<img <img
width="20" width="20"
height="20" height="20"
src={externalActionsPredicate.find(val => val.name === idx).logo} src={externalActions[action.stepId].icon}
alt="zapier" alt="zapier"
/> />
<span class="icon-spacing"> <span class="icon-spacing">
@ -98,7 +85,7 @@
<Detail size="S">Actions</Detail> <Detail size="S">Actions</Detail>
<div class="item-list"> <div class="item-list">
{#each Object.entries(internalActions) as [idx, action]} {#each Object.entries(internal) as [idx, action]}
<div <div
class="item" class="item"
class:selected={selectedAction === action.name} class:selected={selectedAction === action.name}

View File

@ -2,12 +2,10 @@ import DiscordLogo from "assets/discord.svg"
import ZapierLogo from "assets/zapier.png" import ZapierLogo from "assets/zapier.png"
import IntegromatLogo from "assets/integromat.png" import IntegromatLogo from "assets/integromat.png"
import SlackLogo from "assets/slack.svg" import SlackLogo from "assets/slack.svg"
import n8nlogo from "assets/n8n.png"
export const externalActions = { export const externalActions = {
zapier: { name: "zapier", icon: ZapierLogo }, zapier: { name: "zapier", icon: ZapierLogo },
discord: { name: "discord", icon: DiscordLogo }, discord: { name: "discord", icon: DiscordLogo },
slack: { name: "slack", icon: SlackLogo }, slack: { name: "slack", icon: SlackLogo },
integromat: { name: "integromat", icon: IntegromatLogo }, integromat: { name: "integromat", icon: IntegromatLogo },
n8n: { name: "n8n", icon: n8nlogo },
} }

View File

@ -9,13 +9,13 @@
let trigger = cloneDeep( let trigger = cloneDeep(
$automationStore.selectedAutomation.automation.definition.trigger $automationStore.selectedAutomation.automation.definition.trigger
) )
let schemaProperties = Object.entries(trigger.schema.outputs.properties || {})
if (!$automationStore.selectedAutomation.automation.testData) { if (!$automationStore.selectedAutomation.automation.testData) {
$automationStore.selectedAutomation.automation.testData = {} $automationStore.selectedAutomation.automation.testData = {}
} }
// get the outputs so we can define the fields // get the outputs so we can define the fields
let schemaProperties = Object.entries(trigger.schema.outputs.properties || {})
// check to see if there is existing test data in the store // check to see if there is existing test data in the store
$: testData = $automationStore.selectedAutomation.automation.testData $: testData = $automationStore.selectedAutomation.automation.testData