mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-21 08:02:26 +00:00
fix(frontend): preserve customise arguments
This commit is contained in:
@@ -8,7 +8,7 @@ export type SupportedLanguage = Script.language
|
||||
|
||||
export interface SchemaProperty {
|
||||
type: string | undefined
|
||||
description: string
|
||||
description?: string
|
||||
pattern?: string
|
||||
default?: any
|
||||
enum?: string[]
|
||||
|
||||
@@ -506,9 +506,19 @@
|
||||
|
||||
let widgets: HTMLElement | undefined = document.getElementById('monaco-widgets-root') ?? undefined
|
||||
async function loadMonaco() {
|
||||
const model = meditor.createModel(code, lang, mUri.parse(uri))
|
||||
|
||||
let model: meditor.ITextModel
|
||||
try {
|
||||
model = meditor.createModel(code, lang, mUri.parse(uri))
|
||||
} catch (err) {
|
||||
console.log('model already existed', err)
|
||||
const nmodel = meditor.getModel(mUri.parse(uri))
|
||||
if (!nmodel) {
|
||||
throw err
|
||||
}
|
||||
model = nmodel
|
||||
}
|
||||
model.updateOptions(lang == 'python' ? { tabSize: 4, insertSpaces: true } : updateOptions)
|
||||
|
||||
editor = meditor.create(divEl as HTMLDivElement, {
|
||||
...editorConfig(model, code, lang, automaticLayout, fixedOverflowWidgets),
|
||||
overflowWidgetsDomNode: widgets,
|
||||
@@ -555,7 +565,7 @@
|
||||
return () => {
|
||||
try {
|
||||
closeWebsockets()
|
||||
model.dispose()
|
||||
model?.dispose()
|
||||
editor && editor.dispose()
|
||||
} catch (err) {
|
||||
console.log('error disposing editor', err)
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
return {
|
||||
name,
|
||||
selectedType: schema.type,
|
||||
description: schema.description,
|
||||
description: schema.description ?? '',
|
||||
pattern: schema.pattern,
|
||||
default: schema.default,
|
||||
contentEncoding: schema.contentEncoding,
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
schema = schema ?? emptySchema()
|
||||
let isDefault: string[] = []
|
||||
Object.entries(args).forEach(([k, v]) => {
|
||||
if (schema.properties[k].default == v) {
|
||||
if (schema.properties?.[k]?.default == v) {
|
||||
isDefault.push(k)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<svelte:fragment slot="content">
|
||||
<TabContent value="ui">
|
||||
<div class="mt-4" />
|
||||
<SchemaForm {schema} editableSchema={true} />
|
||||
<SchemaForm bind:schema editableSchema={true} />
|
||||
</TabContent>
|
||||
<TabContent value="jsonschema">
|
||||
<Highlight language={json} code={JSON.stringify(schema, null, 4)} />
|
||||
|
||||
@@ -44,7 +44,8 @@ export async function inferArgs(
|
||||
}
|
||||
|
||||
schema.required = []
|
||||
const oldProperties = Object.assign({}, schema.properties)
|
||||
const oldProperties = JSON.parse(JSON.stringify(schema.properties))
|
||||
|
||||
schema.properties = {}
|
||||
|
||||
for (const arg of inferedSchema.args) {
|
||||
@@ -54,7 +55,9 @@ export async function inferArgs(
|
||||
schema.properties[arg.name] = oldProperties[arg.name]
|
||||
}
|
||||
schema.properties[arg.name] = sortObject(schema.properties[arg.name])
|
||||
|
||||
argSigToJsonSchemaType(arg.typ, schema.properties[arg.name])
|
||||
|
||||
schema.properties[arg.name].default = arg.default
|
||||
|
||||
if (!arg.has_default && !schema.required.includes(arg.name)) {
|
||||
@@ -72,7 +75,7 @@ function argSigToJsonSchemaType(
|
||||
| { object: { key: string; typ: any }[] },
|
||||
oldS: SchemaProperty
|
||||
): void {
|
||||
const newS: SchemaProperty = { type: '', description: '' }
|
||||
const newS: SchemaProperty = { type: '' }
|
||||
if (t === 'int') {
|
||||
newS.type = 'integer'
|
||||
} else if (t === 'float') {
|
||||
@@ -134,9 +137,7 @@ function argSigToJsonSchemaType(
|
||||
}
|
||||
}
|
||||
|
||||
let oldDescription = oldS.description
|
||||
Object.assign(oldS, newS)
|
||||
oldS.description = oldDescription
|
||||
if (oldS.format?.startsWith('resource-') && newS.type != 'object') {
|
||||
oldS.format = undefined
|
||||
}
|
||||
|
||||
@@ -751,7 +751,7 @@ export function sortObject<T>(o: T & object): T {
|
||||
return Object.keys(o)
|
||||
.sort()
|
||||
.reduce((obj, key) => {
|
||||
obj[key] = obj[key]
|
||||
obj[key] = o[key]
|
||||
return obj
|
||||
}, {}) as T
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user