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 @@ -281,19 +281,24 @@
'moveContentNodes',
'loadContentNodes',
'loadAncestors',
'removeContentNodes',
]),
loadNodes() {
this.loading = true;
this.more = null;
this.moreLoading = false;
if (!this.trashId) {
this.loading = false;
return;
}
this.loadChildren({ parent: this.trashId, ordering: '-modified' }).then(
childrenResponse => {
this.loading = false;
this.more = childrenResponse.more || null;
},
);
this.removeContentNodes({ parentId: this.trashId }).then(() => {
this.loadChildren({ parent: this.trashId, ordering: '-modified' }).then(
childrenResponse => {
this.loading = false;
this.more = childrenResponse.more || null;
},
);
});
},
moveNodes(target) {
return this.moveContentNodes({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,12 @@ describe('ContentNode methods', () => {

it('should update the node with the payload', async () => {
node.parent = parent.id;
await expect(ContentNode.tableMove({ node, parent, payload, change })).resolves.toBe(payload);
expect(table.update).toHaveBeenCalledWith(node.id, payload);
const result = await ContentNode.tableMove({ node, parent, payload, change });
expect(result).toMatchObject({ ...payload, modified: expect.any(String) });
expect(table.update).toHaveBeenCalledTimes(1);
const [updateId, updatePayload] = table.update.mock.calls[0];
expect(updateId).toBe(node.id);
expect(updatePayload).toBe(result);
expect(table.put).not.toBeCalled();
expect(table.update).not.toHaveBeenCalledWith(node.parent, { changed: true });
});
Expand All @@ -584,19 +588,23 @@ describe('ContentNode methods', () => {
node.parent = parent.id;
updated = false;
const newPayload = { ...payload, root_id: parent.root_id };
await expect(ContentNode.tableMove({ node, parent, payload, change })).resolves.toMatchObject(
newPayload,
const result = await ContentNode.tableMove({ node, parent, payload, change });
expect(result).toMatchObject({ ...newPayload, modified: expect.any(String) });
expect(table.update).toHaveBeenCalledWith(
node.id,
expect.objectContaining({ ...payload, modified: expect.any(String) }),
);
expect(table.update).toHaveBeenCalledWith(node.id, payload);
expect(table.put).toHaveBeenCalledWith(newPayload);
expect(table.put).toHaveBeenCalledWith(result);
expect(table.update).not.toHaveBeenCalledWith(node.parent, { changed: true });
});

it('should mark the old parent as changed', async () => {
await expect(ContentNode.tableMove({ node, parent, payload, change })).resolves.toMatchObject(
payload,
const result = await ContentNode.tableMove({ node, parent, payload, change });
expect(result).toMatchObject({ ...payload, modified: expect.any(String) });
expect(table.update).toHaveBeenCalledWith(
node.id,
expect.objectContaining({ ...payload, modified: expect.any(String) }),
);
expect(table.update).toHaveBeenCalledWith(node.id, payload);
expect(table.put).not.toBeCalled();
expect(table.update).toHaveBeenCalledWith(node.parent, { changed: true });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,10 @@ export const ContentNode = new TreeResource({
async tableMove({ node, parent, payload }) {
// Do direct table writes here rather than using add/update methods to avoid
// creating unnecessary additional change events.
payload = {
...payload,
modified: new Date().toISOString(),
};
const updated = await this.table.update(node.id, payload);
// Update didn't succeed, this node probably doesn't exist, do a put instead,
// but need to add in other parent info.
Expand Down