From b722ac5025b8af412e4b363edb229224f933327a Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Tue, 16 Apr 2024 14:58:54 -0500 Subject: [PATCH 1/4] Defer validation to form change --- .../guided-mode/setup/GuidedNewDatasetInfo.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js b/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js index 7ee16c9bd..696fa78cc 100644 --- a/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js +++ b/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js @@ -9,10 +9,11 @@ import projectGlobalSchema from "../../../../../../../schemas/json/project/globa import { merge } from "../../utils.js"; import { onThrow } from "../../../../errors"; import { header } from "../../../forms/utils"; -import { preprocessMetadataSchema } from "../../../../../../../schemas/base-metadata.schema"; const projectMetadataSchema = merge(projectGlobalSchema, projectGeneralSchema); +const skipError = (message) => (message.includes("requires") && message.includes("name")); + export class GuidedNewDatasetPage extends Page { constructor(...args) { super(...args); @@ -31,6 +32,13 @@ export class GuidedNewDatasetPage extends Page { onNext: async () => { const globalState = this.info.globalState.project; + this.dismiss(); // Dismiss all notifications + + await this.form.validate().catch((error) => { + if (skipError(error.message)) return; + throw error; + }) + // Check validity of project name const name = this.state.name; if (!name) { @@ -39,10 +47,6 @@ export class GuidedNewDatasetPage extends Page { return; } - this.dismiss(); // Dismiss all notifications - - await this.form.validate(); - if (!name) return; // Check if name is already used @@ -86,7 +90,7 @@ export class GuidedNewDatasetPage extends Page { this.form = new JSONSchemaForm({ schema, results: this.state, - // validateEmptyValues: null, + validateEmptyValues: false, dialogOptions: { properties: ["createDirectory"], }, @@ -95,7 +99,10 @@ export class GuidedNewDatasetPage extends Page { }, validateOnChange, onUpdate: () => (this.unsavedUpdates = true), - onThrow, + onThrow: function (message) { + if (skipError(message)) return; + onThrow(message); + } }); return this.form; From 2a40b38440b5ec1c7cdbea37ad9f1d4882d4c497 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Apr 2024 19:59:32 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js b/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js index 696fa78cc..3f96e1bb9 100644 --- a/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js +++ b/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js @@ -12,7 +12,7 @@ import { header } from "../../../forms/utils"; const projectMetadataSchema = merge(projectGlobalSchema, projectGeneralSchema); -const skipError = (message) => (message.includes("requires") && message.includes("name")); +const skipError = (message) => message.includes("requires") && message.includes("name"); export class GuidedNewDatasetPage extends Page { constructor(...args) { @@ -37,7 +37,7 @@ export class GuidedNewDatasetPage extends Page { await this.form.validate().catch((error) => { if (skipError(error.message)) return; throw error; - }) + }); // Check validity of project name const name = this.state.name; @@ -102,7 +102,7 @@ export class GuidedNewDatasetPage extends Page { onThrow: function (message) { if (skipError(message)) return; onThrow(message); - } + }, }); return this.form; From 4c304443f575f8a64008956d2a229111b3000960 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Tue, 16 Apr 2024 17:22:00 -0500 Subject: [PATCH 3/4] Clear name error faster and when the user changes the field --- .../pages/guided-mode/setup/GuidedNewDatasetInfo.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js b/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js index 3f96e1bb9..5f9f80fcf 100644 --- a/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js +++ b/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js @@ -43,7 +43,7 @@ export class GuidedNewDatasetPage extends Page { const name = this.state.name; if (!name) { if (this.#nameNotification) this.dismiss(this.#nameNotification); // Dismiss previous custom notification - this.#nameNotification = this.notify("Please enter a project name.", "error"); + this.#nameNotification = this.notify("Please enter a project name.", "error", 3000); return; } @@ -97,7 +97,12 @@ export class GuidedNewDatasetPage extends Page { onOverride: (name) => { this.notify(`${header(name)} has been overridden with a global value.`, "warning", 3000); }, - validateOnChange, + validateOnChange: async (...args) => { + const results = await validateOnChange.call(this.form, ...args) + if (!results && args[0] === "name") this.#nameNotification && this.dismiss(this.#nameNotification); + return results + + }, onUpdate: () => (this.unsavedUpdates = true), onThrow: function (message) { if (skipError(message)) return; From c8e825195912ac85b080bb01e0bcac2be49fcc29 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Apr 2024 22:22:20 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js b/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js index 5f9f80fcf..71c060fa7 100644 --- a/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js +++ b/src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js @@ -98,10 +98,9 @@ export class GuidedNewDatasetPage extends Page { this.notify(`${header(name)} has been overridden with a global value.`, "warning", 3000); }, validateOnChange: async (...args) => { - const results = await validateOnChange.call(this.form, ...args) + const results = await validateOnChange.call(this.form, ...args); if (!results && args[0] === "name") this.#nameNotification && this.dismiss(this.#nameNotification); - return results - + return results; }, onUpdate: () => (this.unsavedUpdates = true), onThrow: function (message) {