Improve logic in add action modal for collect step
This commit is contained in:
parent
e3d867611b
commit
67272c28af
|
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -13,40 +13,40 @@
|
||||||
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(
|
let selectedAction
|
||||||
step => step.stepId === ActionStepID.COLLECT
|
let actionVal
|
||||||
)
|
let actions = Object.entries($automationStore.blockDefinitions.ACTION)
|
||||||
|
|
||||||
const disabled = {
|
$: collectBlockExists = checkForCollectStep($selectedAutomation)
|
||||||
|
|
||||||
|
const disabled = () => {
|
||||||
|
return {
|
||||||
SEND_EMAIL_SMTP: {
|
SEND_EMAIL_SMTP: {
|
||||||
disabled: !$admin.checklist.smtp.checked,
|
disabled: !$admin.checklist.smtp.checked,
|
||||||
message: "Please configure SMTP",
|
message: "Please configure SMTP",
|
||||||
},
|
},
|
||||||
COLLECT: {
|
COLLECT: {
|
||||||
disabled:
|
disabled: !lastStep || !syncWebhooksEnabled || collectBlockExists,
|
||||||
!collectBlockAllowedSteps.includes(
|
message: collectDisabledMessage(),
|
||||||
$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
|
const collectDisabledMessage = () => {
|
||||||
let actionVal
|
if (collectBlockExists) {
|
||||||
let actions = Object.entries($automationStore.blockDefinitions.ACTION)
|
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
|
||||||
|
@ -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>
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue