fix(frontend): preserve customise arguments

This commit is contained in:
Ruben Fiszel
2023-05-04 15:39:10 +02:00
parent 32f04c7968
commit b4867f12bb
7 changed files with 23 additions and 12 deletions
+1 -1
View File
@@ -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[]
+13 -3
View File
@@ -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)} />
+5 -4
View File
@@ -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
}
+1 -1
View File
@@ -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
}