From 846837ce6505b649edbfe7bab661cdc53a630593 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 28 Sep 2022 19:16:05 +0200 Subject: [PATCH] simplify script editor code bindings --- .../src/lib/components/ScriptBuilder.svelte | 37 +++---------------- .../src/lib/components/ScriptEditor.svelte | 19 ++++------ 2 files changed, 13 insertions(+), 43 deletions(-) diff --git a/frontend/src/lib/components/ScriptBuilder.svelte b/frontend/src/lib/components/ScriptBuilder.svelte index 45cb709742..069f07745d 100644 --- a/frontend/src/lib/components/ScriptBuilder.svelte +++ b/frontend/src/lib/components/ScriptBuilder.svelte @@ -6,9 +6,8 @@ import { inferArgs } from '$lib/infer' import { initialCode, isInitialCode } from '$lib/script_helpers' import { workspaceStore } from '$lib/stores' - import { emptySchema, encodeState, sendUserToast, setQueryWithoutLoad } from '$lib/utils' + import { encodeState, sendUserToast, setQueryWithoutLoad } from '$lib/utils' import { Breadcrumb, BreadcrumbItem } from 'flowbite-svelte' - import { onDestroy } from 'svelte' import SvelteMarkdown from 'svelte-markdown' import Path from './Path.svelte' import RadioButton from './RadioButton.svelte' @@ -18,9 +17,6 @@ import CenteredPage from './CenteredPage.svelte' import Tooltip from './Tooltip.svelte' - let editor: ScriptEditor - let scriptSchema: ScriptSchema - export let script: Script export let initialPath: string = '' export let template: 'pgsql' | 'script' = 'script' @@ -44,6 +40,9 @@ async function editScript(): Promise { try { + if (!script.schema) { + await inferArgs(script.language, script.content, script.schema) + } const newHash = await ScriptService.createScript({ workspace: $workspaceStore!, requestBody: { @@ -65,34 +64,12 @@ } } - export function setCode(script: Script) { - editor?.getEditor().setCode(script.content) - - if (scriptSchema) { - if (script.schema) { - scriptSchema.setSchema(script.schema) - } else { - scriptSchema.setSchema(emptySchema()) - } - } - } - - async function inferSchema() { - await inferArgs(script.language, script.content, script.schema) - } - async function changeStep(step: number) { - if (step == 3) { - script.content = editor?.getEditor().getCode() ?? script.content - await inferSchema() - script.schema = script.schema + if (step > 1) { + await inferArgs(script.language, script.content, script.schema) } goto(`?step=${step}`) } - - onDestroy(() => { - editor?.$destroy() - })
@@ -154,7 +131,6 @@