Skip to content

Commit

Permalink
Merge pull request #1407 from hydephp/duplicate-navigation-items-shou…
Browse files Browse the repository at this point in the history
…ld-give-precedence-to-config-defined-items

Update navigation menu generator to remove duplicates after sorting
  • Loading branch information
caendesilva authored Oct 28, 2023
2 parents ddd432a + 34709c8 commit 409fbe1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This serves two purposes:
- Realtime Compiler: The `DashboardController` class is now marked as internal, as it is not intended to be used outside of the package https://github.com/hydephp/develop/pull/1394
- Updated the realtime compiler server configuration options in https://github.com/hydephp/develop/pull/1395 (backwards compatible)
- Updated the realtime compiler to generate the documentation search index each time it's requested in https://github.com/hydephp/develop/pull/1405 (fixes https://github.com/hydephp/develop/issues/1404)
- Updated the navigation menu generator to remove duplicates after running the sorting method in https://github.com/hydephp/develop/pull/1407 (fixes https://github.com/hydephp/develop/issues/1406)

### Deprecated
- for soon-to-be removed features.
Expand All @@ -33,6 +34,7 @@ This serves two purposes:
- Fixed wrong version constant in https://github.com/hydephp/develop/pull/1391
- Fixed improperly formatted exception message in https://github.com/hydephp/develop/pull/1399
- Fixed missing support for missing and out of date search indexes when previewing site https://github.com/hydephp/develop/issues/1404 in https://github.com/hydephp/develop/pull/1405
- Fixed duplicate navigation items not giving precedence to config defined items https://github.com/hydephp/develop/issues/1406 in https://github.com/hydephp/develop/pull/1407

### Security
- in case of vulnerabilities.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static function create(): static
$menu = new static();

$menu->generate();
$menu->removeDuplicateItems();
$menu->sortByPriority();
$menu->removeDuplicateItems();

return $menu;
}
Expand Down
17 changes: 16 additions & 1 deletion packages/framework/tests/Feature/NavigationMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,22 @@ public function test_duplicates_are_removed_when_adding_in_config_regardless_of_
$this->assertEquals($expected, $menu->items);
}

// TODO test when there are duplicates, config items take precedence
public function test_config_items_take_precedence_over_generated_items()
{
$this->file('_pages/foo.md');

config(['hyde.navigation.custom' => [NavItem::forLink('bar', 'Foo')]]);

$menu = NavigationMenu::create();

$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::forLink('bar', 'Foo'),
]);

$this->assertCount(count($expected), $menu->items);
$this->assertEquals($expected, $menu->items);
}

public function test_documentation_pages_that_are_not_index_are_not_added_to_the_menu()
{
Expand Down

0 comments on commit 409fbe1

Please sign in to comment.