diff --git a/backend/windmill-api/src/scripts.rs b/backend/windmill-api/src/scripts.rs index 528f235eb6..3a4ffbd62a 100644 --- a/backend/windmill-api/src/scripts.rs +++ b/backend/windmill-api/src/scripts.rs @@ -82,6 +82,8 @@ pub struct ScriptWDraft { pub ws_error_handler_muted: Option, #[serde(skip_serializing_if = "Option::is_none")] pub priority: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub restart_unless_cancelled: Option, } pub fn global_service() -> Router { @@ -714,7 +716,7 @@ async fn get_script_by_path_w_draft( let mut tx = user_db.begin(&authed).await?; let script_o = sqlx::query_as::<_, ScriptWDraft>( - "SELECT hash, script.path, summary, description, content, language, kind, tag, schema, draft_only, envs, concurrent_limit, concurrency_time_window_s, cache_ttl, ws_error_handler_muted, draft.value as draft, dedicated_worker, priority FROM script LEFT JOIN draft ON + "SELECT hash, script.path, summary, description, content, language, kind, tag, schema, draft_only, envs, concurrent_limit, concurrency_time_window_s, cache_ttl, ws_error_handler_muted, draft.value as draft, dedicated_worker, priority, restart_unless_cancelled FROM script LEFT JOIN draft ON script.path = draft.path AND script.workspace_id = draft.workspace_id AND draft.typ = 'script' WHERE script.path = $1 AND script.workspace_id = $2 \ AND script.created_at = (SELECT max(created_at) FROM script WHERE path = $1 AND \ diff --git a/cli/store.ts b/cli/store.ts index 2fa6529da9..0e057a9d58 100644 --- a/cli/store.ts +++ b/cli/store.ts @@ -14,7 +14,7 @@ function hash_string(str: string): number { } export async function getRootStore(): Promise { - const store = dir("config") + "/windmill/"; + const store = (dir("config") ?? dir("tmp") ?? "/tmp/") + "/windmill/"; await ensureDir(store); return store; } diff --git a/frontend/src/lib/common.ts b/frontend/src/lib/common.ts index fa67280053..81a586cbfb 100644 --- a/frontend/src/lib/common.ts +++ b/frontend/src/lib/common.ts @@ -36,6 +36,7 @@ export interface SchemaProperty { customErrorMessage?: string properties?: { [name: string]: SchemaProperty } required?: string[] + hideExpr?: string } export interface ModalSchemaProperty { @@ -56,6 +57,7 @@ export interface ModalSchemaProperty { contentEncoding?: 'base64' | 'binary' schema?: Schema customErrorMessage?: string + hideExpr?: string } export function modalToSchema(schema: ModalSchemaProperty): SchemaProperty { @@ -75,7 +77,8 @@ export function modalToSchema(schema: ModalSchemaProperty): SchemaProperty { max: schema.max, currency: schema.currency, currencyLocale: schema.currencyLocale, - multiselect: schema.multiselect + multiselect: schema.multiselect, + hideExpr: schema.hideExpr } } export type Schema = { diff --git a/frontend/src/lib/components/LightweightSchemaForm.svelte b/frontend/src/lib/components/LightweightSchemaForm.svelte index 6ca6a345a1..5f1c6d2be3 100644 --- a/frontend/src/lib/components/LightweightSchemaForm.svelte +++ b/frontend/src/lib/components/LightweightSchemaForm.svelte @@ -55,33 +55,56 @@ schema.properties = n } } + + function computeHide(expr: string | undefined) { + if (expr) { + try { + let template = ` + return async function (values) { +"use strict"; +${expr.startsWith('return ') ? expr.substring(7) : expr} +} +` + console.log(template) + let functor = Function(template) + let r = functor()(args) + return r + } catch (e) { + console.error(`Impossible to eval ${expr}:`, e) + return false + } + } + return false + }
{#each Object.keys(schema.properties ?? {}) as argName (argName)} {#if typeof args == 'object' && schema?.properties[argName] && args} - + {#if !computeHide(schema?.properties[argName].hideExpr) || true} + + {/if} {/if} {/each}
diff --git a/frontend/src/lib/components/SchemaModal.svelte b/frontend/src/lib/components/SchemaModal.svelte index caaa9b5568..0fcecb4be1 100644 --- a/frontend/src/lib/components/SchemaModal.svelte +++ b/frontend/src/lib/components/SchemaModal.svelte @@ -39,7 +39,8 @@ properties: schema.properties ?? {}, required: schema.required ?? [] } - : undefined + : undefined, + hideExpr: schema.hideExpr } } @@ -65,6 +66,7 @@ import LightweightSchemaForm from './LightweightSchemaForm.svelte' import NumberTypeNarrowing from './NumberTypeNarrowing.svelte' import Label from './Label.svelte' + // import SimpleEditor from './SimpleEditor.svelte' export let error = '' export let editing = false @@ -109,7 +111,7 @@ property.currencyLocale = undefined property.multiselect = undefined property.items = undefined - + property.hideExpr = undefined drawer.closeDrawer() } @@ -183,6 +185,7 @@ } else { property.items = undefined } + property.hideExpr = undefined }} id={`schema-modal-type-${argType}`} > @@ -275,9 +278,25 @@ - {:else} -

No advanced configuration for this type

{/if} + {/if} diff --git a/frontend/src/lib/components/ScriptBuilder.svelte b/frontend/src/lib/components/ScriptBuilder.svelte index b5636d5a8b..dbef4643a4 100644 --- a/frontend/src/lib/components/ScriptBuilder.svelte +++ b/frontend/src/lib/components/ScriptBuilder.svelte @@ -288,7 +288,8 @@ concurrency_time_window_s: script.concurrency_time_window_s, cache_ttl: script.cache_ttl, ws_error_handler_muted: script.ws_error_handler_muted, - priority: script.priority + priority: script.priority, + restart_unless_cancelled: script.restart_unless_cancelled } }) } diff --git a/frontend/src/lib/components/flows/common/FlowCard.svelte b/frontend/src/lib/components/flows/common/FlowCard.svelte index 13c1a1a3d0..0d3e37d7de 100644 --- a/frontend/src/lib/components/flows/common/FlowCard.svelte +++ b/frontend/src/lib/components/flows/common/FlowCard.svelte @@ -8,7 +8,7 @@ {#if !noEditor} - + {/if} diff --git a/frontend/src/lib/components/flows/common/FlowCardHeader.svelte b/frontend/src/lib/components/flows/common/FlowCardHeader.svelte index 4c4048d966..50363b6fa2 100644 --- a/frontend/src/lib/components/flows/common/FlowCardHeader.svelte +++ b/frontend/src/lib/components/flows/common/FlowCardHeader.svelte @@ -6,6 +6,7 @@ import { ScriptService, type FlowModule, type PathScript } from '$lib/gen' import { workspaceStore } from '$lib/stores' import { Lock, Unlock } from 'lucide-svelte' + import { createEventDispatcher } from 'svelte' export let flowModule: FlowModule | undefined = undefined export let title: string | undefined = undefined @@ -17,8 +18,11 @@ path: value.path }) latestHash = script.hash + dispatch('reload') } + const dispatch = createEventDispatcher() + $: $workspaceStore && flowModule?.value.type === 'script' && flowModule.value.path && diff --git a/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte b/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte index 0a92c6ce86..6cd5a6648f 100644 --- a/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte +++ b/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte @@ -176,7 +176,7 @@ {#if flowModule.value}
- + reload(flowModule)} {noEditor} bind:flowModule> {#key forceReload} - + reload(flowModule)} + path={flowModule.value.path} + hash={flowModule.value.hash} + /> {/key}
{/if} diff --git a/frontend/src/lib/components/flows/content/FlowModuleScript.svelte b/frontend/src/lib/components/flows/content/FlowModuleScript.svelte index 55bc4962e2..fdc6f3e9a1 100644 --- a/frontend/src/lib/components/flows/content/FlowModuleScript.svelte +++ b/frontend/src/lib/components/flows/content/FlowModuleScript.svelte @@ -4,6 +4,7 @@ import { ScriptService } from '$lib/gen' import { getScriptByPath } from '$lib/scripts' import { workspaceStore } from '$lib/stores' + import { createEventDispatcher } from 'svelte' export let path: string export let hash: string | undefined = undefined @@ -12,6 +13,7 @@ let language: SupportedLanguage let notFound = false + const dispatch = createEventDispatcher() async function loadCode(path: string, hash: string | undefined) { try { notFound = false @@ -20,6 +22,7 @@ : await getScriptByPath(path!) code = script.content language = script.language + dispatch('reload') } catch (e) { notFound = true console.error(e)