Skip to content

Commit

Permalink
feat(frontend): improve approval form edition + add a delete button t… (
Browse files Browse the repository at this point in the history
#3946)

* feat(frontend): improve approval form edition + add a delete button to the EditableSchema

* feat(frontend): only show a few lines of code for Hub/workflow scripts by default

* feat(frontend): fix spacing

* feat(frontend): improve

* feat(frontend): fix toggle

* feat(frontend): add missing space
  • Loading branch information
fatonramadani committed Jun 21, 2024
1 parent e5db278 commit 25a460b
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@
{#if !noEditor}
<div class="border-t">
{#key forceReload}
<FlowModuleScript path={flowModule.value.path} hash={flowModule.value.hash} />
<FlowModuleScript
showAllCode={false}
path={flowModule.value.path}
hash={flowModule.value.hash}
/>
{/key}
</div>
{/if}
Expand Down
33 changes: 30 additions & 3 deletions frontend/src/lib/components/flows/content/FlowModuleScript.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
export let path: string
export let hash: string | undefined = undefined
export let showDate = false
export let showAllCode: boolean = true
let code: string
let language: SupportedLanguage
let lock: string | undefined = undefined
let date: string | undefined = undefined
let notFound = false
async function loadCode(path: string, hash: string | undefined) {
try {
notFound = false
Expand All @@ -33,6 +34,10 @@
}
$: path && loadCode(path, hash)
function toggleShowAll() {
showAllCode = !showAllCode
}
</script>

<div class="flex flex-col flex-1 h-full overflow-auto p-2">
Expand All @@ -41,12 +46,34 @@
{/if}
{#if notFound}
<div class="text-red-400">script not found at {path} in workspace {$workspaceStore}</div>
{:else}
{:else if showAllCode}
<HighlightCode {language} {code} />
{:else}
<div class="code-container h-full">
<HighlightCode {language} code={code?.split('\n').slice(0, 10).join('\n')} />
</div>
<button on:click={toggleShowAll}>Show all</button>
{/if}

{#if lock}
<h3 class="mb-2 mt-6">Lock</h3>
<pre class="bg-surface-secondary text-xs p-2 overflow-auto w-full">{lock}</pre>
{/if}
</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), #2e3440);
pointer-events: none;
}
</style>
85 changes: 56 additions & 29 deletions frontend/src/lib/components/flows/content/FlowModuleSuspend.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Tooltip from '$lib/components/Tooltip.svelte'
import InputTransformForm from '$lib/components/InputTransformForm.svelte'
import type SimpleEditor from '$lib/components/SimpleEditor.svelte'
import { getContext } from 'svelte'
import { getContext, tick } from 'svelte'
import { Alert, Tab, Tabs } from '$lib/components/common'
import { GroupService, type FlowModule } from '$lib/gen'
Expand All @@ -16,6 +16,7 @@
import Label from '$lib/components/Label.svelte'
import SuspendDrawer from './SuspendDrawer.svelte'
import EditableSchemaDrawer from '$lib/components/schema/EditableSchemaDrawer.svelte'
import AddProperty from '$lib/components/schema/AddProperty.svelte'
const { selectedId, flowStateStore } = getContext<FlowEditorContext>('FlowEditorContext')
const result = $flowStateStore[$selectedId]?.previewResult ?? {}
Expand Down Expand Up @@ -47,6 +48,8 @@
loadGroups()
}
}
let jsonView: boolean = false
</script>

<Section label="Suspend/Approval/Prompt" class="w-full">
Expand Down Expand Up @@ -190,33 +193,68 @@
{/if}
</div>
{:else}
<div class="grid grid-cols-4 mt-4 gap-2">
<div class="col-span-2 flex flex-col gap-2">
{#if flowModule.suspend}
{#if emptyString($enterpriseLicense)}
<Alert type="warning" title="Adding a form to the approval page is an EE feature" />
{/if}
<div class="grid grid-cols-4 mt-4 gap-8">
<div class="col-span-2">
{#if flowModule?.suspend?.resume_form}
<EditableSchemaDrawer
bind:schema={flowModule.suspend.resume_form.schema}
on:change={(e) => {
const schema = e.detail

<div class="flex flex-col gap-2">
// If the schema is empty, remove the form
if (Object.keys(schema?.properties ?? {}).length === 0) {
tick().then(() => {
if (!flowModule.suspend) return
flowModule.suspend.resume_form = undefined
})
}
}}
{jsonView}
/>
{:else if emptyString($enterpriseLicense)}
<Alert type="warning" title="Adding a form to the approval page is an EE feature" />
{:else}
<div class="flex flex-col items-end mb-2 w-full">
<Toggle
checked={Boolean(flowModule.suspend.resume_form)}
checked={false}
label="JSON View"
size="xs"
options={{
right: 'Add a form to the approval page'
right: 'JSON Editor',
rightTooltip:
'Arguments can be edited either using the wizard, or by editing their JSON Schema.'
}}
disabled={emptyString($enterpriseLicense)}
on:change={(e) => {
lightMode
on:change={() => {
if (flowModule.suspend) {
if (e.detail) {
flowModule.suspend.resume_form = {
schema: emptySchema()
}
} else {
flowModule.suspend.resume_form = undefined
flowModule.suspend.resume_form = {
schema: emptySchema()
}
}
jsonView = true
}}
/>
</div>
<AddProperty
on:change={(e) => {
jsonView = false
if (flowModule.suspend) {
flowModule.suspend.resume_form = {
schema: e.detail
}
}
}}
schema={{}}
/>
{/if}
</div>
<div class="col-span-2 flex flex-col gap-4">
{#if flowModule.suspend}
{#if emptyString($enterpriseLicense)}
<Alert type="warning" title="Adding a form to the approval page is an EE feature" />
{/if}

<div class="flex flex-col gap-2">
<div class="flex">
<SuspendDrawer text="Default args & Dynamic enums help" />
</div>
Expand All @@ -233,17 +271,6 @@
/>
{/if}
</div>
<div class="col-span-2">
{#if flowModule?.suspend?.resume_form}
<EditableSchemaDrawer bind:schema={flowModule.suspend.resume_form.schema} />
{:else}
<div
class="bg-gray-50 border-gray-200 border dark:bg-gray-900/40 dark:border-gray-700/40 rounded-md p-2 text-xs"
>
No form
</div>
{/if}
</div>
</div>
{/if}
</Section>
1 change: 1 addition & 0 deletions frontend/src/lib/components/schema/AddProperty.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
throw Error('Argument not found!')
}
syncOrders()
dispatch('change', schema)
} catch (err) {
sendUserToast(`Could not delete argument: ${err}`, true)
}
Expand Down
26 changes: 23 additions & 3 deletions frontend/src/lib/components/schema/EditableSchemaDrawer.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { Schema } from '$lib/common'
import { GripVertical, Pen } from 'lucide-svelte'
import { GripVertical, Pen, Trash } from 'lucide-svelte'
import EditableSchemaForm from '../EditableSchemaForm.svelte'
import { Drawer, DrawerContent } from '../common'
import AddProperty from './AddProperty.svelte'
Expand Down Expand Up @@ -56,7 +56,7 @@
}
const yOffset = 49
let jsonView: boolean = false
export let jsonView: boolean = false
let schemaString: string = JSON.stringify(schema, null, '\t')
let editor: SimpleEditor | undefined = undefined
let error: string | undefined = undefined
Expand All @@ -80,7 +80,17 @@
/>
</div>

<AddProperty on:change bind:schema bind:this={addProperty} />
<AddProperty
on:change={() => {
if (jsonView) {
schemaString = JSON.stringify(schema, null, '\t')
editor?.setCode(schemaString)
}
dispatch('change', schema)
}}
bind:schema
bind:this={addProperty}
/>

{#if !jsonView}
<div
Expand Down Expand Up @@ -111,6 +121,15 @@
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div class="flex flex-row gap-1 item-center h-full justify-center">
<Button
iconOnly
size="xs2"
color="light"
startIcon={{ icon: Trash }}
on:click={() => {
addProperty?.handleDeleteArgument([item.value])
}}
/>
<Button
iconOnly
size="xs2"
Expand Down Expand Up @@ -172,6 +191,7 @@
</DrawerContent>
</Drawer>
{:else}
<div class="mt-2" />
<SimpleEditor
bind:this={editor}
small
Expand Down

0 comments on commit 25a460b

Please sign in to comment.