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
3 changes: 2 additions & 1 deletion resources/js/components/structures/PageEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export default {
blueprint: Object,
handle: String,
editEntryUrl: String,
depth: Number,
creating: Boolean,
readOnly: Boolean,
},
Expand Down Expand Up @@ -284,7 +285,7 @@ export default {
this.originValues = info.originValues;
this.meta = info.meta;
this.originMeta = info.originMeta;
this.extraValues = info.extraValues;
this.extraValues = { ...info.extraValues, depth: this.depth };
this.localizedFields = info.localizedFields;
},

Expand Down
4 changes: 4 additions & 0 deletions resources/js/components/structures/PageTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ export default {
this.$emit('changed', this.pages);
},

depthOf(page) {
return this.$refs.tree.getStat(page).level;
},

expandAll() {
this.$refs.tree.openAll();
this.collapsedState = [];
Expand Down
8 changes: 7 additions & 1 deletion resources/js/pages/navigation/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export default {

return;
},

newPageDepth() {
return this.targetParent ? this.targetParent.level + 1 : 1;
},
},

watch: {
Expand Down Expand Up @@ -186,7 +190,7 @@ export default {
},

editPage(page) {
this.editingPage = { page };
this.editingPage = { page, depth: this.$refs.tree.depthOf(page) };
},

updatePage(values) {
Expand Down Expand Up @@ -550,6 +554,7 @@ export default {
:site="site"
:id="editingPage.page.id"
:entry="editingPage.page.entry"
:depth="editingPage.depth"
:editEntryUrl="editingPage.page.entry ? editingPage.page.edit_url : null"
:publish-info="publishInfo[editingPage.page.id]"
:blueprint="blueprint"
Expand All @@ -565,6 +570,7 @@ export default {
v-if="creatingPage"
creating
:site="site"
:depth="newPageDepth"
:blueprint="blueprint"
:handle="handle"
:read-only="!canEdit"
Expand Down
28 changes: 28 additions & 0 deletions resources/js/tests/components/structures/PageTree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,31 @@ test('an editable tree takes the save shortcut and gives it back', async () => {
expect(save).toHaveBeenCalledTimes(1);
expect(outerSaves).toBe(1);
});

test('a page reports the depth it currently sits at, not the depth it was loaded with', async () => {
const child = { id: 'child', title: 'Child', depth: 2, children: [] };
const parent = { id: 'parent', title: 'Parent', depth: 1, children: [child] };

const wrapper = mount(PageTree, {
props: {
pagesUrl: '/test/pages',
editable: false,
},
global: {
stubs: { TreeBranch: true, PanelHeader: true, Panel: true, Icon: true },
mocks: {
$keys: keys,
$config: { get: (key, fallback) => fallback },
$axios: { get: () => Promise.resolve({ data: { pages: [parent] } }) },
},
},
});
await flushPromises();

expect(wrapper.vm.depthOf(child)).toBe(2);

const tree = wrapper.vm.$refs.tree;
tree.move(tree.getStat(child), null, 1);

expect(wrapper.vm.depthOf(child)).toBe(1);
});
Loading