Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit updates to user interaction on tables #757

Merged
merged 7 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,12 +1417,18 @@ 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))
);
return isRendered;
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;
});
return this.#resolving;
}

render() {
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/stories/SimpleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
});
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/stories/pages/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
},
};

Expand Down Expand Up @@ -323,9 +318,7 @@ export class GuidedMetadataPage extends ManagedPage {
this.#checkAllLoaded();
},

onUpdate: () => {
this.unsavedUpdates = "conversions";
},
onUpdate: () => (this.unsavedUpdates = "conversions"),

validateOnChange,
onlyRequired: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/stories/table/Cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/src/stories/table/cells/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
})

Expand Down Expand Up @@ -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()
}
Expand Down
Loading