Skip to content

Commit 67d9e2a

Browse files
authored
PRO-8223: be careful when assuming doc is an actual doc (#5053)
1 parent 3546051 commit 67d9e2a

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Fixes the widget data being cloned to be saved before the `postprocess` method being called, which leads to a loss of data in `AposWidgetEditor` (like the autocrop data).
2222
* In editors like `AposWidgetEditor` relationships are now post processed after they are updated in `AposInputRelationship` only for the relationship that has been updated.
2323
It allows live preview to work well with it, it also avoids complexity and fixes updated data not being properly synced between the editor and the `AposSchema`.
24+
* Deeply nested widgets can now be edited properly via the editor dialog box. This longstanding issue did not affect on-page editing.
2425

2526
### Changes
2627

modules/@apostrophecms/area/lib/custom-tags/area.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports = function(self) {
6969
items: []
7070
};
7171
doc[name] = area;
72-
const docId = doc._docId || doc._id;
72+
const docId = doc._docId || ((doc.metaType === 'doc') ? doc._id : null);
7373
if (docId) {
7474
let mainDoc = await self.apos.doc.db.findOne({ _id: docId });
7575
if (!mainDoc) {

modules/@apostrophecms/doc-type/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,15 +2491,15 @@ module.exports = {
24912491
area._edit = true;
24922492
}
24932493

2494-
area._docId = doc._id;
2494+
area._docId = doc._docId || ((doc.metaType === 'doc') ? doc._id : null);
24952495
for (const item of area.items) {
24962496
if (area._edit) {
24972497
// Keep propagating ._edit so a widget can be passed
24982498
// like a doc to aposArea if it contains nested areas.
24992499
// -Tom
25002500
item._edit = true;
25012501
}
2502-
item._docId = doc._id;
2502+
item._docId = area._docId;
25032503
if (!widgetsByType[item.type]) {
25042504
widgetsByType[item.type] = [];
25052505
}
@@ -2512,7 +2512,7 @@ module.exports = {
25122512
// be edited in context
25132513
for (const info of arrayItemsInfo) {
25142514
const arrayItem = info.arrayItem;
2515-
arrayItem._docId = doc._docId || doc._id;
2515+
arrayItem._docId = doc._docId || ((doc.metaType === 'doc') ? doc._id : null);
25162516
arrayItem._edit = doc._edit;
25172517
}
25182518
}

modules/@apostrophecms/schema/ui/apos/lib/detectChange.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function detectFieldChange(field, v1, v2) {
6464
const newObject = {};
6565
for (const [ key, val ] of Object.entries(o)) {
6666
if (key === '_docId') {
67-
newObject._docId = o._docId.replace(/:.*$/, '');
67+
newObject._docId = (o._docId == null) ? null : o._docId.replace(/:.*$/, '');
6868
} else if (key === '_id') {
6969
// So draft and published can be compared
7070
newObject._id = o._id.replace(/:[\w-]+:[\w]+$/, '');

0 commit comments

Comments
 (0)