From c2e9ef1ca05aee34edd5bc716371b944dac3bce1 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 5 Jul 2022 11:26:06 +0200 Subject: [PATCH] feat: in-flow editor mvp --- backend/openapi.yaml | 9 ++- backend/src/flow.rs | 22 +++++-- backend/src/jobs.rs | 8 ++- frontend/src/lib/components/Editor.svelte | 5 +- frontend/src/lib/components/FlowEditor.svelte | 8 --- frontend/src/lib/components/ModuleStep.svelte | 66 +++++++++++++++++-- .../lib/components/ObjectResourceInput.svelte | 1 - .../src/lib/components/ScriptBuilder.svelte | 49 +------------- .../lib/components/flows/loadFlowSchemas.ts | 25 ------- frontend/src/lib/script_helpers.ts | 45 +++++++++++++ frontend/src/lib/scripts.ts | 3 +- 11 files changed, 142 insertions(+), 99 deletions(-) delete mode 100644 frontend/src/lib/components/flows/loadFlowSchemas.ts create mode 100644 frontend/src/lib/script_helpers.ts diff --git a/backend/openapi.yaml b/backend/openapi.yaml index 9ae52cf01f..024779e200 100644 --- a/backend/openapi.yaml +++ b/backend/openapi.yaml @@ -3701,14 +3701,21 @@ components: properties: path: type: string + content: + type: string + language: + type: string + enum: + - deno + - python3 type: type: string enum: - script - flow + - rawscript required: - type - - path FlowPreview: type: object diff --git a/backend/src/flow.rs b/backend/src/flow.rs index 90f0eea719..39b53f0d13 100644 --- a/backend/src/flow.rs +++ b/backend/src/flow.rs @@ -22,6 +22,7 @@ use crate::{ audit::{audit_log, ActionKind}, db::UserDB, error::{Error, JsonResult, Result}, + jobs::RawCode, scripts::Schema, users::Authed, utils::{Pagination, StripPath}, @@ -90,6 +91,7 @@ pub enum InputTransform { pub enum FlowModuleValue { Script { path: String }, Flow { path: String }, + RawScript(RawCode), } #[derive(Deserialize)] @@ -307,12 +309,22 @@ mod tests { }, ); let fv = FlowValue { - modules: vec![FlowModule { - input_transform: hm, - value: FlowModuleValue::Script { - path: "test".to_string(), + modules: vec![ + FlowModule { + input_transform: hm, + value: FlowModuleValue::Script { + path: "test".to_string(), + }, }, - }], + FlowModule { + input_transform: HashMap::new(), + value: FlowModuleValue::RawScript(RawCode { + content: "test".to_string(), + language: crate::scripts::ScriptLang::Deno, + path: None, + }), + }, + ], failure_module: Some(FlowModule { input_transform: HashMap::new(), value: FlowModuleValue::Flow { diff --git a/backend/src/jobs.rs b/backend/src/jobs.rs index 2b7efc57ea..e169919d36 100644 --- a/backend/src/jobs.rs +++ b/backend/src/jobs.rs @@ -950,10 +950,11 @@ struct CancelJob { reason: Option, } +#[derive(Clone, Serialize, Deserialize, Debug)] pub struct RawCode { - content: String, - path: Option, - language: ScriptLang, + pub content: String, + pub path: Option, + pub language: ScriptLang, } #[derive(Deserialize)] @@ -1504,6 +1505,7 @@ async fn push_next_flow_job( FlowModuleValue::Script { path: script_path } => { script_path_to_payload(script_path, &mut tx, &job.workspace_id).await? } + FlowModuleValue::RawScript(raw_code) => JobPayload::Code(raw_code.clone()), a @ _ => { tracing::info!("Unrecognized module values {:?}", a); Err(Error::BadRequest(format!( diff --git a/frontend/src/lib/components/Editor.svelte b/frontend/src/lib/components/Editor.svelte index f9a61ff0bb..58e4456a15 100644 --- a/frontend/src/lib/components/Editor.svelte +++ b/frontend/src/lib/components/Editor.svelte @@ -13,7 +13,7 @@ let editor: monaco.editor.IStandaloneCodeEditor export let deno = false export let lang = deno ? 'typescript' : 'python' - export let code: string + export let code: string = '' export let hash: string = (Math.random() + 1).toString(36).substring(2) export let cmdEnterAction: (() => void) | undefined = undefined export let formatAction: (() => void) | undefined = undefined @@ -277,6 +277,9 @@ scrollBeyondLastLine: false, minimap: { enabled: false + }, + scrollbar: { + alwaysConsumeMouseWheel: false } }) diff --git a/frontend/src/lib/components/FlowEditor.svelte b/frontend/src/lib/components/FlowEditor.svelte index 76ba76d7b8..c307a835b5 100644 --- a/frontend/src/lib/components/FlowEditor.svelte +++ b/frontend/src/lib/components/FlowEditor.svelte @@ -2,12 +2,10 @@ import type { Schema } from '$lib/common' import { FlowModuleValue, type Flow } from '$lib/gen' import { loadSchema } from '$lib/scripts' - import { workspaceStore } from '$lib/stores' import { emptySchema } from '$lib/utils' import { faPlus } from '@fortawesome/free-solid-svg-icons' import Icon from 'svelte-awesome' import FlowPreview from './FlowPreview.svelte' - import { loadFlowSchemas } from './flows/loadFlowSchemas' import ModuleStep from './ModuleStep.svelte' import SchemaEditor from './SchemaEditor.svelte' import type SchemaForm from './SchemaForm.svelte' @@ -28,12 +26,6 @@ flow.value.modules = flow.value.modules.concat(newModule) schemas.push(emptySchema()) } - - async function loadSchemas() { - schemas = await loadFlowSchemas(flow, $workspaceStore!) - } - - $: $workspaceStore && loadSchemas() diff --git a/frontend/src/lib/components/ModuleStep.svelte b/frontend/src/lib/components/ModuleStep.svelte index 2405e81d20..c0392d9285 100644 --- a/frontend/src/lib/components/ModuleStep.svelte +++ b/frontend/src/lib/components/ModuleStep.svelte @@ -1,8 +1,10 @@
  • @@ -74,7 +103,32 @@

    Step script

    - + + {#if mod.value.type == 'script'} + + {:else} +
    + +
    + +
    + + {/if}

    Step inputs

    = {} if (!isString(value) && value) { - console.log(value) args = value } diff --git a/frontend/src/lib/components/ScriptBuilder.svelte b/frontend/src/lib/components/ScriptBuilder.svelte index 395e3071ec..16957c3afe 100644 --- a/frontend/src/lib/components/ScriptBuilder.svelte +++ b/frontend/src/lib/components/ScriptBuilder.svelte @@ -1,51 +1,3 @@ - -