@cap-js/change-tracking
Advanced tools
Comparing version 1.0.3 to 1.0.4
const cds = require('@sap/cds') | ||
const isChangeTracked = (entity) => ( | ||
entity['@changelog'] | ||
|| entity.elements && Object.values(entity.elements).some(e => e['@changelog']) | ||
(entity['@changelog'] | ||
|| entity.elements && Object.values(entity.elements).some(e => e['@changelog'])) && entity.query?.SET?.op !== 'union' | ||
) | ||
// Add the appropriate Side Effects attribute to the custom action | ||
const addSideEffects = (actions, flag, element) => { | ||
for (const se of Object.values(actions)) { | ||
const target = flag ? 'TargetProperties' : 'TargetEntities' | ||
const sideEffectAttr = se[`@Common.SideEffects.${target}`] | ||
const property = flag ? 'changes' : { '=': `${element}.changes` } | ||
if (sideEffectAttr?.length >= 0) { | ||
sideEffectAttr.findIndex( | ||
(item) => | ||
(item['='] ? item['='] : item) === | ||
(property['='] ? property['='] : property) | ||
) === -1 && sideEffectAttr.push(property) | ||
} else { | ||
se[`@Common.SideEffects.${target}`] = [property] | ||
} | ||
} | ||
} | ||
// Unfold @changelog annotations in loaded model | ||
@@ -26,3 +44,5 @@ cds.on('loaded', m => { | ||
// Add association to ChangeView... | ||
const on = [...changes.on]; keys.forEach((k, i) => { i && on.push('||'); on.push({ ref: [k] }) }) | ||
const on = [...changes.on]; keys.forEach((k, i) => { i && on.push('||'); on.push({ | ||
ref: k === 'up_' ? [k,'ID'] : [k] // REVISIT: up_ handling is a dirty hack for now | ||
})}) | ||
const assoc = { ...changes, on } | ||
@@ -38,2 +58,27 @@ const query = entity.projection || entity.query?.SELECT | ||
entity['@UI.Facets']?.push(facet) | ||
// The changehistory list should be refreshed after the custom action is triggered | ||
if (entity.actions) { | ||
// Update the changehistory list on the current entity when the custom action of the entity is triggered | ||
if (entity['@UI.Facets']) { | ||
addSideEffects(entity.actions, true) | ||
} | ||
// When the custom action of the child entity is performed, the change history list of the parent entity is updated | ||
if (entity.elements) { | ||
//ToDo: Revisit Breaklook with node.js Expert | ||
breakLoop: for (const [ele, eleValue] of Object.entries(entity.elements)) { | ||
const parentEntity = m.definitions[eleValue.target] | ||
if (parentEntity && parentEntity['@UI.Facets'] && eleValue.type === 'cds.Association') { | ||
for (const value of Object.values(parentEntity.elements)) { | ||
if (value.target === name) { | ||
addSideEffects(entity.actions, false, ele) | ||
break breakLoop | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
@@ -40,0 +85,0 @@ } |
@@ -7,2 +7,17 @@ # Change Log | ||
## Version 1.0.4 - 08.01.24 | ||
### Added | ||
- Side effect annotation now allows automatic refresh after a custom action caused changes | ||
### Changed | ||
- Added a check to disable change tracking for views with a UNION | ||
### Fixed | ||
- Handling of associations within change tracked entities | ||
- Handling of change log when custom actions on child entities are called | ||
## Version 1.0.3 - 10.11.23 | ||
@@ -41,1 +56,2 @@ | ||
- Initial release | ||
@@ -362,3 +362,3 @@ const cds = require("@sap/cds") | ||
await _formatChangeLog(changes, req) | ||
if (isComposition && !isDraftEnabled) { | ||
if (isComposition) { | ||
[ target, entityKey ] = await _prepareChangeLogForComposition(target, entityKey, changes, this) | ||
@@ -365,0 +365,0 @@ } |
{ | ||
"name": "@cap-js/change-tracking", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "CDS plugin providing out-of-the box support for automatic capturing, storing, and viewing of the change records of modeled entities.", | ||
@@ -5,0 +5,0 @@ "repository": "cap-js/change-tracking", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73544
723