fix(frontend): Fix frontend script (#1476)

* fix(frontend): fix frontend script intendation

* feat(frontend): wip

* feat(frontend): fix reload all

* feat(frontend): add missing donePromise call

* feat(frontend): move donePromise in setResult

* feat(frontend): revert refresh
This commit is contained in:
Faton Ramadani
2023-04-25 15:46:45 +02:00
committed by GitHub
parent 3b36277757
commit ae3ef61e2c
6 changed files with 27 additions and 15 deletions

View File

@@ -74,6 +74,7 @@
loading = false
rejectCb(new Error('Canceled'))
}
return p as CancelablePromise<void>
}
@@ -350,6 +351,8 @@
delete $errorByComponent[previousJobId]
$errorByComponent = $errorByComponent
}
donePromise?.()
}
function handleInputClick(e: CustomEvent) {
@@ -389,7 +392,6 @@
if (startedAt > lastStartedAt) {
lastStartedAt = startedAt
setResult(e.detail.result)
donePromise?.()
}
}
loading = false

View File

@@ -46,17 +46,21 @@
isFirstLoad = true
}
loading = true
Promise.all(
Object.keys($runnableComponents).map((id) => {
const promises = Object.keys($runnableComponents)
.map((id) => {
if (
!$runnableComponents?.[id]?.autoRefresh &&
(!isFirstLoad || !$runnableComponents?.[id]?.refreshOnStart)
) {
return
}
return $runnableComponents?.[id]?.cb?.()
})
).finally(() => {
.filter(Boolean)
Promise.all(promises).finally(() => {
loading = false
})
}

View File

@@ -217,15 +217,15 @@
on:click={() => {
const newInlineScript = {
content: `// read outputs and ctx
console.log(ctx.email)
// access a global state store
if (!state.foo) { state.foo = 0 }
state.foo += 1
// you can also navigate (goto), recompute a script (recompute), or set a tab (setTab)
return state.foo`,
console.log(ctx.email)
// access a global state store
if (!state.foo) { state.foo = 0 }
state.foo += 1
// you can also navigate (goto), recompute a script (recompute), or set a tab (setTab)
return state.foo`,
language: 'frontend',
path: 'frontend script',
schema: undefined

View File

@@ -35,5 +35,10 @@
{onLoad}
{recomputeOnInputChanged}
id={$selectedComponent?.[0]}
shouldHideAddDependencyButton={[
'buttoncomponent',
'formcomponent',
'formbuttoncomponent'
].includes(appComponent.type)}
{onClick}
/>

View File

@@ -12,6 +12,7 @@
export let onLoad: boolean = false
export let id: string | undefined = undefined
export let recomputeOnInputChanged: boolean = false
export let shouldHideAddDependencyButton: boolean = false
const colors = {
green: 'text-green-800 border-green-600 bg-green-100',
@@ -133,7 +134,7 @@
<div class="w-full">
<div class="flex justify-between items-center">
<div class="text-xs font-semibold text-slate-800 mb-1">Change on values</div>
{#if inlineScript?.language === 'frontend'}
{#if inlineScript?.language === 'frontend' && !shouldHideAddDependencyButton}
<Button
variant="border"
size="xs"

View File

@@ -139,7 +139,7 @@ export async function main(
export const FETCH_INIT_CODE = `export async function main(
url: string | undefined,
method: string = 'GET',
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' = 'GET',
body: Object = {},
headers: Record<string, string> = {}
): Promise<Response | null> {