2021-01-09 07:22:03 +13:00
|
|
|
<script>
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Body,
|
|
|
|
DropdownMenu,
|
|
|
|
ModalContent,
|
2021-01-27 11:42:31 +13:00
|
|
|
Spacer,
|
2021-01-09 07:22:03 +13:00
|
|
|
} from "@budibase/bbui"
|
|
|
|
import { AddIcon, ArrowDownIcon } from "components/common/Icons/"
|
|
|
|
import actionTypes from "./actions"
|
2021-01-16 02:11:51 +13:00
|
|
|
import { createEventDispatcher } from "svelte"
|
|
|
|
import { automationStore } from "builderStore"
|
2021-01-09 07:22:03 +13:00
|
|
|
|
2021-01-16 02:11:51 +13:00
|
|
|
const EVENT_TYPE_KEY = "##eventHandlerType"
|
2021-01-09 07:22:03 +13:00
|
|
|
|
2021-01-22 03:52:59 +13:00
|
|
|
export let actions
|
2021-01-09 07:22:03 +13:00
|
|
|
|
|
|
|
let addActionButton
|
|
|
|
let addActionDropdown
|
|
|
|
let selectedAction
|
|
|
|
|
|
|
|
$: selectedActionComponent =
|
|
|
|
selectedAction &&
|
2021-01-16 02:11:51 +13:00
|
|
|
actionTypes.find(t => t.name === selectedAction[EVENT_TYPE_KEY]).component
|
2021-01-09 07:22:03 +13:00
|
|
|
|
|
|
|
const deleteAction = index => {
|
|
|
|
actions.splice(index, 1)
|
|
|
|
actions = actions
|
|
|
|
}
|
|
|
|
|
|
|
|
const addAction = actionType => () => {
|
|
|
|
const newAction = {
|
|
|
|
parameters: {},
|
2021-01-16 02:11:51 +13:00
|
|
|
[EVENT_TYPE_KEY]: actionType.name,
|
2021-01-09 07:22:03 +13:00
|
|
|
}
|
|
|
|
actions.push(newAction)
|
|
|
|
selectedAction = newAction
|
|
|
|
actions = actions
|
|
|
|
addActionDropdown.hide()
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectAction = action => () => {
|
|
|
|
selectedAction = action
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="actions-container">
|
|
|
|
<div class="actions-list">
|
|
|
|
<div>
|
|
|
|
<div bind:this={addActionButton}>
|
2021-01-27 11:42:31 +13:00
|
|
|
<Spacer small />
|
|
|
|
<Button wide secondary on:click={addActionDropdown.show}>
|
2021-01-09 07:22:03 +13:00
|
|
|
Add Action
|
2021-01-27 11:42:31 +13:00
|
|
|
</Button>
|
|
|
|
<Spacer medium />
|
2021-01-09 07:22:03 +13:00
|
|
|
</div>
|
|
|
|
<DropdownMenu
|
|
|
|
bind:this={addActionDropdown}
|
|
|
|
anchor={addActionButton}
|
|
|
|
align="right">
|
|
|
|
<div class="available-actions-container">
|
|
|
|
{#each actionTypes as actionType}
|
|
|
|
<div class="available-action" on:click={addAction(actionType)}>
|
|
|
|
<span>{actionType.name}</span>
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
</DropdownMenu>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{#if actions && actions.length > 0}
|
|
|
|
{#each actions as action, index}
|
|
|
|
<div class="action-container">
|
|
|
|
<div class="action-header" on:click={selectAction(action)}>
|
|
|
|
<span class:selected={action === selectedAction}>
|
2021-01-27 11:42:31 +13:00
|
|
|
{index + 1}. {action[EVENT_TYPE_KEY]}
|
2021-01-09 07:22:03 +13:00
|
|
|
</span>
|
|
|
|
</div>
|
2021-01-13 05:49:11 +13:00
|
|
|
<i
|
|
|
|
class="ri-close-fill"
|
2021-01-27 11:42:31 +13:00
|
|
|
style="margin-left: auto;"
|
2021-01-13 05:49:11 +13:00
|
|
|
on:click={() => deleteAction(index)} />
|
2021-01-09 07:22:03 +13:00
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
<div class="action-config">
|
|
|
|
{#if selectedAction}
|
|
|
|
<div class="selected-action-container">
|
|
|
|
<svelte:component
|
|
|
|
this={selectedActionComponent}
|
|
|
|
parameters={selectedAction.parameters} />
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.action-header {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
2021-01-12 09:17:56 +13:00
|
|
|
margin-top: var(--spacing-m);
|
2021-01-09 07:22:03 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
.action-header > span {
|
|
|
|
margin-bottom: var(--spacing-m);
|
2021-01-27 11:42:31 +13:00
|
|
|
font-size: var(--font-size-xs);
|
2021-01-09 07:22:03 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
.action-header > span:hover,
|
|
|
|
.selected {
|
|
|
|
cursor: pointer;
|
|
|
|
font-weight: 500;
|
|
|
|
}
|
|
|
|
|
|
|
|
.actions-list {
|
2021-01-27 22:44:58 +13:00
|
|
|
border-right: var(--border-light);
|
2021-01-12 09:17:56 +13:00
|
|
|
padding: var(--spacing-s);
|
2021-01-09 07:22:03 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
.available-action {
|
|
|
|
padding: var(--spacing-s);
|
2021-01-27 11:42:31 +13:00
|
|
|
font-size: var(--font-size-xs);
|
2021-01-09 07:22:03 +13:00
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.available-action:hover {
|
|
|
|
background: var(--grey-2);
|
|
|
|
}
|
|
|
|
|
|
|
|
.actions-container {
|
2021-01-12 09:17:56 +13:00
|
|
|
height: 40vh;
|
2021-01-09 07:22:03 +13:00
|
|
|
display: grid;
|
|
|
|
grid-gap: var(--spacing-m);
|
2021-01-27 11:42:31 +13:00
|
|
|
grid-template-columns: 260px 1fr;
|
2021-01-09 07:22:03 +13:00
|
|
|
grid-auto-flow: column;
|
|
|
|
min-height: 0;
|
|
|
|
padding-top: 0;
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.action-container {
|
2021-01-27 11:42:31 +13:00
|
|
|
border-top: var(--border-light);
|
2021-01-13 05:49:11 +13:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2021-01-09 07:22:03 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
.selected-action-container {
|
2021-01-27 11:42:31 +13:00
|
|
|
padding: var(--spacing-xl);
|
2021-01-09 07:22:03 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
a {
|
|
|
|
flex: 1;
|
|
|
|
color: var(--grey-5);
|
|
|
|
font-size: var(--font-size-s);
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
a:hover {
|
|
|
|
color: var(--blue);
|
|
|
|
}
|
2021-01-27 22:44:58 +13:00
|
|
|
|
|
|
|
i:hover {
|
|
|
|
color: var(--red);
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2021-01-09 07:22:03 +13:00
|
|
|
</style>
|