@cap-js/change-tracking 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/).
6
6
 
7
+ ## Version 1.0.4 - 08.01.24
8
+
9
+ ### Added
10
+
11
+ - Side effect annotation now allows automatic refresh after a custom action caused changes
12
+
13
+ ### Changed
14
+
15
+ - Added a check to disable change tracking for views with a UNION
16
+
17
+ ### Fixed
18
+
19
+ - Handling of associations within change tracked entities
20
+ - Handling of change log when custom actions on child entities are called
21
+
7
22
  ## Version 1.0.3 - 10.11.23
8
23
 
9
24
  ### Added
@@ -37,3 +52,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
37
52
  ### Added
38
53
 
39
54
  - Initial release
55
+
package/cds-plugin.js CHANGED
@@ -1,10 +1,28 @@
1
1
  const cds = require('@sap/cds')
2
2
 
3
3
  const isChangeTracked = (entity) => (
4
- entity['@changelog']
5
- || entity.elements && Object.values(entity.elements).some(e => e['@changelog'])
4
+ (entity['@changelog']
5
+ || entity.elements && Object.values(entity.elements).some(e => e['@changelog'])) && entity.query?.SET?.op !== 'union'
6
6
  )
7
7
 
8
+ // Add the appropriate Side Effects attribute to the custom action
9
+ const addSideEffects = (actions, flag, element) => {
10
+ for (const se of Object.values(actions)) {
11
+ const target = flag ? 'TargetProperties' : 'TargetEntities'
12
+ const sideEffectAttr = se[`@Common.SideEffects.${target}`]
13
+ const property = flag ? 'changes' : { '=': `${element}.changes` }
14
+ if (sideEffectAttr?.length >= 0) {
15
+ sideEffectAttr.findIndex(
16
+ (item) =>
17
+ (item['='] ? item['='] : item) ===
18
+ (property['='] ? property['='] : property)
19
+ ) === -1 && sideEffectAttr.push(property)
20
+ } else {
21
+ se[`@Common.SideEffects.${target}`] = [property]
22
+ }
23
+ }
24
+ }
25
+
8
26
 
9
27
  // Unfold @changelog annotations in loaded model
10
28
  cds.on('loaded', m => {
@@ -23,7 +41,9 @@ cds.on('loaded', m => {
23
41
  for (let e in elms) if (elms[e].key) keys.push(e)
24
42
 
25
43
  // Add association to ChangeView...
26
- const on = [...changes.on]; keys.forEach((k, i) => { i && on.push('||'); on.push({ ref: [k] }) })
44
+ const on = [...changes.on]; keys.forEach((k, i) => { i && on.push('||'); on.push({
45
+ ref: k === 'up_' ? [k,'ID'] : [k] // REVISIT: up_ handling is a dirty hack for now
46
+ })})
27
47
  const assoc = { ...changes, on }
28
48
  const query = entity.projection || entity.query?.SELECT
29
49
  if (query) {
@@ -34,6 +54,31 @@ cds.on('loaded', m => {
34
54
 
35
55
  // Add UI.Facet for Change History List
36
56
  entity['@UI.Facets']?.push(facet)
57
+
58
+ // The changehistory list should be refreshed after the custom action is triggered
59
+ if (entity.actions) {
60
+
61
+ // Update the changehistory list on the current entity when the custom action of the entity is triggered
62
+ if (entity['@UI.Facets']) {
63
+ addSideEffects(entity.actions, true)
64
+ }
65
+
66
+ // When the custom action of the child entity is performed, the change history list of the parent entity is updated
67
+ if (entity.elements) {
68
+ //ToDo: Revisit Breaklook with node.js Expert
69
+ breakLoop: for (const [ele, eleValue] of Object.entries(entity.elements)) {
70
+ const parentEntity = m.definitions[eleValue.target]
71
+ if (parentEntity && parentEntity['@UI.Facets'] && eleValue.type === 'cds.Association') {
72
+ for (const value of Object.values(parentEntity.elements)) {
73
+ if (value.target === name) {
74
+ addSideEffects(entity.actions, false, ele)
75
+ break breakLoop
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
37
82
  }
38
83
  }
39
84
  })
package/lib/change-log.js CHANGED
@@ -359,7 +359,7 @@ async function track_changes (req) {
359
359
  if (!changes) return
360
360
 
361
361
  await _formatChangeLog(changes, req)
362
- if (isComposition && !isDraftEnabled) {
362
+ if (isComposition) {
363
363
  [ target, entityKey ] = await _prepareChangeLogForComposition(target, entityKey, changes, this)
364
364
  }
365
365
  const dbEntity = getDBEntity(target)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/change-tracking",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "CDS plugin providing out-of-the box support for automatic capturing, storing, and viewing of the change records of modeled entities.",
5
5
  "repository": "cap-js/change-tracking",
6
6
  "author": "SAP SE (https://www.sap.com)",