mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 16:02:14 +00:00
fix(frontend): rework the error handler script picker
This commit is contained in:
@@ -102,7 +102,7 @@
|
||||
</top>
|
||||
<down slot="down">
|
||||
<pre
|
||||
class="overflow-x-auto break-all relative h-full p-2 text-sm">{#if testJob && 'result' in testJob && testJob.result}<DisplayResult
|
||||
class="overflow-x-auto break-all relative h-full p-2 text-sm">{#if testJob && 'result' in testJob && testJob.result != undefined}<DisplayResult
|
||||
result={testJob.result}
|
||||
/>
|
||||
{:else if testIsLoading}Waiting for Result...
|
||||
|
||||
@@ -12,11 +12,12 @@
|
||||
|
||||
{#if $flowStore.value.failure_module}
|
||||
<FlowModule
|
||||
previewArgs={previewArgs}
|
||||
{previewArgs}
|
||||
bind:flowModule={$flowStore.value.failure_module}
|
||||
bind:flowModuleState={$flowStateStore.failureModule}
|
||||
on:delete={() => {
|
||||
$flowStore.value.failure_module = undefined
|
||||
}}
|
||||
failureModule={true}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
export let shouldDisableLoopCreation: boolean = false
|
||||
export let shouldDisableTriggerScripts: boolean = false
|
||||
export let failureModule: boolean
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
</script>
|
||||
|
||||
@@ -18,8 +20,8 @@
|
||||
{/if}
|
||||
|
||||
<div class="grid sm:grid-col-2 lg:grid-cols-3 gap-4">
|
||||
<PickScript kind={Script.kind.SCRIPT} on:pick />
|
||||
<PickHubScript kind={Script.kind.SCRIPT} on:pick />
|
||||
<PickScript kind={failureModule ? Script.kind.FAILURE : Script.kind.SCRIPT} on:pick />
|
||||
<PickHubScript kind={failureModule ? Script.kind.FAILURE : Script.kind.SCRIPT} on:pick />
|
||||
|
||||
<FlowScriptPicker
|
||||
label={`Create a for-loop here`}
|
||||
@@ -29,20 +31,26 @@
|
||||
on:click={() => dispatch('loop')}
|
||||
/>
|
||||
|
||||
<FlowScriptPicker
|
||||
label={`New PostgreSQL query`}
|
||||
icon={faCode}
|
||||
iconColor="text-blue-800"
|
||||
on:click={() =>
|
||||
dispatch('new', { language: RawScript.language.DENO, kind: 'script', subkind: 'pgsql' })}
|
||||
/>
|
||||
{#if !failureModule}
|
||||
<FlowScriptPicker
|
||||
label={`New PostgreSQL query`}
|
||||
icon={faCode}
|
||||
iconColor="text-blue-800"
|
||||
on:click={() =>
|
||||
dispatch('new', { language: RawScript.language.DENO, kind: 'script', subkind: 'pgsql' })}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<FlowScriptPicker
|
||||
label="New Python script (3.10)"
|
||||
icon={faCode}
|
||||
iconColor="text-green-500"
|
||||
on:click={() =>
|
||||
dispatch('new', { language: RawScript.language.PYTHON3, kind: 'script', subkind: 'flow' })}
|
||||
dispatch('new', {
|
||||
language: RawScript.language.PYTHON3,
|
||||
kind: 'script',
|
||||
subkind: failureModule ? 'failure' : 'flow'
|
||||
})}
|
||||
/>
|
||||
|
||||
<FlowScriptPicker
|
||||
@@ -50,7 +58,11 @@
|
||||
icon={faCode}
|
||||
iconColor="text-blue-800"
|
||||
on:click={() =>
|
||||
dispatch('new', { language: RawScript.language.DENO, kind: 'script', subkind: 'flow' })}
|
||||
dispatch('new', {
|
||||
language: RawScript.language.DENO,
|
||||
kind: 'script',
|
||||
subkind: failureModule ? 'failure' : 'flow'
|
||||
})}
|
||||
/>
|
||||
|
||||
<FlowScriptPicker
|
||||
@@ -58,7 +70,11 @@
|
||||
icon={faCode}
|
||||
iconColor="text-blue-700"
|
||||
on:click={() =>
|
||||
dispatch('new', { language: RawScript.language.GO, kind: 'script', subkind: 'flow' })}
|
||||
dispatch('new', {
|
||||
language: RawScript.language.GO,
|
||||
kind: 'script',
|
||||
subkind: failureModule ? 'failure' : 'flow'
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
export let flowModule: FlowModule
|
||||
export let previewArgs: Record<string, any> = {}
|
||||
export let flowModuleState: FlowModuleState
|
||||
export let failureModule: boolean
|
||||
|
||||
$: [parentIndex, childIndex] = $selectedId.split('-').map(Number)
|
||||
|
||||
@@ -54,12 +55,14 @@
|
||||
let selected = 'inputs'
|
||||
|
||||
$: shouldPick = isEmptyFlowModule(flowModule)
|
||||
$: stepPropPicker = getStepPropPicker(
|
||||
$selectedId.split('-').map(Number),
|
||||
$flowStore.schema,
|
||||
$flowStateStore,
|
||||
previewArgs
|
||||
)
|
||||
$: stepPropPicker = failureModule
|
||||
? { pickableProperties: { previous_result: { error: 'the error message' } }, extraLib: '' }
|
||||
: getStepPropPicker(
|
||||
$selectedId.split('-').map(Number),
|
||||
$flowStore.schema,
|
||||
$flowStateStore,
|
||||
previewArgs
|
||||
)
|
||||
|
||||
function onKeyDown(event: KeyboardEvent) {
|
||||
if ((event.ctrlKey || event.metaKey) && event.key == 'Enter') {
|
||||
@@ -136,6 +139,7 @@
|
||||
kind: e.detail.kind,
|
||||
subkind: e.detail.subkind
|
||||
})}
|
||||
{failureModule}
|
||||
/>
|
||||
{:else}
|
||||
{#if flowModule.value.type === 'rawscript'}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
{#each [$flowStateStore.modules[parentIndex].childFlowModules] as state}
|
||||
{#if mod.type == 'forloopflow' && state != undefined}
|
||||
<FlowModule
|
||||
failureModule={false}
|
||||
previewArgs={$previewArgs}
|
||||
bind:flowModule={mod.modules[childIndex]}
|
||||
bind:flowModuleState={state[childIndex]}
|
||||
@@ -39,6 +40,7 @@
|
||||
{/each}
|
||||
{:else if $flowStore.value.modules[parentIndex]}
|
||||
<FlowModule
|
||||
failureModule={false}
|
||||
previewArgs={$previewArgs}
|
||||
bind:flowModule={$flowStore.value.modules[parentIndex]}
|
||||
bind:flowModuleState={$flowStateStore.modules[parentIndex]}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Schema } from '$lib/common'
|
||||
import { CompletedJob, Job, Script, ScriptService, type FlowModule, type RawScript } from '$lib/gen'
|
||||
import { initialCode } from '$lib/script_helpers'
|
||||
import { DENO_FAILURE_MODULE_CODE, initialCode } from '$lib/script_helpers'
|
||||
import { userStore, workspaceStore } from '$lib/stores'
|
||||
import {
|
||||
buildExtraLib,
|
||||
@@ -49,7 +49,7 @@ export async function createInlineScriptModule({
|
||||
}: {
|
||||
language: RawScript.language
|
||||
kind: Script.kind
|
||||
subkind: 'pgsql' | 'flow'
|
||||
subkind: 'pgsql' | 'flow',
|
||||
}): Promise<[FlowModule, FlowModuleState]> {
|
||||
const code = initialCode(language, kind, subkind)
|
||||
|
||||
@@ -184,7 +184,7 @@ type Result = any
|
||||
type PickableProperties = {
|
||||
flow_input?: Object
|
||||
previous_result: Result | undefined
|
||||
step: Result[]
|
||||
step?: Result[]
|
||||
}
|
||||
|
||||
type StepPropPicker = {
|
||||
@@ -210,8 +210,8 @@ export function getStepPropPicker(
|
||||
parentIndex == 0
|
||||
? flowInput
|
||||
: results.length > 0
|
||||
? results[results.length - 1]
|
||||
: NEVER_TESTED_THIS_FAR
|
||||
? results[results.length - 1]
|
||||
: NEVER_TESTED_THIS_FAR
|
||||
|
||||
if (isInsideLoop) {
|
||||
let forLoopFlowInput = {
|
||||
@@ -235,8 +235,8 @@ export function getStepPropPicker(
|
||||
childIndex == 0
|
||||
? forLoopFlowInput
|
||||
: innerResults.length > 0
|
||||
? innerResults[innerResults.length - 1]
|
||||
: NEVER_TESTED_THIS_FAR
|
||||
? innerResults[innerResults.length - 1]
|
||||
: NEVER_TESTED_THIS_FAR
|
||||
|
||||
const extraLib = buildExtraLib(
|
||||
objectToTsType(forLoopFlowInput),
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<Menu placement="bottom-end">
|
||||
<button
|
||||
slot="trigger"
|
||||
class="flex items-center px-3 py-2.5 text-sm border focus:outline-none focus:ring-4 font-medium rounded-md text-gray-800 bg-white hover:bg-gray-100 focus:ring-gray-300 px-4 py-2"
|
||||
class="flex items-center text-sm border focus:outline-none focus:ring-4 font-medium rounded-md text-gray-800 bg-white hover:bg-gray-100 focus:ring-gray-300 px-4 py-2"
|
||||
>
|
||||
Import/Export
|
||||
</button>
|
||||
|
||||
@@ -61,6 +61,20 @@ func main(x string) (interface{}, error) {
|
||||
}
|
||||
`
|
||||
|
||||
export const GO_FAILURE_MODULE_CODE = `import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// connect the error parameter to 'previous_result.error'
|
||||
|
||||
func main(error string) (interface{}, error) {
|
||||
fmt.Println(error)
|
||||
fmt.Println("job", os.Getenv("WM_JOB_ID"))
|
||||
return x, nil
|
||||
}
|
||||
`
|
||||
|
||||
export const DENO_INIT_CODE_CLEAR = `// import * as wmill from "https://deno.land/x/windmill@v${__pkg__.version}/mod.ts"
|
||||
|
||||
export async function main(x: string) {
|
||||
@@ -68,12 +82,34 @@ export async function main(x: string) {
|
||||
}
|
||||
`
|
||||
|
||||
export const DENO_FAILURE_MODULE_CODE = `
|
||||
// connect the error parameter to 'previous_result.error'
|
||||
|
||||
export async function main(error: string) {
|
||||
const job = Deno.env.get("WM_JOB_ID")
|
||||
console.log("error", error)
|
||||
console.log("job", job)
|
||||
return { error, job }
|
||||
}
|
||||
`
|
||||
|
||||
export const PYTHON_INIT_CODE_CLEAR = `#import wmill
|
||||
|
||||
def main(x: str):
|
||||
return x
|
||||
`
|
||||
|
||||
export const PYTHON_FAILURE_MODULE_CODE = `import os
|
||||
|
||||
# connect the error parameter to 'previous_result.error'
|
||||
|
||||
def main(error: str):
|
||||
job = os.environ.get("WM_JOB_ID")
|
||||
print("error", error)
|
||||
print("job", job)
|
||||
return error, job
|
||||
`
|
||||
|
||||
export const POSTGRES_INIT_CODE = `import {
|
||||
pgSql,
|
||||
type Resource,
|
||||
@@ -123,14 +159,17 @@ export function isInitialCode(content: string): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
export function initialCode(language: 'deno' | 'python3' | 'go', kind: Script.kind, subkind: 'pgsql' | 'flow' | 'script' | undefined): string {
|
||||
export function initialCode(language: 'deno' | 'python3' | 'go', kind: Script.kind, subkind: 'pgsql' | 'flow' | 'script' | 'failure' | undefined): string {
|
||||
if (language === 'deno') {
|
||||
if (kind === 'trigger') {
|
||||
return DENO_INIT_CODE_TRIGGER
|
||||
} else if (kind === 'script') {
|
||||
if (subkind === 'flow') {
|
||||
return DENO_INIT_CODE_CLEAR
|
||||
} else if (subkind === 'pgsql') {
|
||||
} else if (subkind === 'failure') {
|
||||
return DENO_FAILURE_MODULE_CODE
|
||||
}
|
||||
else if (subkind === 'pgsql') {
|
||||
return POSTGRES_INIT_CODE
|
||||
} else {
|
||||
return DENO_INIT_CODE
|
||||
@@ -141,10 +180,16 @@ export function initialCode(language: 'deno' | 'python3' | 'go', kind: Script.ki
|
||||
} else if (language === 'python3') {
|
||||
if (subkind === 'flow') {
|
||||
return PYTHON_INIT_CODE_CLEAR
|
||||
} else if (subkind === 'failure') {
|
||||
return PYTHON_FAILURE_MODULE_CODE
|
||||
} else {
|
||||
return PYTHON_INIT_CODE
|
||||
}
|
||||
} else {
|
||||
return GO_INIT_CODE
|
||||
if (subkind === 'failure') {
|
||||
return GO_FAILURE_MODULE_CODE
|
||||
} else {
|
||||
return GO_INIT_CODE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user