Skip to content

Commit 16a3d4f

Browse files
authored
Merge pull request #4774 from akolson/fix-undo-on-copy
Fix undo on copy
2 parents 681f20a + 9a2afbb commit 16a3d4f

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

contentcuration/contentcuration/frontend/channelEdit/components/ContentNodeOptions.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
},
125125
{
126126
label: this.$tr('makeACopy'),
127-
onClick: this.duplicateNode,
127+
onClick: () => this.duplicateNode(this.nodeId),
128128
condition: this.canEdit,
129129
},
130130
{
@@ -347,7 +347,7 @@
347347
}
348348
);
349349
}),
350-
duplicateNode: withChangeTracker(async function(changeTracker) {
350+
duplicateNode: withChangeTracker(async function(nodeId, changeTracker) {
351351
this.trackAction('Copy');
352352
this.showSnackbar({
353353
duration: null,
@@ -358,8 +358,8 @@
358358
// actionCallback: () => changeTracker.revert(),
359359
});
360360
const copiedContentNode = await this.copyContentNode({
361-
id: this.nodeId,
362-
target: this.nodeId,
361+
id: nodeId,
362+
target: nodeId,
363363
position: RELATIVE_TREE_POSITIONS.RIGHT,
364364
});
365365

contentcuration/contentcuration/frontend/channelEdit/vuex/contentNode/__tests__/actions.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ describe('contentNode actions', () => {
3636
jest
3737
.spyOn(ContentNode, 'fetchModel')
3838
.mockImplementation(() => Promise.resolve(contentNodeDatum));
39+
jest
40+
.spyOn(ContentNode, 'getAncestors')
41+
.mockImplementation(() => Promise.resolve([contentNodeDatum]));
3942
return ContentNode._add({ title: 'notatest', parent: newId, lft: 2 }).then(() => {
4043
store = storeFactory({
4144
modules: {

contentcuration/contentcuration/frontend/shared/data/resources.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,9 +1774,14 @@ export const ContentNode = new TreeResource({
17741774
* @param {Function} updateCallback
17751775
* @return {Promise<void>}
17761776
*/
1777-
updateAncestors({ id, includeSelf = false, ignoreChanges = false }, updateCallback) {
1778-
return this.transaction({ mode: 'rw' }, async () => {
1779-
const ancestors = await this.getAncestors(id);
1777+
async updateAncestors({ id, includeSelf = false, ignoreChanges = false }, updateCallback) {
1778+
// getAncestors invokes a non-Dexie API, so it must be called outside the transaction.
1779+
// Invoking it within a transaction can lead to transaction-related issues, including premature
1780+
// commit errors, which are a common problem when mixing non-Dexie API calls with transactions.
1781+
// See: https://dexie.org/docs/DexieErrors/Dexie.PrematureCommitError
1782+
const ancestors = await this.getAncestors(id);
1783+
1784+
return await this.transaction({ mode: 'rw' }, async () => {
17801785
for (const ancestor of ancestors) {
17811786
if (ancestor.id === id && !includeSelf) {
17821787
continue;

0 commit comments

Comments
 (0)