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 Nov 2, 2023
1 parent 16ce013 commit 698c0de
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 45 deletions.
34 changes: 16 additions & 18 deletions src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,22 +350,24 @@ export class JSONSchemaForm extends LitElement {
const requiredButNotSpecified = await this.#validateRequirements(resolved); // get missing required paths
const isValid = !requiredButNotSpecified.length;


const flaggedInputs = this.shadowRoot ? this.shadowRoot.querySelectorAll(".invalid") : [];

const allErrors = Array.from(flaggedInputs).map(el => {
return Array.from(el.nextElementSibling.children).map(li => li.message)
}).flat()
const allErrors = Array.from(flaggedInputs)
.map((el) => {
return Array.from(el.nextElementSibling.children).map((li) => li.message);
})
.flat();

const nMissingRequired = allErrors.reduce((acc, curr) => {
return acc += curr.includes(this.#isARequiredPropertyString) ? 1 : 0
}, 0)
console.log(allErrors)
return (acc += curr.includes(this.#isARequiredPropertyString) ? 1 : 0);
}, 0);

console.log(allErrors);

// Print out a detailed error message if any inputs are missing
let message = '';
if (!isValid && nMissingRequired === allErrors.length) message = `${nMissingRequired} required inputs are not defined.`
let message = "";
if (!isValid && nMissingRequired === allErrors.length)
message = `${nMissingRequired} required inputs are not defined.`;

// Check if all inputs are valid
if (flaggedInputs.length) {
Expand Down Expand Up @@ -647,7 +649,7 @@ export class JSONSchemaForm extends LitElement {
return value === undefined || value === "";
}

#isARequiredPropertyString = `is a required property`
#isARequiredPropertyString = `is a required property`;

// Assume this is going to return as a Promise—even if the change function isn't returning one
triggerValidation = async (name, path = [], checkLinks = true) => {
Expand All @@ -674,10 +676,8 @@ export class JSONSchemaForm extends LitElement {

const info = Array.isArray(valid) ? valid?.filter((info) => info.type === "info") : [];


const isUndefined = this.isUndefined(parent[name]);
const schema = this.getSchema(localPath);


const hasLinks = this.#getLink(externalPath);
if (hasLinks) {
Expand All @@ -694,12 +694,10 @@ export class JSONSchemaForm extends LitElement {
}, externalPath);
}
}
}
}

if (!errors.length) {

if (isUndefined) {

// Throw at least a basic warning if a non-linked property is required and missing
if (!hasLinks && isRequired) {
const schema = this.getSchema(localPath);
Expand All @@ -718,8 +716,8 @@ export class JSONSchemaForm extends LitElement {
});
}
}
}
}

// Validate Regex Pattern automatically
else if (schema.pattern) {
const regex = new RegExp(schema.pattern);
Expand Down
52 changes: 26 additions & 26 deletions src/renderer/src/stories/JSONSchemaInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ export class JSONSchemaInput extends LitElement {
}
},
onThrow: (...args) => this.#onThrow(...args),
}
};

table = this.createTable(name, tableMetadata, fullPath) // Try creating table. Otherwise use nested form
if (table) return this.form.tables[name] = (table === true) ? new BasicTable(tableMetadata) : table
table = this.createTable(name, tableMetadata, fullPath); // Try creating table. Otherwise use nested form
if (table) return (this.form.tables[name] = table === true ? new BasicTable(tableMetadata) : table);
}

const headerText = document.createElement("span");
Expand All @@ -268,17 +268,15 @@ export class JSONSchemaInput extends LitElement {

let tempParent = {};

const itemInfo = info.items
const formProperties = itemInfo.properties


let element
const itemInfo = info.items;
const formProperties = itemInfo.properties;

let element;

addButton.addEventListener("click", () => {
if (modal) modal.remove();

tempParent[name] = {} // Wipe previous values
tempParent[name] = {}; // Wipe previous values

modal = new Modal({
header: headerText,
Expand All @@ -288,17 +286,19 @@ export class JSONSchemaInput extends LitElement {
const div = document.createElement("div");
div.style.padding = "25px";

element = formProperties ? new JSONSchemaForm({
schema: itemInfo,
results: tempParent[name],
onThrow: this.#onThrow
}) : new JSONSchemaInput({
info: itemInfo,
validateOnChange: false,
path: this.path,
form: this.form,
onUpdate: (value) => (tempParent[name] = value),
})
element = formProperties
? new JSONSchemaForm({
schema: itemInfo,
results: tempParent[name],
onThrow: this.#onThrow,
})
: new JSONSchemaInput({
info: itemInfo,
validateOnChange: false,
path: this.path,
form: this.form,
onUpdate: (value) => (tempParent[name] = value),
});

div.append(element);

Expand Down Expand Up @@ -326,16 +326,16 @@ export class JSONSchemaInput extends LitElement {
primary: true,
});

submitButton.addEventListener("click", async () => {

submitButton.addEventListener("click", async () => {
let value = tempParent[name];

if (formProperties) {
await element.validate()
await element.validate();
if (itemInfo?.format) {
let newValue = itemInfo?.format
for (let key in formProperties) newValue = newValue.replace(`{${key}}`, value[key] ?? '').trim()
value = newValue
let newValue = itemInfo?.format;
for (let key in formProperties)
newValue = newValue.replace(`{${key}}`, value[key] ?? "").trim();
value = newValue;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class GuidedMetadataPage extends ManagedPage {
createTable: (name, metadata, path) => {
// NOTE: Handsontable will occasionally have a context menu that doesn't actually trigger any behaviors
if (name !== "Electrodes") return new SimpleTable(metadata);
else return true // All other tables are handled by the default behavior
else return true; // All other tables are handled by the default behavior
// if (name !== "ElectrodeColumns" && name !== "Electrodes") return new Table(metadata);
},
onThrow,
Expand Down

0 comments on commit 698c0de

Please sign in to comment.