UI improvements

This commit is contained in:
Ruben Fiszel
2022-11-01 23:48:04 +01:00
parent 7dafa6e955
commit c0e85e8476
4 changed files with 32 additions and 18 deletions
+21 -14
View File
@@ -1,33 +1,34 @@
<script lang="ts">
import { truncate } from '$lib/utils'
import Modal from './Modal.svelte'
import Tooltip from './Tooltip.svelte'
import json from 'svelte-highlight/languages/json'
import { Highlight } from 'svelte-highlight'
import { ResourceService, type Resource } from '$lib/gen'
import { ResourceService } from '$lib/gen'
import { workspaceStore } from '$lib/stores'
import Drawer from './common/drawer/Drawer.svelte'
import { DrawerContent } from './common'
export let value: any
let resourceViewer: Modal
let resource: Resource
let jsonViewer: Drawer
let jsonViewerContent: any | undefined
function isString(value: any) {
return typeof value === 'string' || value instanceof String
}
async function getResource(path: string) {
resource = await ResourceService.getResource({ workspace: $workspaceStore!, path })
jsonViewerContent = (await ResourceService.getResource({ workspace: $workspaceStore!, path }))
.value
}
let asJson: string = JSON.stringify(value, null, 4)
$: asJson = JSON.stringify(value, null, 4)
</script>
<Modal bind:this={resourceViewer}>
<div slot="title">{resource.path}</div>
<div slot="content">
<Highlight language={json} code={JSON.stringify(resource.value, null, 4)} />
</div>
</Modal>
<Drawer bind:this={jsonViewer} size="400px">
<DrawerContent title="See JSON" on:close={jsonViewer.toggleDrawer}>
<Highlight language={json} code={JSON.stringify(jsonViewerContent, null, 4)} />
</DrawerContent>
</Drawer>
{#if value == '<function call>'}
{'<function call>'}<Tooltip
@@ -39,10 +40,16 @@
class="text-xs text-blue-500"
on:click={async () => {
await getResource(value.substring('$res:'.length))
resourceViewer.openModal()
jsonViewer.openModal()
}}>{value}</button
>{:else if asJson.length > 40}
{truncate(asJson, 40)}<Tooltip>{asJson}</Tooltip>
{truncate(asJson, 40)}<a
href="#json"
on:click|preventDefault={() => {
jsonViewerContent = value
jsonViewer.toggleDrawer()
}}>(+)</a
>
{:else}
{asJson}
{/if}
@@ -43,7 +43,9 @@
<div class="overlay" on:click={handleClickAway} />
<div class="panel {placement}" class:size>
<slot />
{#if open}
<slot />
{/if}
</div>
</aside>
@@ -71,8 +71,13 @@
$flowStateStore[module.id] = state
}}
on:pick={async ({ detail }) => {
const { path, summary } = detail
const { path, summary, kind } = detail
const [module, state] = await pickScript(path, summary, flowModule.id)
if (kind == Script.kind.APPROVAL) {
module.suspend = { required_events: 1, timeout: 1800 }
}
flowModule = module
$flowStateStore[module.id] = state
}}
@@ -341,7 +341,7 @@
{@const url = webhooks[key][type]}
<li class="flex justify-between items-center mt-2">
<a
href={'//' + url}
href={$page.url.protocol + '//' + url}
class="whitespace-nowrap text-ellipsis overflow-hidden mr-1"
>
{url}
@@ -351,7 +351,7 @@
{type}
</Badge>
<Button
on:click={() => copyToClipboard(url)}
on:click={() => copyToClipboard($page.url.protocol + '//' + url)}
color="blue"
size="xs"
startIcon={{ icon: faClipboard }}