diff --git a/community/resource_types/state.json b/community/resource_types/state.json new file mode 100644 index 0000000000..a05ef1a47f --- /dev/null +++ b/community/resource_types/state.json @@ -0,0 +1,11 @@ +{ + "workspace_id": "starter", + "name": "state", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {}, + "required": [], + "type": "object" + }, + "description": "" +} diff --git a/frontend/src/lib/components/EditorBar.svelte b/frontend/src/lib/components/EditorBar.svelte index 93ab76153e..1de6f99099 100644 --- a/frontend/src/lib/components/EditorBar.svelte +++ b/frontend/src/lib/components/EditorBar.svelte @@ -54,9 +54,7 @@ $: editor && addEditorActions() async function loadVariables() { - return (await VariableService.listVariable({ workspace: $workspaceStore ?? '' })).map((x) => { - return { name: x.path, ...x } - }) + return await VariableService.listVariable({ workspace: $workspaceStore ?? '' }) } async function loadContextualVariables() { @@ -147,13 +145,10 @@ sendUserToast(`${name} inserted at cursor`) }} itemName="Variable" - extraField="name" + extraField="path" loadItems={loadVariables} >
-
- The variable you were looking for does not exist yet? -
+ {#if buttons} +
+ {#each Object.entries(buttons) as [name, button]} + + {/each} +
+ {/if} {/each} @@ -86,7 +116,7 @@ {noItemMessage} {/if}
- + diff --git a/frontend/src/lib/components/ResourceEditor.svelte b/frontend/src/lib/components/ResourceEditor.svelte index 3388612edb..e7878d9517 100644 --- a/frontend/src/lib/components/ResourceEditor.svelte +++ b/frontend/src/lib/components/ResourceEditor.svelte @@ -14,6 +14,7 @@ import ResourceTypePicker from './ResourceTypePicker.svelte' import DrawerContent from './common/drawer/DrawerContent.svelte' import autosize from 'svelte-autosize' + import SimpleEditor from './SimpleEditor.svelte' let path = '' let initialPath = '' @@ -37,6 +38,8 @@ let variableEditor: VariableEditor let drawer: Drawer + let rawCode: string | undefined = undefined + const dispatch = createEventDispatcher() export async function initNew(rt?: string) { @@ -58,8 +61,8 @@ resourceToEdit = await ResourceService.getResource({ workspace: $workspaceStore!, path: p }) description = resourceToEdit!.description ?? '' selectedResourceType = resourceToEdit!.resource_type - await loadResourceType() args = resourceToEdit!.value + await loadResourceType() drawer.openDrawer() } @@ -77,6 +80,14 @@ async function editResource(): Promise { try { if (resourceToEdit) { + if (rawCode != undefined) { + try { + args = JSON.parse(rawCode) + } catch (e) { + sendUserToast("Couldn't parse the content as JSON", true) + return + } + } await ResourceService.updateResource({ workspace: $workspaceStore!, path: resourceToEdit.path, @@ -95,13 +106,18 @@ async function loadResourceType(): Promise { if (selectedResourceType) { - resourceType = await ResourceService.getResourceType({ - workspace: $workspaceStore!, - path: selectedResourceType - }) + try { + resourceType = await ResourceService.getResourceType({ + workspace: $workspaceStore!, + path: selectedResourceType + }) - if (resourceType.schema) { - resourceSchema = resourceType.schema as Schema + if (resourceType.schema) { + resourceSchema = resourceType.schema as Schema + } + } catch (err) { + resourceSchema = undefined + rawCode = JSON.stringify(args, null, 2) } } else { sendUserToast(`ResourceType cannot be undefined.`, true) @@ -194,7 +210,9 @@ {/each} {:else} -
Invalid schema
+
+ +
{/if} {/if} diff --git a/frontend/src/lib/script_helpers.ts b/frontend/src/lib/script_helpers.ts index f4c9341e7e..aaa8dca4d6 100644 --- a/frontend/src/lib/script_helpers.ts +++ b/frontend/src/lib/script_helpers.ts @@ -3,8 +3,10 @@ import type { Script } from "./gen" export const PYTHON_INIT_CODE = `import os import wmill +# You can import any package from PyPI, even if the assistant complains + """ -Use Cmd/Ctrl + S to autoformat the code. +Use Cmd/Ctrl + S to autoformat the code. Reset content in the bar to start from a clean template. The client is used to interact with windmill itself through its standard API. One can explore the methods available through autocompletion of \`wmill.XXX\`. """