From 5502047474c5a896a835ba286ea893440ff3713f Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Wed, 13 Jul 2022 11:29:43 +0200 Subject: [PATCH] Refactor flow UI/UX + added fork and create script from inline script (#175) * Refactor flow UI/UX + added fork and create script from inline script * Prevent infinite loop when remove steps * Fix forking a script from the Hub * Fix viewing code of a script from the Hub * Fix PR comments * Fix code highlight * Fix path * Find next available path * Fix copy first step schema --- frontend/src/app.css | 24 ++ .../src/lib/components/FlowBuilder.svelte | 25 +- frontend/src/lib/components/FlowEditor.svelte | 52 ++--- .../src/lib/components/FlowPreview.svelte | 5 +- frontend/src/lib/components/ModuleStep.svelte | 219 ++++++------------ frontend/src/lib/components/SchemaForm.svelte | 88 +------ .../flows/CopyFirstStepSchema.svelte | 11 + .../flows/DynamicInputHelpBox.svelte | 73 ++++++ .../lib/components/flows/FlowInputs.svelte | 28 +++ .../components/flows/FlowModuleHeader.svelte | 76 ++++++ .../lib/components/flows/PropPicker.svelte | 2 - .../src/lib/components/flows/flowStore.ts | 190 +++++++++++++++ .../flows/pickers/FlowScriptPicker.svelte | 13 ++ .../flows/pickers/PickHubScript.svelte | 34 +++ .../flows/pickers/PickScript.svelte | 45 ++++ frontend/src/lib/components/flows/utils.ts | 109 +++++++++ .../src/routes/flows/edit/[...path].svelte | 2 +- 17 files changed, 708 insertions(+), 288 deletions(-) create mode 100644 frontend/src/lib/components/flows/CopyFirstStepSchema.svelte create mode 100644 frontend/src/lib/components/flows/DynamicInputHelpBox.svelte create mode 100644 frontend/src/lib/components/flows/FlowInputs.svelte create mode 100644 frontend/src/lib/components/flows/FlowModuleHeader.svelte create mode 100644 frontend/src/lib/components/flows/flowStore.ts create mode 100644 frontend/src/lib/components/flows/pickers/FlowScriptPicker.svelte create mode 100644 frontend/src/lib/components/flows/pickers/PickHubScript.svelte create mode 100644 frontend/src/lib/components/flows/pickers/PickScript.svelte diff --git a/frontend/src/app.css b/frontend/src/app.css index 6f0bd1cddb..7b19f3ebf0 100644 --- a/frontend/src/app.css +++ b/frontend/src/app.css @@ -89,6 +89,30 @@ @apply text-sm; } + .default-secondary-button-v2 { + @apply text-gray-900; + @apply bg-white; + @apply border; + @apply border-gray-200; + @apply font-medium; + @apply rounded-lg; + @apply text-sm; + @apply px-5; + @apply py-2.5; + @apply text-center; + @apply inline-flex; + @apply items-center; + } + + .default-secondary-button-v2:focus { + @apply ring-4; + @apply outline-none; + @apply ring-gray-100; + } + .default-secondary-button-v2:hover { + @apply bg-gray-100 + } + .input-error { @apply border-red-500 !important; } diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index e3421e4acc..6808f6f26e 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -2,11 +2,12 @@ import { goto } from '$app/navigation' import { page } from '$app/stores' import { FlowService, ScriptService, type Flow } from '$lib/gen' - import { clearPreviewResults, workspaceStore, hubScripts } from '$lib/stores' + import { clearPreviewResults, hubScripts, workspaceStore } from '$lib/stores' import { sendUserToast } from '$lib/utils' import { onMount } from 'svelte' import SvelteMarkdown from 'svelte-markdown' import FlowEditor from './FlowEditor.svelte' + import { flowStore, initFlow } from './flows/flowStore' import Path from './Path.svelte' import Required from './Required.svelte' import ScriptSchema from './ScriptSchema.svelte' @@ -26,7 +27,7 @@ } async function saveFlow(): Promise { - if (initialPath == '') { + if (initialPath === '') { await FlowService.createFlow({ workspace: $workspaceStore!, requestBody: { @@ -40,7 +41,7 @@ } else { await FlowService.updateFlow({ workspace: $workspaceStore!, - path: initialPath, + path: flow.path, requestBody: { path: flow.path, summary: flow.summary, @@ -58,10 +59,12 @@ goto(`?step=${step}`) } - $: { + flowStore.subscribe((flow: Flow) => { $page.url.searchParams.set('state', btoa(JSON.stringify(flow))) history.replaceState({}, '', $page.url) - } + }) + + $: flow && initFlow(flow) onMount(() => { loadSearchData() @@ -107,12 +110,14 @@ class="default-button px-6 max-h-8" on:click={() => { changeStep(step + 1) - }}>Next + Next + {#if step == 2} - + {/if} {:else} @@ -187,7 +192,7 @@ {:else if step === 2} - + {:else if step === 3} - import type { Schema } from '$lib/common' - import { FlowModuleValue, type Flow } from '$lib/gen' - import { loadSchema } from '$lib/scripts' - import { emptySchema } from '$lib/utils' import { faPlus } from '@fortawesome/free-solid-svg-icons' import Icon from 'svelte-awesome' import FlowPreview from './FlowPreview.svelte' + import CopyFirstStepSchema from './flows/CopyFirstStepSchema.svelte' + import { addModule, flowStore } from './flows/flowStore' import ModuleStep from './ModuleStep.svelte' import SchemaEditor from './SchemaEditor.svelte' - import type SchemaForm from './SchemaForm.svelte' - - export let flow: Flow let args: Record = {} - let schemas: Schema[] = [] - let schemaForms: (SchemaForm | undefined)[] = [] - - function addModule() { - schemaForms.push(undefined) - - let newModule = { - value: { type: FlowModuleValue.type.SCRIPT, path: '' }, - input_transform: {} - } - flow.value.modules = flow.value.modules.concat(newModule) - schemas.push(emptySchema()) - } + $: numberOfSteps = $flowStore?.value.modules.length - 1 -