Files
windmill/frontend/src/lib/components/SchemaViewer.svelte
T
Faton Ramadani 6bb80b803d feat(frontend): Menu + Tab components (#517)
* feat(frontend): Migrate Tabs

* feat(frontend): Generalise Menu

* feat(frontend): Menu component done

* feat(frontend): Fix placements

* feat(frontend): Clean unused imports

* feat(frontend): Fix linting
2022-08-31 18:41:13 +02:00

73 lines
2.2 KiB
Svelte

<script lang="ts">
import type { Schema } from '$lib/common'
import { emptySchema } from '$lib/utils'
import Highlight from 'svelte-highlight'
import json from 'svelte-highlight/languages/json'
import TableCustom from './TableCustom.svelte'
import Tab from './common/tabs/Tab.svelte'
import TabContent from './common/tabs/TabContent.svelte'
import Tabs from './common/tabs/Tabs.svelte'
export let schema: Schema | undefined = emptySchema()
</script>
<div class="w-full">
<Tabs selected="arguments">
<Tab value="arguments">Arguments</Tab>
<Tab value="advanced">Advanced</Tab>
<svelte:fragment slot="content">
<TabContent value="arguments">
{#if schema && schema.properties && Object.keys(schema.properties).length > 0 && schema.required}
<div class="flex flex-row">
<TableCustom>
<tr slot="header-row" class="underline">
<th>name</th>
<th>type</th>
<th>description</th>
<th>default</th>
<th>format</th>
<th>required</th>
</tr>
<tbody slot="body">
{#each Object.entries(schema.properties) as [name, property] (name)}
<tr>
<td>{name}</td>
<td
>{#if !property.type} any {:else} {property.type} {/if}</td
>
<td>{property.description}</td>
<td
>{property.default == '<function call>'
? '<function call>'
: property.default
? JSON.stringify(property.default)
: ''}</td
>
<td
>{property.format ?? ''}
{property.contentEncoding
? `(encoding: ${property.contentEncoding})`
: ''}</td
>
<td
>{#if schema.required.includes(name)}
<span class="text-red-600 font-bold text-lg">*</span>
{/if}</td
>
</tr>
{/each}
</tbody>
</TableCustom>
</div>
{:else}
<div class="text-gray-700 text-xs italic">This script has no arguments</div>
{/if}
</TabContent>
<TabContent value="advanced">
<Highlight language={json} code={JSON.stringify(schema, null, 4)} />
</TabContent>
</svelte:fragment>
</Tabs>
</div>