feat: add the ability to edit previous versions

This commit is contained in:
Ruben Fiszel
2023-03-30 08:25:00 +02:00
parent 7fc97e274e
commit 2368da2146
3 changed files with 11 additions and 7 deletions
@@ -24,6 +24,7 @@
export let template: 'pgsql' | 'mysql' | 'script' = 'script'
export let initialArgs: Record<string, any> = {}
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'
)
}
}
@@ -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 @@
</script>
{#if script}
<ScriptBuilder {initialPath} {script} {initialArgs} />
<ScriptBuilder bind:topHash {initialPath} {script} {initialArgs} />
{/if}
@@ -214,7 +214,9 @@
</Button>
{#if !$userStore?.operator}
<Button
href={`/scripts/edit/${script.hash}?step=2&args=${encodeState(args)}`}
href={`/scripts/edit/${script.hash}?step=2&args=${encodeState(args)}${
topHash ? '&topHash=' + topHash : ''
}`}
color="blue"
size="md"
startIcon={{ icon: faEdit }}