Skip to content

Commit 5fd8314

Browse files
fix: When a custom action is triggered, the changehistory list needs to be refreshed manually. (#57)
When the custom action is triggered, the generated changelog will not be shown in the UI, you need to refresh the page to see the new changelog, so submit this PR to fix it. --------- Co-authored-by: I560824 <[email protected]> Co-authored-by: Nick Josipovic <[email protected]>
1 parent 4bf9050 commit 5fd8314

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

cds-plugin.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ const isChangeTracked = (entity) => (
55
|| entity.elements && Object.values(entity.elements).some(e => e['@changelog'])) && entity.query?.SET?.op !== 'union'
66
)
77

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+
826

927
// Unfold @changelog annotations in loaded model
1028
cds.on('loaded', m => {
@@ -36,6 +54,31 @@ cds.on('loaded', m => {
3654

3755
// Add UI.Facet for Change History List
3856
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+
}
3982
}
4083
}
4184
})

0 commit comments

Comments
 (0)