From 698c0deb12fcb671d22b07b385c4e73a887a66e6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Nov 2023 21:06:07 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/renderer/src/stories/JSONSchemaForm.js | 34 ++++++------ src/renderer/src/stories/JSONSchemaInput.js | 52 +++++++++---------- .../pages/guided-mode/data/GuidedMetadata.js | 2 +- 3 files changed, 43 insertions(+), 45 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaForm.js b/src/renderer/src/stories/JSONSchemaForm.js index 8d1c53036..d0efca3cb 100644 --- a/src/renderer/src/stories/JSONSchemaForm.js +++ b/src/renderer/src/stories/JSONSchemaForm.js @@ -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) { @@ -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) => { @@ -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) { @@ -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); @@ -718,8 +716,8 @@ export class JSONSchemaForm extends LitElement { }); } } - } - + } + // Validate Regex Pattern automatically else if (schema.pattern) { const regex = new RegExp(schema.pattern); diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index acc2a4998..cff0ddc9f 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -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"); @@ -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, @@ -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); @@ -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; } } diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js index 7ec768450..5baa85fc9 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js @@ -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,