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

In the unmanaged case, unmanipulated data also generates a changelog. #79

Open
Sv7enNowitzki opened this issue Mar 22, 2024 · 0 comments

Comments

@Sv7enNowitzki
Copy link
Collaborator

Sv7enNowitzki commented Mar 22, 2024

Hi,

Here's the situation in incidents-app:

Model:
image

Annotation:

annotate ProcessorService.Incidents with @changelog: [title] {
  conversation @changelog: [conversation.message];
}

As we know, conversation is a inline composition of child entity, This is an unmanaged case. If we want to enable managed for inline composition of child entity, It can be set up as shown below:
image

Above is the background information, then the problem is in the following figure, when we go to an incident page, we will find that there is already a current conversation, so we create a new conversation:
image

And click 'Save' button, you can see that the change history generates two changelogs, but we see that there is an additional changelog generated, which we don't need because we haven't done anything with the original conversation:
image

When we enable aspect managed, generate changelog normally:
image

The reason is:

In req.diff(), the data is logged regardless of whether that data has been manipulated or not, so for the managed case, change-tracking will have a place for logic to filter out data that hasn't been manipulated, because for change-tracking, if it hasn't been manipulated, it shouldn't be logged:

https://github.com/cap-js/change-tracking/blob/main/lib/change-log.js#L189

  // Since req.diff() will record the managed data, change history will filter those logs only be changed managed data
  const managedAttrs = ["modifiedAt", "modifiedBy"]
  if (curChange.modification === "update") {
    const rowOldAttrs = Object.keys(childNodeChange._old)
    const diffAttrs = rowOldAttrs.filter((attr) => managedAttrs.indexOf(attr) === -1)
    if (!diffAttrs.length) {
      return
    }
  }

But for the unmanaged case, the unmanipulated data has no _op in req.diff(), so by the time we get to the logic above, the value of curChange.modification is undefined, so it skips the filtering and is added directly to the changelog, so here's the solution:
image

If you have time, please take a look at this scenario.

Best Regards,
Wenjun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant