Skip to content

Commit 59a3cc4

Browse files
committed
Move logic to instance accessor
1 parent e9aac1c commit 59a3cc4

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

packages/framework/src/Framework/Features/Navigation/GeneratesDocumentationSidebarMenu.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use Hyde\Pages\DocumentationPage;
88

9-
use function collect;
10-
119
/**
1210
* @experimental This class may change significantly before its release.
1311
*
@@ -42,16 +40,7 @@ protected function sortSidebarGroupsByLowestPriority(): void
4240
// we do an initial sorting here to order any groups.
4341

4442
$this->items = $this->items->sortBy(function (NavItem $item): int {
45-
return $item->hasChildren()
46-
? $this->getLowestPriorityInGroup($item)
47-
: $item->getPriority();
43+
return $item->getPriority();
4844
})->values();
4945
}
50-
51-
protected function getLowestPriorityInGroup(NavItem $item): int
52-
{
53-
// Todo: Could actually be moved to the NavItem accessor
54-
55-
return collect($item->getChildren())->min(fn (NavItem $child): int => $child->getPriority());
56-
}
5746
}

packages/framework/src/Framework/Features/Navigation/NavItem.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Stringable;
1212
use Hyde\Support\Models\ExternalRoute;
1313

14+
use function collect;
1415
use function is_string;
1516

1617
/**
@@ -135,9 +136,15 @@ public function getLabel(): string
135136

136137
/**
137138
* Get the priority to determine the order of the navigation item.
139+
*
140+
* For dropdowns, this is the priority of the lowest priority child, unless the dropdown has a lower priority.
138141
*/
139142
public function getPriority(): int
140143
{
144+
if ($this->hasChildren()) {
145+
return min($this->priority, collect($this->getChildren())->min(fn (NavItem $child): int => $child->getPriority()));
146+
}
147+
141148
return $this->priority;
142149
}
143150

packages/framework/tests/Unit/NavItemTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function testDropdownFacadeWithChildren()
278278

279279
$item = NavItem::dropdown('foo', $children);
280280
$this->assertSame($children, $item->getChildren());
281-
$this->assertSame(999, $item->getPriority());
281+
$this->assertSame(500, $item->getPriority());
282282
}
283283

284284
public function testDropdownFacadeWithCustomPriority()

0 commit comments

Comments
 (0)