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..71c060fa7 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,18 +32,21 @@ 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) { 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; } - this.dismiss(); // Dismiss all notifications - - await this.form.validate(); - if (!name) return; // Check if name is already used @@ -86,16 +90,23 @@ export class GuidedNewDatasetPage extends Page { this.form = new JSONSchemaForm({ schema, results: this.state, - // validateEmptyValues: null, + validateEmptyValues: false, dialogOptions: { properties: ["createDirectory"], }, 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, + onThrow: function (message) { + if (skipError(message)) return; + onThrow(message); + }, }); return this.form;