Skip to content

Commit f6bc1fd

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

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ protected function getOrCreateGroupItem(string $groupName): NavItem
123123
protected function createGroupItem(string $identifier, string $groupName): NavItem
124124
{
125125
$label = $this->searchForGroupLabelInConfig($identifier) ?? $groupName;
126+
$priority = $this->searchForGroupPriorityInConfig($identifier);
126127

127-
return NavItem::dropdown(static::normalizeGroupLabel($label), []);
128+
return NavItem::dropdown(static::normalizeGroupLabel($label), [], $priority);
128129
}
129130

130131
protected function searchForGroupLabelInConfig(string $identifier): ?string
@@ -142,4 +143,10 @@ protected static function normalizeGroupLabel(string $label): string
142143

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

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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static function forRoute(Route|string $route, ?string $label = null, ?int
9999
*/
100100
public static function dropdown(string $label, array $items, ?int $priority = null): static
101101
{
102-
return new static('', $label, $priority ?? static::searchForDropdownPriorityInNavigationConfig(Str::slug($label)) ?? 999, $label, $items);
102+
return new static('', $label, $priority ?? 999, $label, $items);
103103
}
104104

105105
/**
@@ -207,10 +207,4 @@ protected static function makeIdentifier(string $label): string
207207
{
208208
return Str::slug($label); // Todo: If it's a dropdown based on a subdirectory, we should use the subdirectory as the identifier
209209
}
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-
}
216210
}

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)