Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
},
{
label: this.$tr('makeACopy'),
onClick: this.duplicateNode,
onClick: () => this.duplicateNode(this.nodeId),
condition: this.canEdit,
},
{
Expand Down Expand Up @@ -347,7 +347,7 @@
}
);
}),
duplicateNode: withChangeTracker(async function(changeTracker) {
duplicateNode: withChangeTracker(async function(nodeId, changeTracker) {
this.trackAction('Copy');
this.showSnackbar({
duration: null,
Expand All @@ -358,8 +358,8 @@
// actionCallback: () => changeTracker.revert(),
});
const copiedContentNode = await this.copyContentNode({
id: this.nodeId,
target: this.nodeId,
id: nodeId,
target: nodeId,
position: RELATIVE_TREE_POSITIONS.RIGHT,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ describe('contentNode actions', () => {
jest
.spyOn(ContentNode, 'fetchModel')
.mockImplementation(() => Promise.resolve(contentNodeDatum));
jest
.spyOn(ContentNode, 'getAncestors')
.mockImplementation(() => Promise.resolve([contentNodeDatum]));
return ContentNode._add({ title: 'notatest', parent: newId, lft: 2 }).then(() => {
store = storeFactory({
modules: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1774,9 +1774,14 @@ export const ContentNode = new TreeResource({
* @param {Function} updateCallback
* @return {Promise<void>}
*/
updateAncestors({ id, includeSelf = false, ignoreChanges = false }, updateCallback) {
return this.transaction({ mode: 'rw' }, async () => {
const ancestors = await this.getAncestors(id);
async updateAncestors({ id, includeSelf = false, ignoreChanges = false }, updateCallback) {
// getAncestors invokes a non-Dexie API, so it must be called outside the transaction.
// Invoking it within a transaction can lead to transaction-related issues, including premature
// commit errors, which are a common problem when mixing non-Dexie API calls with transactions.
// See: https://dexie.org/docs/DexieErrors/Dexie.PrematureCommitError
const ancestors = await this.getAncestors(id);

return await this.transaction({ mode: 'rw' }, async () => {
for (const ancestor of ancestors) {
if (ancestor.id === id && !includeSelf) {
continue;
Expand Down