Re: [INFO REQ] [Typescript] > Store > Changes not populated
Posted: Tue Nov 08, 2022 5:18 pm
by dev team
As an additional note, we are using Model.set() within an iteration. This sometimes will display the changes from the Store, but there doesn't seem to be any reproduction steps consistently.
for (const jobKey in job) {
record.set(jobKey, job[jobKey]);
}
Re: [INFO REQ] [Typescript] > Store > Changes not populated
Posted: Wed Nov 09, 2022 7:09 am
by alex.l
Hi dev team,
Unfortunately, the code you shared doesn't look relevant to me. We need more context here.
Try to set data like this:
record.set(job);
And see if it fix the problems you experienced.
Re: [INFO REQ] [Typescript] > Store > Changes not populated
Posted: Wed Nov 09, 2022 9:16 am
by dev team
Hi Alex.
As we are using a custom editor created using StencilJS, we take the Model from the store for a particular row, hydrate the forms and present.
From here the user can edit any data and click save. This will evaluate what data has been changed from the originalData to the new Model and emit the diff.
A separate StencilJS component will listen for the saveClicked event and essentially flow through to where we will be checking if the grid.store.changes has any values. This is where this issue lies. It seems to be inconsistent to whether we will have changes hydrated at this time. If not then record.revertChanges(); is called rolling back user input.
private get changes(): { added: JobModel[], modified: JobModel[], removed: JobModel[] } {
return this.store.changes as { added: JobModel[], modified: JobModel[], removed: JobModel[] };
}
private async handleJobPatchCreation(record: JobModel) {
const changes = this.changes;
if (changes) {
if (changes?.modified) {
const modified: Partial<Job>[] = changes.modified.map((j: JobModel) => {
return j.modifications;
});
// Generate the jsonPatchDocument
const jobUpdate: JobPatch[] = jobUpdated(this.jobs, modified);
//Emit an event with the payload.
this.jobUpdated.emit(jobUpdate);
}
if (changes?.added) {
// Generate the jsonPatchDocument
const jobAdd: JobPatch[] = jobAdded(changes.added);
// Filter out the operations to just be the Job add and not any of the Bryntum metadata
jobAdd[0].operations = jobAdd[0].operations.filter(addOperation => addOperation.path === '/_data');
this.jobAdded.emit(jobAdd);
}
this.store.commit();
}
else {
record.revertChanges();
}
}
Re: [INFO REQ] [Typescript] > Store > Changes not populated