Skip to content

Commit e2e0f2d

Browse files
committed
Refactor to handle priority search in generators
1 parent ffa86ff commit e2e0f2d

File tree

5 files changed

+17
-26
lines changed

5 files changed

+17
-26
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Hyde\Foundation\Facades\Routes;
1414
use Hyde\Foundation\Kernel\RouteCollection;
1515

16+
use function filled;
1617
use function collect;
1718
use function strtolower;
1819

@@ -123,8 +124,9 @@ protected function getOrCreateGroupItem(string $groupName): NavItem
123124
protected function createGroupItem(string $identifier, string $groupName): NavItem
124125
{
125126
$label = $this->searchForGroupLabelInConfig($identifier) ?? $groupName;
127+
$priority = $this->searchForGroupPriorityInConfig($identifier);
126128

127-
return NavItem::dropdown(static::normalizeGroupLabel($label), []);
129+
return NavItem::dropdown(static::normalizeGroupLabel($label), [], $priority);
128130
}
129131

130132
protected function searchForGroupLabelInConfig(string $identifier): ?string
@@ -142,4 +144,10 @@ protected static function normalizeGroupLabel(string $label): string
142144

143145
return $label;
144146
}
147+
148+
/** Todo: Move into shared class */
149+
protected static function searchForGroupPriorityInConfig(string $groupKey): ?int
150+
{
151+
return Config::getArray('docs.sidebar_order', [])[$groupKey] ?? null;
152+
}
145153
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected function moveGroupedItemsIntoDropdowns(): void
7474

7575
foreach ($dropdowns as $group => $items) {
7676
// Create a new dropdown item containing the buffered items
77-
$this->items->add(NavItem::dropdown(static::normalizeGroupLabel($group), $items));
77+
$this->items->add(NavItem::dropdown(static::normalizeGroupLabel($group), $items, static::searchForDropdownPriorityInConfig($group)));
7878
}
7979
}
8080

@@ -103,4 +103,10 @@ protected static function normalizeGroupLabel(string $label): string
103103

104104
return $label;
105105
}
106+
107+
/** Todo: Move into shared class */
108+
protected static function searchForDropdownPriorityInConfig(string $groupKey): ?int
109+
{
110+
return Config::getArray('hyde.navigation.order', [])[$groupKey] ?? null;
111+
}
106112
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Hyde\Framework\Features\Navigation;
66

7-
use Hyde\Facades\Config;
87
use Hyde\Foundation\Facades\Routes;
98
use Hyde\Hyde;
109
use Hyde\Support\Models\Route;
@@ -99,7 +98,7 @@ public static function forRoute(Route|string $route, ?string $label = null, ?int
9998
*/
10099
public static function dropdown(string $label, array $items, ?int $priority = null): static
101100
{
102-
return new static('', $label, $priority ?? static::searchForDropdownPriorityInNavigationConfig(Str::slug($label)) ?? 999, $label, $items);
101+
return new static('', $label, $priority ?? 999, $label, $items);
103102
}
104103

105104
/**
@@ -207,10 +206,4 @@ protected static function makeIdentifier(string $label): string
207206
{
208207
return Str::slug($label); // Todo: If it's a dropdown based on a subdirectory, we should use the subdirectory as the identifier
209208
}
210-
211-
/** @deprecated This responsibility does not belong here. This should happen before the NavItem is created. */
212-
protected static function searchForDropdownPriorityInNavigationConfig(string $groupKey): ?int
213-
{
214-
return Config::getArray('hyde.navigation.order', [])[$groupKey] ?? null;
215-
}
216209
}

packages/framework/tests/Feature/AutomaticNavigationConfigurationsTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,6 @@ public function testMainNavigationDropdownPriorityCanBeSetInConfigUsingDiffering
10641064

10651065
public function testSidebarGroupPriorityCanBeSetInConfig()
10661066
{
1067-
$this->markTestSkipped('TODO');
1068-
10691067
config(['docs.sidebar_order' => ['foo' => 500]]);
10701068

10711069
$this->assertSidebarEquals(
@@ -1076,8 +1074,6 @@ public function testSidebarGroupPriorityCanBeSetInConfig()
10761074

10771075
public function testSidebarGroupPriorityCanBeSetInConfigUsingDifferingCases()
10781076
{
1079-
$this->markTestSkipped('TODO');
1080-
10811077
config(['docs.sidebar_order' => ['hello-world' => 500]]);
10821078

10831079
$expected = [['label' => 'Hello World', 'priority' => 500]];

packages/framework/tests/Unit/NavItemTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,4 @@ public function testCanAddItemToDropdown()
396396

397397
$this->assertSame([$child], $parent->getChildren());
398398
}
399-
400-
public function testDefaultDropdownItemPriority()
401-
{
402-
$this->assertSame(999, NavItem::dropdown('foo', [])->getPriority());
403-
}
404-
405-
public function testCanResolveDropdownItemPriorityFromConfig()
406-
{
407-
$this->mockConfig(['hyde.navigation.order' => ['foo' => 500]]);
408-
409-
$this->assertSame(500, NavItem::dropdown('foo', [])->getPriority());
410-
}
411399
}

0 commit comments

Comments
 (0)