multiple small fixes

This commit is contained in:
Ruben Fiszel
2023-12-07 15:40:09 +01:00
parent da15a56a07
commit c0ed1ace54
10 changed files with 92 additions and 33 deletions
+3 -1
View File
@@ -82,6 +82,8 @@ pub struct ScriptWDraft {
pub ws_error_handler_muted: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub priority: Option<i16>,
#[serde(skip_serializing_if = "Option::is_none")]
pub restart_unless_cancelled: Option<bool>,
}
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 \
+1 -1
View File
@@ -14,7 +14,7 @@ function hash_string(str: string): number {
}
export async function getRootStore(): Promise<string> {
const store = dir("config") + "/windmill/";
const store = (dir("config") ?? dir("tmp") ?? "/tmp/") + "/windmill/";
await ensureDir(store);
return store;
}
+4 -1
View File
@@ -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 = {
@@ -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
}
</script>
<div class={twMerge('w-full flex flex-col px-0.5 pb-2', largeGap ? 'gap-8' : 'gap-2')}>
{#each Object.keys(schema.properties ?? {}) as argName (argName)}
{#if typeof args == 'object' && schema?.properties[argName] && args}
<LightweightArgInput
label={argName}
description={schema.properties[argName].description}
bind:value={args[argName]}
bind:valid={inputCheck[argName]}
bind:error={errors[argName]}
type={schema.properties[argName].type}
required={schema.required?.includes(argName) ?? false}
pattern={schema.properties[argName].pattern}
defaultValue={schema.properties[argName].default}
enum_={schema.properties[argName].enum}
format={schema.properties[argName].format}
contentEncoding={schema.properties[argName].contentEncoding}
customErrorMessage={schema.properties[argName].customErrorMessage}
properties={schema.properties[argName].properties}
nestedRequired={schema.properties[argName].required}
itemsType={schema.properties[argName].items}
extra={schema.properties[argName]}
on:inputClicked
{displayType}
{css}
/>
{#if !computeHide(schema?.properties[argName].hideExpr) || true}
<LightweightArgInput
label={argName}
description={schema.properties[argName].description}
bind:value={args[argName]}
bind:valid={inputCheck[argName]}
bind:error={errors[argName]}
type={schema.properties[argName].type}
required={schema.required?.includes(argName) ?? false}
pattern={schema.properties[argName].pattern}
defaultValue={schema.properties[argName].default}
enum_={schema.properties[argName].enum}
format={schema.properties[argName].format}
contentEncoding={schema.properties[argName].contentEncoding}
customErrorMessage={schema.properties[argName].customErrorMessage}
properties={schema.properties[argName].properties}
nestedRequired={schema.properties[argName].required}
itemsType={schema.properties[argName].items}
extra={schema.properties[argName]}
on:inputClicked
{displayType}
{css}
/>
{/if}
{/if}
{/each}
</div>
+23 -4
View File
@@ -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 @@
</div>
</svelte:fragment>
</Tabs>
{:else}
<p>No advanced configuration for this type</p>
{/if}
<!-- <div class="pt-2">
<Toggle
options={{ right: 'Hide this field conditionally' }}
class="!justify-start"
checked={Boolean(property.hideExpr)}
on:change={() => {
property.hideExpr = property.hideExpr ? undefined : "//props.foo == 'bar'\nfalse"
}}
/>
{#if property.hideExpr != undefined}
<SimpleEditor
lang="javascript"
bind:code={property.hideExpr}
shouldBindKey={false}
autoHeight
/>
{/if}
</div> -->
</div>
{/if}
</div>
@@ -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
}
})
}
@@ -8,7 +8,7 @@
</script>
{#if !noEditor}
<FlowCardHeader {title} bind:flowModule>
<FlowCardHeader on:reload {title} bind:flowModule>
<slot name="header" />
</FlowCardHeader>
{/if}
@@ -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 &&
@@ -176,7 +176,7 @@
{#if flowModule.value}
<div class="h-full" bind:this={wrapper} bind:clientWidth={width}>
<FlowCard {noEditor} bind:flowModule>
<FlowCard on:reload={() => reload(flowModule)} {noEditor} bind:flowModule>
<svelte:fragment slot="header">
<FlowModuleHeader
bind:module={flowModule}
@@ -296,7 +296,11 @@
{#if !noEditor}
<div class="border-t">
{#key forceReload}
<FlowModuleScript path={flowModule.value.path} hash={flowModule.value.hash} />
<FlowModuleScript
on:reload={() => reload(flowModule)}
path={flowModule.value.path}
hash={flowModule.value.hash}
/>
{/key}
</div>
{/if}
@@ -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)