Files
windmill/frontend/src/lib/components/FlowViewerInner.svelte
Faton Ramadani 258445e523 feat(frontend): unify all triggers UX and simplify flow settings (#4259)
* feat(frontend): added list of triggers in the flow graph

* feat(frontend): added list of triggers in the flow graph

* feat(frontend): clean up

* feat(frontend): improve UX

* feat(frontend): triggers

* feat(frontend): triggers

* feat(frontend): done

* feat(frontend): fix trigger when position when a preprocessor is presetn

* Glm/rework flow settings v2 (#4497)

* fat(frontend): simplify flow settings menu

* improve scroll

* changing mute toggle

* Add advanced settings badge

* Add nord theme colors

* Add bage for advanced options

* fix minor issue

* fix minor issue

* Add triggers menu to flow settings

* Add quick trigger access

* remove triggers in flow settings

* fix minor issue

* Move triggers settings to flow right panel

* polishing

* fix unset store

* remove save up to for triggers

* fix padding

* reset default tag color

* remove custom select component

* revert path change

* revert section modif

* Revert unused feature

---------

Co-authored-by: Guilhem <guilhem@mbp-de-windmill.home>

* Connect top bar cron to schedules settings

* Turn copilot into node

* fix copilot placement

* remove useless import

* fix center copilot

* fix binding

* remove copilot on top of preprocessor

* render copilot node on condition

* quickfix

* remove copilot node

* fix minor issues

* fix route count update

* fix schedule sync

* harmonize colors

* fix alignment and add edges

* recenter node summary

* fix schedules sync

* Add id title

* all

* all

* all

* iteration

* all

* all

* done

* fix

* more fixes

---------

Co-authored-by: Guilhem <guilhemlemouel@gmail.com>
Co-authored-by: Guilhem <guilhem@mbp-de-windmill.home>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
Co-authored-by: Ruben Fiszel <ruben@rubenfiszel.com>
2024-10-16 17:58:15 +02:00

128 lines
2.8 KiB
Svelte

<script lang="ts">
import Highlight from 'svelte-highlight'
import json from 'svelte-highlight/languages/json'
import type { FlowValue } from '$lib/gen'
import { Tab, Tabs, Button } from './common'
import { copyToClipboard } from '../utils'
import { ArrowDown, Clipboard } from 'lucide-svelte'
import YAML from 'yaml'
import { yaml } from 'svelte-highlight/languages'
import HighlightTheme from './HighlightTheme.svelte'
import { filteredContentForExport } from './flows/utils'
export let flow: {
summary: string
description?: string
value: FlowValue
schema?: any
}
$: flowFiltered = filteredContentForExport(flow)
let rawType: 'json' | 'yaml' = 'yaml'
function trimStringToLines(inputString: string, maxLines: number = 100): string {
const lines = inputString?.split('\n') ?? []
const linesToKeep = lines.slice(0, maxLines)
return linesToKeep.join('\n')
}
let code: string = ''
function computeCode() {
const str =
rawType === 'json' ? JSON.stringify(flowFiltered, null, 4) : YAML.stringify(flowFiltered)
const numberOfLines = str.split('\n').length
if (numberOfLines > maxLines) {
shouldDisplayLoadMore = true
}
code = str
}
let shouldDisplayLoadMore = false
$: flowFiltered && rawType && computeCode()
let maxLines = 100
</script>
<HighlightTheme />
<div>
<Tabs
bind:selected={rawType}
on:selected={() => {
maxLines = 100
}}
>
<Tab value="yaml">YAML</Tab>
<Tab value="json">JSON</Tab>
<svelte:fragment slot="content">
<div class="relative pt-2">
<Button
on:click={() =>
copyToClipboard(
rawType === 'yaml'
? YAML.stringify(flowFiltered)
: JSON.stringify(flowFiltered, null, 4)
)}
color="light"
variant="border"
size="xs"
startIcon={{ icon: Clipboard }}
btnClasses="absolute top-2 right-2 w-min z-20"
iconOnly
/>
<div class={shouldDisplayLoadMore ? 'code-container' : ''}>
<Highlight
class="overflow-auto px-1"
language={rawType === 'yaml' ? yaml : json}
code={trimStringToLines(code, maxLines)}
/>
</div>
{#if shouldDisplayLoadMore}
<Button
on:click={() => {
maxLines += 500
// If the code is less than the max lines, we don't need to show the button
if (maxLines >= code?.split('\n').length) {
shouldDisplayLoadMore = false
}
}}
color="light"
size="xs"
btnClasses="mb-2 mx-2"
startIcon={{ icon: ArrowDown }}
>
Show more
</Button>
{/if}
</div>
</svelte:fragment>
</Tabs>
</div>
<style>
.code-container {
position: relative;
overflow: hidden;
}
.code-container::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 100px;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgb(var(--color-surface)));
pointer-events: none;
}
</style>