From 2368da214660ff1835b49b4c2c87256c9bd565cf Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 30 Mar 2023 08:25:00 +0200 Subject: [PATCH] feat: add the ability to edit previous versions --- frontend/src/lib/components/ScriptBuilder.svelte | 11 ++++++----- .../(logged)/scripts/edit/[...hash]/+page.svelte | 3 ++- .../(logged)/scripts/get/[...hash]/+page.svelte | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/frontend/src/lib/components/ScriptBuilder.svelte b/frontend/src/lib/components/ScriptBuilder.svelte index 0d09726f13..6662126b08 100644 --- a/frontend/src/lib/components/ScriptBuilder.svelte +++ b/frontend/src/lib/components/ScriptBuilder.svelte @@ -24,6 +24,7 @@ export let template: 'pgsql' | 'mysql' | 'script' = 'script' export let initialArgs: Record = {} export let lockedLanguage = false + export let topHash: string | undefined = undefined const langs: [string, SupportedLanguage][] = [ ['Typescript', Script.language.DENO], @@ -84,8 +85,7 @@ await inferArgs(script.language, script.content, script.schema) } catch (error) { sendUserToast( - `Impossible to infer the schema. Assuming this is a script without main function`, - true + `The main signature was not parsable. This script is considered to be without main function` ) } @@ -96,7 +96,7 @@ summary: script.summary, description: script.description ?? '', content: script.content, - parent_hash: script.hash != '' ? script.hash : undefined, + parent_hash: script.hash != '' ? topHash ?? script.hash : undefined, schema: script.schema, is_template: script.is_template, language: script.language, @@ -109,9 +109,10 @@ } else { await goto(`/scripts/edit/${newHash}?step=2`) script.hash = newHash + topHash = undefined } } catch (error) { - sendUserToast(`Impossible to save the script: ${error.body || error.message}`, true) + sendUserToast(`Error while saving the script: ${error.body || error.message}`, true) } loadingSave = false } @@ -123,7 +124,7 @@ await inferArgs(script.language, script.content, script.schema) } catch (error) { console.info( - 'Impossible to infer the schema. Assuming this is a script without main function' + 'The main signature was not parsable. This script is considered to be without main function' ) } } diff --git a/frontend/src/routes/(root)/(logged)/scripts/edit/[...hash]/+page.svelte b/frontend/src/routes/(root)/(logged)/scripts/edit/[...hash]/+page.svelte index f1a81e52c1..75f5c8a01e 100644 --- a/frontend/src/routes/(root)/(logged)/scripts/edit/[...hash]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/scripts/edit/[...hash]/+page.svelte @@ -9,6 +9,7 @@ const initialState = $page.url.searchParams.get('state') const initialArgs = decodeArgs($page.url.searchParams.get('args') ?? undefined) + let topHash = $page.url.searchParams.get('topHash') ?? undefined let scriptLoadedFromUrl = initialState != undefined ? decodeState(initialState) : undefined @@ -36,5 +37,5 @@ {#if script} - + {/if} diff --git a/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte b/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte index d243258f40..fb3a7b1205 100644 --- a/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte @@ -214,7 +214,9 @@ {#if !$userStore?.operator}