diff --git a/src/renderer/src/stories/JSONSchemaForm.js b/src/renderer/src/stories/JSONSchemaForm.js index bfd84feed..d1a7967ea 100644 --- a/src/renderer/src/stories/JSONSchemaForm.js +++ b/src/renderer/src/stories/JSONSchemaForm.js @@ -484,18 +484,39 @@ export class JSONSchemaForm extends LitElement { } }; - #getRenderable = (schema = {}, required, path) => { + #getRenderable = (schema = {}, required, path, recursive = false) => { const entries = Object.entries(schema.properties ?? {}); - return entries.filter(([key, value]) => { + const isArrayOfArrays = (arr) => !!arr.find((v) => Array.isArray(v)) + + const flattenRecursedValues = (arr) => { + const newArr = [] + arr.forEach((o) => { + if (isArrayOfArrays(o)) newArr.push(...o) + else newArr.push(o) + }) + + return newArr + } + + const isRenderable = (key, value) => { + if (recursive && value.properties) return this.#getRenderable(value, required[key], [...path, key], true) + + else return [key, value] + } + + const res = entries.map(([key, value]) => { if (!value.properties && key === "definitions") return false; // Skip definitions if (this.ignore.includes(key)) return false; - if (this.showLevelOverride >= path.length) return true; - if (required[key]) return true; - if (this.#getLink([...this.#base, ...path, key])) return true; - if (!this.onlyRequired) return true; + if (this.showLevelOverride >= path.length) return isRenderable(key, value); + if (required[key]) return isRenderable(key, value); + if (this.#getLink([...this.#base, ...path, key])) return isRenderable(key, value); + if (!this.onlyRequired) return isRenderable(key, value); return false; - }); + }).filter(o => !!o) + + return flattenRecursedValues(res); // Flatten on the last pass + }; validateOnChange = () => {}; @@ -735,6 +756,7 @@ export class JSONSchemaForm extends LitElement { if (this.mode === "accordion" && hasMany) { const headerName = header(name); + this.#nestedForms[name] = new JSONSchemaForm({ identifier: this.identifier, schema: info, @@ -770,10 +792,11 @@ export class JSONSchemaForm extends LitElement { base: fullPath, }); - const accordion = new Accordion({ + + const accordion = new Accordion({ sections: { [headerName]: { - subtitle: `${this.#getRenderable(info, required[name], fullPath).length} fields`, + subtitle: `${this.#getRenderable(info, required[name], fullPath, true).length} fields`, content: this.#nestedForms[name], }, },