adds DnD support ot the actions drawer

This commit is contained in:
Keviin Åberg Kultalahti 2021-02-26 14:21:05 +01:00
parent 3e1744c759
commit 188f2b74d7
3 changed files with 848 additions and 30 deletions

View File

@ -79,6 +79,7 @@
"posthog-js": "1.4.5", "posthog-js": "1.4.5",
"remixicon": "2.5.0", "remixicon": "2.5.0",
"shortid": "2.2.15", "shortid": "2.2.15",
"svelte-dnd-action": "^0.8.9",
"svelte-loading-spinners": "^0.1.1", "svelte-loading-spinners": "^0.1.1",
"svelte-portal": "0.1.0", "svelte-portal": "0.1.0",
"uuid": "8.3.1", "uuid": "8.3.1",

View File

@ -1,10 +1,17 @@
<script> <script>
import {flip} from "svelte/animate";
import {dndzone} from "svelte-dnd-action";
import { Button, DropdownMenu, Spacer } from "@budibase/bbui" import { Button, DropdownMenu, Spacer } from "@budibase/bbui"
import actionTypes from "./actions" import actionTypes from "./actions"
const flipDurationMs = 150;
const EVENT_TYPE_KEY = "##eventHandlerType" const EVENT_TYPE_KEY = "##eventHandlerType"
export let actions export let actions
actions = actions.map((action, i) => {
return {...action, id: i}
})
let addActionButton let addActionButton
let addActionDropdown let addActionDropdown
@ -30,19 +37,26 @@
const newAction = { const newAction = {
parameters: {}, parameters: {},
[EVENT_TYPE_KEY]: actionType.name, [EVENT_TYPE_KEY]: actionType.name,
id: actions.length + 1
} }
if (!actions) { if (!actions) {
actions = [] actions = []
} }
actions.push(newAction) actions = [...actions, newAction]
selectedAction = newAction selectedAction = newAction
actions = actions
addActionDropdown.hide() addActionDropdown.hide()
} }
const selectAction = action => () => { const selectAction = action => () => {
selectedAction = action selectedAction = action
} }
function handleDndConsider(e) {
actions = e.detail.items;
}
function handleDndFinalize(e) {
actions = e.detail.items;
}
</script> </script>
<div class="actions-container"> <div class="actions-container">
@ -69,8 +83,9 @@
</div> </div>
{#if actions && actions.length > 0} {#if actions && actions.length > 0}
{#each actions as action, index} <div class="action-dnd-container" use:dndzone={{items: actions, flipDurationMs, dropTargetStyle: { outline: 'none'}}} on:consider={handleDndConsider} on:finalize={handleDndFinalize}>
<div class="action-container"> {#each actions as action, index (action.id)}
<div class="action-container" animate:flip={{duration: flipDurationMs}}>
<div <div
class="action-header" class="action-header"
class:selected={action === selectedAction} class:selected={action === selectedAction}
@ -84,6 +99,7 @@
on:click={() => deleteAction(index)} /> on:click={() => deleteAction(index)} />
</div> </div>
{/each} {/each}
</div>
{/if} {/if}
</div> </div>
<div class="action-config"> <div class="action-config">

File diff suppressed because it is too large Load Diff