Improve logic in add action modal for collect step

This commit is contained in:
Peter Clement 2023-05-16 16:06:37 +01:00
parent e3d867611b
commit 67272c28af
3 changed files with 65 additions and 39 deletions

View File

@ -1,3 +1,4 @@
import { ActionStepID } from "constants/backend/automations"
import { TableNames } from "../constants" import { TableNames } from "../constants"
import { import {
AUTO_COLUMN_DISPLAY_NAMES, AUTO_COLUMN_DISPLAY_NAMES,
@ -53,3 +54,9 @@ export function buildAutoColumn(tableName, name, subtype) {
} }
return base return base
} }
export function checkForCollectStep(automation) {
return automation.definition.steps.some(
step => step.stepId === ActionStepID.COLLECT
)
}

View File

@ -13,41 +13,41 @@
import { admin, licensing } from "stores/portal" import { admin, licensing } from "stores/portal"
import { externalActions } from "./ExternalActions" import { externalActions } from "./ExternalActions"
import { TriggerStepID, ActionStepID } from "constants/backend/automations" import { TriggerStepID, ActionStepID } from "constants/backend/automations"
import { checkForCollectStep } from "builderStore/utils"
export let blockIdx export let blockIdx
export let lastStep export let lastStep
let syncWebhooksEnabled = false let syncWebhooksEnabled = $licensing.syncWebhooksEnabled
let collectBlockAllowedSteps = [TriggerStepID.APP, TriggerStepID.WEBHOOK] let collectBlockAllowedSteps = [TriggerStepID.APP, TriggerStepID.WEBHOOK]
let collectBlockExists = $selectedAutomation.definition.steps.some(
step => step.stepId === ActionStepID.COLLECT
)
const disabled = {
SEND_EMAIL_SMTP: {
disabled: !$admin.checklist.smtp.checked,
message: "Please configure SMTP",
},
COLLECT: {
disabled:
!collectBlockAllowedSteps.includes(
$selectedAutomation.definition.trigger.stepId
) ||
!lastStep ||
!syncWebhooksEnabled ||
collectBlockExists,
message: !collectBlockAllowedSteps.includes(
$selectedAutomation.definition.trigger.stepId
)
? "Only available for App Action or Webhook triggers"
: "Only available as the last step",
},
}
let selectedAction let selectedAction
let actionVal let actionVal
let actions = Object.entries($automationStore.blockDefinitions.ACTION) let actions = Object.entries($automationStore.blockDefinitions.ACTION)
$: collectBlockExists = checkForCollectStep($selectedAutomation)
const disabled = () => {
return {
SEND_EMAIL_SMTP: {
disabled: !$admin.checklist.smtp.checked,
message: "Please configure SMTP",
},
COLLECT: {
disabled: !lastStep || !syncWebhooksEnabled || collectBlockExists,
message: collectDisabledMessage(),
},
}
}
const collectDisabledMessage = () => {
if (collectBlockExists) {
return "Only one Collect step allowed"
}
if (!lastStep) {
return "Only available as the last step"
}
}
const external = actions.reduce((acc, elm) => { const external = actions.reduce((acc, elm) => {
const [k, v] = elm const [k, v] = elm
if (!v.internal && !v.custom) { if (!v.internal && !v.custom) {
@ -62,6 +62,15 @@
acc[k] = v acc[k] = v
} }
delete acc.LOOP delete acc.LOOP
// Filter out Collect block if not App Action or Webhook
if (
!collectBlockAllowedSteps.includes(
$selectedAutomation.definition.trigger.stepId
)
) {
delete acc.COLLECT
}
return acc return acc
}, {}) }, {})
@ -130,7 +139,7 @@
<Detail size="S">Actions</Detail> <Detail size="S">Actions</Detail>
<div class="item-list"> <div class="item-list">
{#each Object.entries(internal) as [idx, action]} {#each Object.entries(internal) as [idx, action]}
{@const isDisabled = disabled[idx] && disabled[idx].disabled} {@const isDisabled = disabled()[idx] && disabled()[idx].disabled}
<div <div
class="item" class="item"
class:disabled={isDisabled} class:disabled={isDisabled}
@ -147,7 +156,7 @@
</Tags> </Tags>
</div> </div>
{:else if isDisabled} {:else if isDisabled}
<Icon name="Help" tooltip={disabled[idx].message} /> <Icon name="Help" tooltip={disabled()[idx].message} />
{/if} {/if}
</div> </div>
</div> </div>

View File

@ -31,6 +31,9 @@
let showLooping = false let showLooping = false
let role let role
$: collectBlockExists = $selectedAutomation.definition.steps.some(
step => step.stepId === ActionStepID.COLLECT
)
$: automationId = $selectedAutomation?._id $: automationId = $selectedAutomation?._id
$: showBindingPicker = $: showBindingPicker =
block.stepId === ActionStepID.CREATE_ROW || block.stepId === ActionStepID.CREATE_ROW ||
@ -224,21 +227,28 @@
</Layout> </Layout>
</div> </div>
{/if} {/if}
<Modal bind:this={actionModal} width="30%">
<ActionModal {lastStep} {blockIdx} />
</Modal>
<Modal bind:this={webhookModal} width="30%">
<CreateWebhookModal />
</Modal>
</div> </div>
<div class="separator" /> {#if !collectBlockExists || !lastStep}
<Icon on:click={() => actionModal.show()} hoverable name="AddCircle" size="S" />
{#if isTrigger ? totalBlocks > 1 : blockIdx !== totalBlocks - 2}
<div class="separator" /> <div class="separator" />
<Icon
on:click={() => actionModal.show()}
hoverable
name="AddCircle"
size="S"
/>
{#if isTrigger ? totalBlocks > 1 : blockIdx !== totalBlocks - 2}
<div class="separator" />
{/if}
{/if} {/if}
<Modal bind:this={actionModal} width="30%">
<ActionModal {lastStep} {blockIdx} />
</Modal>
<Modal bind:this={webhookModal} width="30%">
<CreateWebhookModal />
</Modal>
<style> <style>
.delete-padding { .delete-padding {
padding-left: 30px; padding-left: 30px;