diff --git a/src/renderer/src/stories/FileSystemSelector.js b/src/renderer/src/stories/FileSystemSelector.js index df79bc57f..fc21050a9 100644 --- a/src/renderer/src/stories/FileSystemSelector.js +++ b/src/renderer/src/stories/FileSystemSelector.js @@ -188,11 +188,7 @@ export class FilesystemSelector extends LitElement { isUpdated = resolved !== this.value; } - if (isUpdated) { - this.value = resolved; - this.#handleFiles(this.value); // Notify of the change to the separators - return; - } + if (isUpdated) this.#handleFiles(resolved); // Notify of the change to the separators const resolvedValueDisplay = isArray ? len > 1 diff --git a/src/renderer/src/stories/JSONSchemaForm.js b/src/renderer/src/stories/JSONSchemaForm.js index e1902a2a3..f8c82241a 100644 --- a/src/renderer/src/stories/JSONSchemaForm.js +++ b/src/renderer/src/stories/JSONSchemaForm.js @@ -178,7 +178,7 @@ export class JSONSchemaForm extends LitElement { this.identifier = props.identifier; this.mode = props.mode ?? "default"; this.schema = props.schema ?? {}; - this.results = props.results ?? {}; + this.results = (props.base ? structuredClone(props.results) : props.results) ?? {}; // Deep clone results in nested forms this.globals = props.globals ?? {}; this.ignore = props.ignore ?? []; @@ -254,10 +254,10 @@ export class JSONSchemaForm extends LitElement { // NOTE: Forms with nested forms will handle their own state updates if (!value) { - if (fullPath.length === 1) delete resultParent[name]; + delete resultParent[name]; delete resolvedParent[name]; } else { - if (fullPath.length === 1) resultParent[name] = value; + resultParent[name] = value; resolvedParent[name] = value; } @@ -297,9 +297,9 @@ export class JSONSchemaForm extends LitElement { throw new Error(message); }; - validate = async () => { + validate = async (resolved) => { // Check if any required inputs are missing - const invalidInputs = await this.#validateRequirements(); // get missing required paths + const invalidInputs = await this.#validateRequirements(resolved); // get missing required paths const isValid = !invalidInputs.length; // Print out a detailed error message if any inputs are missing @@ -316,9 +316,9 @@ export class JSONSchemaForm extends LitElement { if (message) this.throw(message); - for (let key in this.#nestedForms) await this.#nestedForms[key].validate(); // Validate nested forms too + for (let key in this.#nestedForms) await this.#nestedForms[key].validate(resolved ? resolved[key] : undefined); // Validate nested forms too try { - for (let key in this.tables) await this.tables[key].validate(); // Validate nested tables too + for (let key in this.tables) await this.tables[key].validate(resolved ? resolved[key] : undefined); // Validate nested tables too } catch (e) { this.throw(e.message); } diff --git a/src/renderer/src/stories/pages/Page.js b/src/renderer/src/stories/pages/Page.js index 49b22071b..1e0fffcef 100644 --- a/src/renderer/src/stories/pages/Page.js +++ b/src/renderer/src/stories/pages/Page.js @@ -64,7 +64,12 @@ export class Page extends LitElement { this.beforeTransition(); // Otherwise note unsaved updates if present - if (this.unsavedUpdates || ("states" in this.info && !this.info.states.saved)) { + if ( + this.unsavedUpdates || + ("states" in this.info && + transition === 1 && // Only ensure save for standard forward progression + !this.info.states.saved) + ) { if (transition === 1) await this.save(); // Save before a single forward transition else { Swal.fire({ diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js index eacd86b3a..dd9c9f872 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js @@ -1,5 +1,3 @@ -import { html } from "lit"; - import Swal from "sweetalert2"; import { isStorybook } from "../../../../dependencies/globals.js"; import { JSONSchemaForm } from "../../../JSONSchemaForm.js"; diff --git a/tests/metadata.test.ts b/tests/metadata.test.ts index 2d1292778..5932395d9 100644 --- a/tests/metadata.test.ts +++ b/tests/metadata.test.ts @@ -136,7 +136,6 @@ test('inter-table updates are triggered', async () => { test('changes are resolved correctly', async () => { const results = {} - const schema = { properties: { v0: { @@ -148,11 +147,16 @@ test('changes are resolved correctly', async () => { l2: { type: "object", properties: { - v2: { - type: 'string' - } + l3: { + type: "object", + properties: { + v2: { + type: 'string' + } + }, + required: ['v2'] + }, }, - required: ['v2'] }, v1: { type: 'string' @@ -181,13 +185,13 @@ test('changes are resolved correctly', async () => { const input1 = form.getInput(['v0']) const input2 = form.getInput(['l1', 'v1']) - const input3 = form.getInput(['l1', 'l2', 'v2']) + const input3 = form.getInput(['l1', 'l2', 'l3', 'v2']) input1.updateData('test') input2.updateData('test') input3.updateData('test') // Validate that the new structure is correct - await form.validate().then(res => errors = false).catch(e => errors = true) + await form.validate(form.results).then(res => errors = false).catch(e => errors = true) expect(errors).toBe(false) // Is valid })