Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 14, 2023
1 parent a62a8e5 commit 8b4291f
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,36 +487,36 @@ export class JSONSchemaForm extends LitElement {
#getRenderable = (schema = {}, required, path, recursive = false) => {
const entries = Object.entries(schema.properties ?? {});

const isArrayOfArrays = (arr) => !!arr.find((v) => Array.isArray(v))
const isArrayOfArrays = (arr) => !!arr.find((v) => Array.isArray(v));

const flattenRecursedValues = (arr) => {
const newArr = []
const newArr = [];
arr.forEach((o) => {
if (isArrayOfArrays(o)) newArr.push(...o)
else newArr.push(o)
})
if (isArrayOfArrays(o)) newArr.push(...o);
else newArr.push(o);
});

return newArr
}
return newArr;
};

const isRenderable = (key, value) => {
if (recursive && value.properties) return this.#getRenderable(value, required[key], [...path, key], true)

else return [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 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)
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 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 = () => {};
Expand Down Expand Up @@ -756,7 +756,6 @@ export class JSONSchemaForm extends LitElement {
if (this.mode === "accordion" && hasMany) {
const headerName = header(name);


this.#nestedForms[name] = new JSONSchemaForm({
identifier: this.identifier,
schema: info,
Expand Down Expand Up @@ -792,8 +791,7 @@ export class JSONSchemaForm extends LitElement {
base: fullPath,
});


const accordion = new Accordion({
const accordion = new Accordion({
sections: {
[headerName]: {
subtitle: `${this.#getRenderable(info, required[name], fullPath, true).length} fields`,
Expand Down

0 comments on commit 8b4291f

Please sign in to comment.