fix: improve schedule args clearing on script change

This commit is contained in:
Ruben Fiszel
2024-01-29 11:18:18 +01:00
parent 59bbff662e
commit 8e5f4dda95
4 changed files with 20 additions and 12 deletions
@@ -56,6 +56,9 @@
let script_path = ''
let initialScriptPath = ''
let runnable: Script | Flow | undefined
let args: Record<string, any> = {}
export function openEdit(ePath: string, isFlow: boolean) {
is_flow = isFlow
initialPath = ePath
@@ -70,6 +73,8 @@
}
export async function openNew(is_flow: boolean, initial_script_path?: string) {
args = {}
runnable = undefined
let defaultErrorHandlerMaybe = undefined
let defaultRecoveryHandlerMaybe = undefined
if ($workspaceStore) {
@@ -90,7 +95,6 @@
initialPath = initialScriptPath
script_path = initialScriptPath
if (defaultErrorHandlerMaybe !== undefined && defaultErrorHandlerMaybe !== null) {
console.log(defaultErrorHandlerMaybe)
wsErrorHandlerMuted = defaultErrorHandlerMaybe['wsErrorHandlerMuted']
let splitted = (defaultErrorHandlerMaybe['errorHandlerPath'] as string).split('/')
errorHandleritemKind = splitted[0] as 'flow' | 'script'
@@ -135,9 +139,6 @@
$: (is_flow = itemKind == 'flow') && resetRetries()
let runnable: Script | Flow | undefined
let args: Record<string, any> = {}
let isValid = true
let path: string = ''
@@ -161,7 +162,10 @@
const dispatch = createEventDispatcher()
async function loadScript(p: string | undefined): Promise<void> {
console.log('LOAD', p)
if (p) {
args = {}
runnable = undefined
if (is_flow) {
runnable = await FlowService.getFlowByPath({ workspace: $workspaceStore!, path: p })
} else {
@@ -239,7 +243,12 @@
schedule = s.schedule
timezone = s.timezone
summary = s.summary ?? ''
let oldScriptPath = script_path
script_path = s.script_path ?? ''
if (oldScriptPath == script_path) {
loadScript(script_path)
}
console.log(script_path)
is_flow = s.is_flow
no_flow_overlap = s.no_flow_overlap ?? false
wsErrorHandlerMuted = s.ws_error_handler_muted ?? false
@@ -538,8 +547,6 @@
</div>
</Section>
{#if !is_flow}{/if}
<div class="flex flex-col gap-2">
<Tabs bind:selected={optionTabSelected}>
<Tab value="error_handler">Error Handler</Tab>
@@ -54,6 +54,8 @@
args = nargs
}
let keys: string[] = []
function removeExtraKey() {
const nargs = {}
Object.keys(args ?? {}).forEach((key) => {
@@ -68,7 +70,6 @@
let itemPicker: ItemPicker | undefined = undefined
let variableEditor: VariableEditor | undefined = undefined
let keys: string[] = []
$: {
let lkeys = Object.keys(schema?.properties ?? {})
if (schema?.properties && JSON.stringify(lkeys) != JSON.stringify(keys)) {
@@ -867,7 +867,7 @@
<LanguageIcon lang={script.language} height={20} />
</button>
</div>
<div class="min-w-64 w-full max-w-md">
<div class="min-w-32 lg:min-w-64 w-full max-w-md">
<input
type="text"
placeholder="Script summary"
@@ -931,7 +931,7 @@
>
<div class="flex flex-row gap-2 items-center">
<DiffIcon size={14} />
Diff
<span class="hidden lg:flex"> Diff </span>
</div>
</Button>
<Button
@@ -943,7 +943,7 @@
}}
startIcon={{ icon: Settings }}
>
Settings
<span class="hidden lg:flex"> Settings </span>
</Button>
<Button
loading={loadingDraft}
@@ -952,7 +952,7 @@
on:click={() => saveDraft()}
disabled={initialPath != '' && !savedScript}
>
<span class="hidden sm:flex">
<span class="hidden lg:flex">
Save draft&nbsp;<Kbd small isModifier>{getModifierKey()}</Kbd>
</span>
<Kbd small>S</Kbd>
@@ -135,7 +135,7 @@
<div class="text-center text-sm text-tertiary mt-2"> No schedules </div>
{:else if filteredItems?.length}
<div class="border rounded-md divide-y">
{#each filteredItems as { path, error, summary, edited_by, edited_at, schedule, timezone, enabled, script_path, is_flow, extra_perms, canWrite, args, marked, jobs }}
{#each filteredItems as { path, error, summary, edited_by, edited_at, schedule, timezone, enabled, script_path, is_flow, extra_perms, canWrite, args, marked, jobs } (path)}
{@const href = `${is_flow ? '/flows/get' : '/scripts/get'}/${script_path}`}
{@const avg_s = jobs
? jobs.reduce((acc, x) => acc + x.duration_ms, 0) / jobs.length