Files
windmill/frontend/src/lib/components/FlowViewer.svelte
T
Faton Ramadani b3eabffb76 fix(frontend): fix large JSON viewer (#4273)
* fix(frontend): fix large JSON viewer

* fix(frontend): fix large JSON viewer

* fix(frontend): improve UX

* fix(frontend): improve show more button

* fix(frontend): add fading effect

* fix(frontend): remove show more when we reach the end

* fix(frontend): Add show more button to the raw tab

* fix(frontend): Add show more button to the raw tab
2024-08-21 16:23:53 +02:00

90 lines
2.4 KiB
Svelte

<script lang="ts">
import type { FlowValue } from '$lib/gen'
import { Tab, Tabs, TabContent } from './common'
import SchemaViewer from './SchemaViewer.svelte'
import FieldHeader from './FieldHeader.svelte'
import FlowGraphViewer from './FlowGraphViewer.svelte'
import HighlightTheme from './HighlightTheme.svelte'
import FlowViewerInner from './FlowViewerInner.svelte'
export let flow: {
summary: string
description?: string
value: FlowValue
schema?: any
}
export let initialOpen: number | undefined = undefined
export let noSide = false
export let noGraph: boolean = false
export let tab: 'ui' | 'raw' | 'schema' = noGraph ? 'schema' : 'ui'
export let noSummary = false
export let noGraphDownload = false
let open: { [id: number]: boolean } = {}
if (initialOpen) {
open[initialOpen] = true
}
function toAny(x: unknown): any {
return x as any
}
</script>
<HighlightTheme />
<Tabs bind:selected={tab}>
{#if !noGraph}
<Tab value="ui">Graph</Tab>
{/if}
<Tab value="raw">Raw</Tab>
<Tab value="schema">Input Schema</Tab>
<svelte:fragment slot="content">
<TabContent value="ui">
<div class="flow-root w-full pb-4">
{#if !noSummary}
<h2 class="my-4">{flow.summary}</h2>
<div>{flow.description ?? ''}</div>
{/if}
<p class="font-black text-lg w-full my-4">
<span>Flow Input</span>
</p>
{#if flow.schema && flow.schema.properties && Object.keys(flow.schema.properties).length > 0 && flow.schema}
<ul class="my-2">
{#each Object.entries(flow.schema.properties) as [inp, v]}
<li class="list-disc flex flex-row">
<FieldHeader
label={inp}
required={flow.schema.required?.includes(inp)}
type={toAny(v)?.type}
contentEncoding={toAny(v)?.contentEncoding}
format={toAny(v)?.format}
/><span class="ml-4 mt-2 text-xs"
>{toAny(v)?.default != undefined
? 'default: ' + JSON.stringify(toAny(v)?.default)
: ''}</span
>
</li>
{/each}
</ul>
{:else}
<div class="text-secondary text-xs italic mb-4">No inputs</div>
{/if}
<FlowGraphViewer download={!noGraphDownload} {noSide} {flow} overflowAuto />
</div>
</TabContent>
<TabContent value="raw">
<FlowViewerInner {flow} />
</TabContent>
<TabContent value="schema">
<div class="my-4" />
<SchemaViewer schema={flow.schema} />
</TabContent>
</svelte:fragment>
</Tabs>