Files
windmill/frontend/src/lib/components/flows/map/InsertModuleButton.svelte
T
Faton RamadaniandRuben Fiszel 632bd18a2e use xyflow internally instead of svelvet for graph rendering (#4173)
* fix(frontend): wip

* fix(frontend): wip

* fix(frontend): fix while loops + theme

* fix(frontend): wip

* fix(frontend): wip

* fix(frontend): same view as before

* fix(frontend): wip

* fix(frontend): wip

* feat(frontend): flow status viewer

* fix(frontend): wip

* feat(frontend): migrate to xyflow

* feat(frontend): dataflow

* feat(frontend): clean up

* feat(frontend): clean up

* feat(frontend): clean up

* feat(frontend): fix min-height

* feat(frontend): clean up

* feat(frontend): add missing insert button for empty loops

* feat(frontend): Fix insert

* feat(frontend): Fix branch one

* feat(frontend): Support default branch for branch one

* feat(frontend): fix add and delete branches

* feat(frontend): Make the iterations menu work

* feat(frontend): Fix graph height in the flow status viewer

* feat(frontend): code improvement

* feat(frontend): add missing trigger

* feat(frontend): add support for triggers

* feat(frontend): fix move

* feat(frontend): fix No branch for branch one

* feat(frontend): fix light theme

* feat(frontend): fix build

* feat(frontend): remove dead code

* feat(frontend): fix move

* feat(frontend): fix vertical alignement

* feat(frontend): fix viewport

* feat(frontend): style fix

* feat(frontend): fix viewgraph

* feat(frontend): fix build

* feat(frontend): Fix node position

* feat(frontend): UI nits

* feat(frontend): UI nits

* feat(frontend): fix zoom level + fix insert button position

* feat(frontend): svelvet clean up

* feat(frontend): fix paste button position

* feat(frontend): clean up

* feat(frontend): migrate Decision Tree

* feat(frontend): clean up

* feat(frontend): add callback

* feat(frontend): migrate Decision Tree

* feat(frontend): fix build

* feat(frontend): fix branches

* feat(frontend): fix branches

* feat(frontend): fix insert

* feat(frontend): wip

* feat(frontend): done

* feat(frontend): done

* feat(frontend): fix reactivity

* feat(frontend): fix z-index issues

* feat(frontend): fix bg issue

* feat(frontend): fix border status

* add padding to flow height

* Update FlowGraphV2.svelte

---------

Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
2024-08-19 09:17:56 +02:00

170 lines
4.4 KiB
Svelte

<script lang="ts">
import { Menu } from '$lib/components/common'
import { createEventDispatcher, getContext } from 'svelte'
import { CheckCircle2, Code, Cross, GitBranch, Repeat, Square, Zap } from 'lucide-svelte'
import StepGen from '$lib/components/copilot/StepGen.svelte'
import type { FlowModule } from '$lib/gen'
import BarsStaggered from '$lib/components/icons/BarsStaggered.svelte'
import type { WhitelabelCustomUi } from '$lib/components/custom_ui'
import { twMerge } from 'tailwind-merge'
const dispatch = createEventDispatcher()
export let trigger = false
export let stop = false
export let open: boolean | undefined = undefined
export let index: number
export let funcDesc = ''
export let modules: FlowModule[]
export let disableAi = false
$: !open && (funcDesc = '')
let customUi: undefined | WhitelabelCustomUi = getContext('customUi')
</script>
<Menu
transitionDuration={0}
pointerDown
bind:show={open}
noMinW
placement="bottom-center"
let:close
>
<svelte:fragment slot="trigger">
<button
title="Add step"
id={`flow-editor-add-step-${index}`}
type="button"
class={twMerge(
'w-6 h-6 flex items-center justify-center',
'border border-gray-300 dark:border-gray-500',
'text-primary text-sm',
'bg-surface focus:outline-none hover:bg-surface-hover focus:ring-4 focus:ring-surface-selected rounded-full '
)}
>
<Cross size={14} />
</button>
</svelte:fragment>
<div id="flow-editor-insert-module">
<StepGen on:insert {index} bind:funcDesc bind:open {close} {modules} {disableAi} />
{#if funcDesc.length === 0}
<div class="font-mono divide-y text-xs w-full text-secondary">
<button
class="w-full text-left py-2 px-3 hover:bg-surface-hover whitespace-nowrap flex flex-row gap-2 items-center"
on:pointerdown={() => {
close()
dispatch('new', 'script')
}}
role="menuitem"
tabindex="-1"
>
<Code size={14} />
Action
</button>
{#if customUi?.triggers != false && trigger}
<button
class="w-full text-left py-2 px-3 hover:bg-surface-hover whitespace-nowrap flex flex-row gap-2 items-center"
on:pointerdown={() => {
close()
dispatch('new', 'trigger')
}}
role="menuitem"
tabindex="-1"
>
<Zap size={14} />
Trigger
</button>
{/if}
<button
class="w-full text-left py-2 px-3 hover:bg-surface-hover whitespace-nowrap flex flex-row gap-2 items-center"
on:pointerdown={() => {
close()
dispatch('new', 'approval')
}}
role="menuitem"
tabindex="-1"
>
<CheckCircle2 size={14} />
Approval/Prompt
</button>
<button
class="w-full text-left py-2 px-3 hover:bg-surface-hover whitespace-nowrap flex flex-row gap-2 items-center"
on:pointerdown={() => {
close()
dispatch('new', 'forloop')
}}
role="menuitem"
>
<Repeat size={14} />
For Loop
</button>
<button
class="w-full text-left py-2 px-3 hover:bg-surface-hover whitespace-nowrap flex flex-row gap-2 items-center"
on:pointerdown={() => {
close()
dispatch('new', 'whileloop')
}}
role="menuitem"
>
<Repeat size={14} />
While Loop
</button>
<button
class="w-full text-left py-2 px-3 hover:bg-surface-hover whitespace-nowrap flex flex-row gap-2 items-center"
on:pointerdown={() => {
close()
dispatch('new', 'branchone')
}}
role="menuitem"
>
<GitBranch size={14} />
Branch to one
</button>
<button
class="w-full text-left py-2 px-3 hover:bg-surface-hover whitespace-nowrap flex flex-row gap-2 items-center"
on:pointerdown={() => {
close()
dispatch('new', 'branchall')
}}
role="menuitem"
>
<GitBranch size={14} />
Branch to all
</button>
{#if customUi?.flowNode != false}
<button
class="w-full text-left py-2 px-3 hover:bg-surface-hover rounded-none whitespace-nowrap flex flex-row gap-2 items-center"
on:pointerdown={() => {
close()
dispatch('new', 'flow')
}}
role="menuitem"
>
<BarsStaggered size={14} />
Flow
</button>
{/if}
{#if stop}
<button
class="w-full text-left py-2 px-3 hover:bg-surface-hover inline-flex gap-2.5"
on:pointerdown={() => {
close()
dispatch('new', 'end')
}}
role="menuitem"
>
<Square size={14} />
End Flow
</button>
{/if}
</div>
{/if}
</div>
</Menu>