Add autocomplete search and improve navbar UI#153
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an autocomplete-powered global package search and refactors the navbar/search UI into reusable CakePHP elements, backed by new helper logic and test coverage.
Changes:
- Added
/autocompleteJSON endpoint plusPackagesTable::findAutocomplete()finder for ranked, limited search results with tag containment. - Introduced Alpine.js
packageSearchcomponent and extracted navbar/search markup intotemplates/element/*elements, with a newUserHelperfor identity display. - Expanded fixtures and added/updated tests for the helper, finder, and controller endpoint.
Reviewed changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/TestCase/View/Helper/UserHelperTest.php | Adds unit tests for UserHelper helper methods. |
| tests/TestCase/Model/Table/PackagesTableTest.php | Adds tests for the new findAutocomplete() finder and tag containment. |
| tests/TestCase/Controller/PackagesControllerTest.php | Adds integration tests for /autocomplete JSON endpoint behavior. |
| tests/Fixture/PackagesFixture.php | Extends fixture data to support autocomplete ranking tests. |
| templates/layout/default.php | Replaces inline navbar/search markup with element('navbar'). |
| templates/element/search.php | Adds global search form element with Alpine-powered autocomplete dropdown. |
| templates/element/navbar.php | Adds new navbar element incorporating the search element and user menu. |
| src/View/Helper/UserHelper.php | Introduces helper for username/display name/avatar rendering. |
| src/View/AppView.php | Loads the new User helper globally. |
| src/Model/Table/PackagesTable.php | Implements findAutocomplete() finder with ranking + limits + tags. |
| src/Controller/PackagesController.php | Adds autocomplete() action and allows unauthenticated access to it. |
| resources/js/app.js | Adds Alpine.js autocomplete client logic and starts Alpine. |
| resources/css/style.css | Adds [x-cloak] styling for Alpine templates. |
| package.json | Adds Alpine.js dependency. |
| package-lock.json | Locks Alpine.js and transitive dependencies (and updates package name field). |
| config/routes.php | Enables JSON extension parsing and connects /autocomplete. |
| config/Migrations/schema-dump-default.lock | Adds schema dump lock artifact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an Alpine.js-powered autocomplete search dropdown and extracts layout components into reusable CakePHP elements with proper test coverage.
Changes
Autocomplete search
/autocompleteJSON endpoint inPackagesControllerreturning package name, description, stats, and version infofindAutocomplete()custom finder onPackagesTableusing the existingFriendsOfCake/Searchplugin with name-match relevance sorting (packages matching by name rank above description-only matches)packageSearchcomponent with debounced fetch, keyboard navigation (↑↓/Enter/Escape), and AbortController for cancelling stale requestsUI refactoring
element/search.phpand navbar intoelement/navbar.php, simplifying the default layoutUserHelperwithusername(),displayName(),avatarUrl(), andavatar()methods — replaces inline identity logic in templatesTests
UserHelperTest— 12 tests covering all helper methods for logged-in/logged-out statesPackagesTableTest— 8 tests for thefindAutocompletefinder (matching, limit, priority, ordering, tag containment)PackagesControllerTest— 5 integration tests for the autocomplete endpoint (JSON structure, short/missing/no-match queries, result limit)