Skip to content

Commit 09bcd32

Browse files
committed
bugfix: invalid depth if the content depth > 1
1 parent 0f20bca commit 09bcd32

File tree

3 files changed

+38
-40
lines changed

3 files changed

+38
-40
lines changed

database/seeders/SampleSeeder.php

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ protected function getSampleDocumentTypes()
299299
$items[] = new ImportDataEntities\DocumentType(
300300
slug: 'post-page',
301301
showAsTable: false,
302-
showAtRoot: true,
302+
showAtRoot: false,
303303
category: 'web',
304304
fieldGroups: [],
305305
templates: [
@@ -401,10 +401,10 @@ protected function getSampleDocumentTypes()
401401
->merge($allSlugs)
402402
->unique()
403403
->filter()
404-
->where(fn ($slug) => ! in_array($slug, [
404+
->reject(fn ($slug) => in_array($slug, [
405405
'homepage', // self
406-
'case-study', // children under case-study index page
407-
'post', // data-type
406+
'case-study-detail-page', // children under case-study index page
407+
'blog-data', // data-type
408408
]))
409409
->values()
410410
->toArray();
@@ -504,6 +504,31 @@ protected function getSampleContent()
504504
publishState: 'publish',
505505
parent: 'home',
506506
);
507+
508+
$items[] = new ImportDataEntities\Content(
509+
slug: 'post',
510+
title: ['en' => 'Post', 'fr' => 'Post'],
511+
documentType: 'post-page',
512+
publishState: 'publish',
513+
parent: 'home/blog',
514+
routes: [
515+
[
516+
'locale' => null,
517+
'uri' => 'blog/post/{slug}',
518+
'is_default_pattern' => false,
519+
],
520+
[
521+
'locale' => 'en',
522+
'uri' => '{locale}/blog/post/{slug}',
523+
'is_default_pattern' => false,
524+
],
525+
[
526+
'locale' => 'fr',
527+
'uri' => 'fr/blog/post/{slug}',
528+
'is_default_pattern' => false,
529+
],
530+
],
531+
);
507532
foreach (range(1, 10) as $i) {
508533

509534
$sampleCatOrTags = [
@@ -601,37 +626,6 @@ protected function getSampleContent()
601626
parent: 'home',
602627
);
603628

604-
$items[] = new ImportDataEntities\Content(
605-
slug: 'dynamic-post-page',
606-
title: ['en' => 'Dynamic Post Page', 'fr' => 'Dynamic Post Page'],
607-
documentType: 'post-page',
608-
publishState: 'publish',
609-
parent: 'home',
610-
routes: [
611-
[
612-
'locale' => null,
613-
'uri' => 'blog/post/{slug}',
614-
'is_default_pattern' => false,
615-
],
616-
[
617-
'locale' => 'en',
618-
'uri' => 'en/blog/post/{slug}',
619-
'is_default_pattern' => false,
620-
],
621-
[
622-
'locale' => 'fr',
623-
'uri' => 'fr/blog/post/{slug}',
624-
'is_default_pattern' => false,
625-
],
626-
],
627-
webSetting: [
628-
'seo' => [
629-
'meta_title' => 'Post',
630-
'og_title' => 'Post',
631-
],
632-
],
633-
);
634-
635629
$items[] = new ImportDataEntities\Content(
636630
slug: 'case-studies',
637631
title: ['en' => 'Works', 'fr' => 'Travaux'],

src/Livewire/BaseContentTreeNode.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public function modelExplorer(ModelExplorer $modelExplorer): ModelExplorer
5353
return 0;
5454
}
5555

56-
$parentDepth = collect($this->cachedModelExplorerItems)
57-
->flatten(1)
58-
->firstWhere('key', $parentKey)['depth'] ?? -1;
56+
if ($record->ancestorsAndSelf != null) {
57+
return count($record->ancestorsAndSelf);
58+
}
5959

60-
return $parentDepth + 1;
60+
return 0;
6161
})
6262
->determineItemTitleUsing(fn (Model | Content $record) => $record->title)
6363
->determineItemHasChildrenUsing(fn (Model | Content $record) => $record->children_count > 0);

src/Livewire/ContentSidebar.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ public function mount()
3737
{
3838
$this->cacheModelExplorerNodesOn(parentKey: $this->getModelRootLevelParentId());
3939

40+
// Init selected model item
4041
if (! empty($this->selectedModelItemKeys)) {
4142
$record = $this->resolveSelectedModelItems($this->selectedModelItemKeys)->first();
43+
// Do not show seleccted record if it is a table node
4244
if ($this->isDisplayChildrenAsTable($record?->parent)) {
4345
$this->setSelectedModelItem([$record->parent->getKey()], merge: false, replace: true);
44-
} else {
46+
}
47+
// Expand ancestors nodes
48+
else {
4549
$this->expandParentModelItemIfSelected($this->selectedModelItemKeys);
4650
}
4751
}

0 commit comments

Comments
 (0)