From f4859c6fdf63b5012de9dd5e9595a9ba877ce2d5 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Wed, 17 Apr 2024 14:12:17 -0500 Subject: [PATCH 1/4] Limit updates to user interaction on tables --- src/renderer/src/stories/JSONSchemaForm.js | 16 ++++++++++++---- src/renderer/src/stories/SimpleTable.js | 3 ++- src/renderer/src/stories/pages/Page.js | 1 + .../pages/guided-mode/data/GuidedMetadata.js | 11 ++--------- .../guided-mode/options/GuidedStubPreview.js | 5 +---- src/renderer/src/stories/table/Cell.ts | 2 +- src/renderer/src/stories/table/cells/base.ts | 3 +-- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaForm.js b/src/renderer/src/stories/JSONSchemaForm.js index 1af50a2d0..7dd5d8d21 100644 --- a/src/renderer/src/stories/JSONSchemaForm.js +++ b/src/renderer/src/stories/JSONSchemaForm.js @@ -443,7 +443,7 @@ export class JSONSchemaForm extends LitElement { isObject(value) && isObject(resolvedParent) ? merge(value, resolvedParent[name]) : value; // Merge with existing resolved values } - if (hasUpdate || forceUpdate) this.onUpdate(localPath, value); // Ensure the value has actually changed + if ((hasUpdate || forceUpdate)) this.onUpdate(localPath, value); // Ensure the value has actually changed } #addMessage = (name, message, type) => { @@ -1417,12 +1417,20 @@ export class JSONSchemaForm extends LitElement { this.inputs = {}; } + #resolving // Check if everything is internally rendered get rendered() { - const isRendered = resolve(this.#rendered, () => - Promise.all([...Object.values(this.forms), ...Object.values(this.tables)].map(({ rendered }) => rendered)) + if (this.#resolving) return this.#resolving; + this.#resolving = resolve(this.#rendered, () => { + const promise = Promise.all([...Object.values(this.forms), ...Object.values(this.tables)].map(({ rendered }) => rendered)) + promise.then(() => { + this.#resolving = null; + console.error('DONE', this.base) + }) + return promise + } ); - return isRendered; + return this.#resolving; } render() { diff --git a/src/renderer/src/stories/SimpleTable.js b/src/renderer/src/stories/SimpleTable.js index 2fd49fd85..6d841bbb2 100644 --- a/src/renderer/src/stories/SimpleTable.js +++ b/src/renderer/src/stories/SimpleTable.js @@ -877,7 +877,8 @@ export class SimpleTable extends LitElement { } } - this.#onCellChange(cell); + this.#onCellChange(cell); // Only update data if the value has changed + this.#checkStatus(); // Check status after every validation update }, }); diff --git a/src/renderer/src/stories/pages/Page.js b/src/renderer/src/stories/pages/Page.js index 4eb7f3cc4..f50357b1a 100644 --- a/src/renderer/src/stories/pages/Page.js +++ b/src/renderer/src/stories/pages/Page.js @@ -137,6 +137,7 @@ export class Page extends LitElement { if (desyncedData) { delete desyncedData[key]; if (Object.keys(desyncedData).length === 0) delete this.info.globalState.desyncedData; + await this.save({}, false) } } 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 b690a4e57..174676443 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js @@ -61,7 +61,6 @@ const tableRenderConfig = { }, UnitColumns: function (metadata) { metadata.editable = false; - console.log("Column metadata", metadata); metadata.schema.description = "Update unit information directly on your source data."; return true; @@ -184,12 +183,8 @@ export class GuidedMetadataPage extends ManagedPage { footer = { onNext: async () => { await this.save(); // Save in case the conversion fails - for (let { form } of this.forms) await form.validate(); // Will throw an error in the callback - - await this.convert({ preview: true }); - - return this.to(1); + return this.to(1); // Will trigger preview conversion if necessary }, }; @@ -323,9 +318,7 @@ export class GuidedMetadataPage extends ManagedPage { this.#checkAllLoaded(); }, - onUpdate: () => { - this.unsavedUpdates = "conversions"; - }, + onUpdate: () => (this.unsavedUpdates = "conversions"), validateOnChange, onlyRequired: false, diff --git a/src/renderer/src/stories/pages/guided-mode/options/GuidedStubPreview.js b/src/renderer/src/stories/pages/guided-mode/options/GuidedStubPreview.js index f66900cfc..39635033c 100644 --- a/src/renderer/src/stories/pages/guided-mode/options/GuidedStubPreview.js +++ b/src/renderer/src/stories/pages/guided-mode/options/GuidedStubPreview.js @@ -40,10 +40,7 @@ export class GuidedStubPreviewPage extends Page { next: "Run Conversion", onNext: async () => { await this.save(); // Save in case the conversion fails - - await this.convert(); - - return this.to(1); + return this.to(1); // Will trigger conversion if necessary }, }; diff --git a/src/renderer/src/stories/table/Cell.ts b/src/renderer/src/stories/table/Cell.ts index d554f8a62..414365b52 100644 --- a/src/renderer/src/stories/table/Cell.ts +++ b/src/renderer/src/stories/table/Cell.ts @@ -16,7 +16,7 @@ type ValidationResult = { type ValidationFunction = (value: any) => any | any[] -type OnValidateFunction = (info: ValidationResult) => void +type OnValidateFunction = (info: ValidationResult, changed?: boolean) => void type TableCellProps = { value: string, diff --git a/src/renderer/src/stories/table/cells/base.ts b/src/renderer/src/stories/table/cells/base.ts index 565818de0..cf9dbbe37 100644 --- a/src/renderer/src/stories/table/cells/base.ts +++ b/src/renderer/src/stories/table/cells/base.ts @@ -98,7 +98,7 @@ export class TableCellBase extends LitElement { this.editable = editable this.#editable.addEventListener('input', (ev: InputEvent) => { - this.interacted = true + if (ev.isTrusted) this.interacted = true if (ev.inputType.includes('history')) this.setText(this.#editable.innerText) // Catch undo / redo} }) @@ -160,7 +160,6 @@ export class TableCellBase extends LitElement { document.removeEventListener('click', this.#editableClose) } else { current = this.#editor.value - console.log('Editor value', current) this.interacted = true if (this.#editor && this.#editor.onEditEnd) this.#editor.onEditEnd() } From 6d2157895675cc477be054015306c5088c265b5e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 Apr 2024 19:15:09 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/renderer/src/stories/JSONSchemaForm.js | 17 +++++++++-------- src/renderer/src/stories/pages/Page.js | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaForm.js b/src/renderer/src/stories/JSONSchemaForm.js index 7dd5d8d21..4191d7b50 100644 --- a/src/renderer/src/stories/JSONSchemaForm.js +++ b/src/renderer/src/stories/JSONSchemaForm.js @@ -443,7 +443,7 @@ export class JSONSchemaForm extends LitElement { isObject(value) && isObject(resolvedParent) ? merge(value, resolvedParent[name]) : value; // Merge with existing resolved values } - if ((hasUpdate || forceUpdate)) this.onUpdate(localPath, value); // Ensure the value has actually changed + if (hasUpdate || forceUpdate) this.onUpdate(localPath, value); // Ensure the value has actually changed } #addMessage = (name, message, type) => { @@ -1417,19 +1417,20 @@ export class JSONSchemaForm extends LitElement { this.inputs = {}; } - #resolving + #resolving; // Check if everything is internally rendered get rendered() { if (this.#resolving) return this.#resolving; this.#resolving = resolve(this.#rendered, () => { - const promise = Promise.all([...Object.values(this.forms), ...Object.values(this.tables)].map(({ rendered }) => rendered)) + const promise = Promise.all( + [...Object.values(this.forms), ...Object.values(this.tables)].map(({ rendered }) => rendered) + ); promise.then(() => { this.#resolving = null; - console.error('DONE', this.base) - }) - return promise - } - ); + console.error("DONE", this.base); + }); + return promise; + }); return this.#resolving; } diff --git a/src/renderer/src/stories/pages/Page.js b/src/renderer/src/stories/pages/Page.js index f50357b1a..a8a0767d1 100644 --- a/src/renderer/src/stories/pages/Page.js +++ b/src/renderer/src/stories/pages/Page.js @@ -137,7 +137,7 @@ export class Page extends LitElement { if (desyncedData) { delete desyncedData[key]; if (Object.keys(desyncedData).length === 0) delete this.info.globalState.desyncedData; - await this.save({}, false) + await this.save({}, false); } } From e6b4b1519bfb27e1821d2646a898b7ce35e7f31a Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Wed, 17 Apr 2024 14:15:52 -0500 Subject: [PATCH 3/4] Update JSONSchemaForm.js --- src/renderer/src/stories/JSONSchemaForm.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaForm.js b/src/renderer/src/stories/JSONSchemaForm.js index 7dd5d8d21..ebe7b88ed 100644 --- a/src/renderer/src/stories/JSONSchemaForm.js +++ b/src/renderer/src/stories/JSONSchemaForm.js @@ -1423,10 +1423,7 @@ export class JSONSchemaForm extends LitElement { if (this.#resolving) return this.#resolving; this.#resolving = resolve(this.#rendered, () => { const promise = Promise.all([...Object.values(this.forms), ...Object.values(this.tables)].map(({ rendered }) => rendered)) - promise.then(() => { - this.#resolving = null; - console.error('DONE', this.base) - }) + promise.then(() => this.#resolving = null) return promise } ); From 3e10b9f21da298e08bfb752da5a8274c6eb65c38 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 Apr 2024 19:16:36 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/renderer/src/stories/JSONSchemaForm.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaForm.js b/src/renderer/src/stories/JSONSchemaForm.js index 40b5904fa..86372e0a8 100644 --- a/src/renderer/src/stories/JSONSchemaForm.js +++ b/src/renderer/src/stories/JSONSchemaForm.js @@ -1422,11 +1422,12 @@ export class JSONSchemaForm extends LitElement { get rendered() { if (this.#resolving) return this.#resolving; this.#resolving = resolve(this.#rendered, () => { - const promise = Promise.all([...Object.values(this.forms), ...Object.values(this.tables)].map(({ rendered }) => rendered)) - promise.then(() => this.#resolving = null) - return promise - } - ); + const promise = Promise.all( + [...Object.values(this.forms), ...Object.values(this.tables)].map(({ rendered }) => rendered) + ); + promise.then(() => (this.#resolving = null)); + return promise; + }); return this.#resolving; }