feat(Sylius): Search in the choose media modal#127
Merged
Conversation
ae44333 to
744a863
Compare
744a863 to
6fec7e7
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds search capability to the Sylius “choose media” modal so admins can filter directories and media by a text query, including recursive search.
Changes:
- Introduces a search UI in the choose-media modal and adds new i18n keys for the search label/button.
- Updates the Sylius
MediaAdminController::choose()(and AJAX directory-create flow) to accept a search value and perform recursive filtering when searching. - Updates the admin JS bundle and asset references (hashed filename, manifest/entrypoints).
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Bridge/Sylius/translations/JoliMediaSyliusBundle.fr.yaml | Adds French translations for search label/button. |
| src/Bridge/Sylius/translations/JoliMediaSyliusBundle.en.yaml | Adds English translations for search label/button. |
| src/Bridge/Sylius/templates/admin/shared/layout/base/scripts.html.twig | Updates the referenced hashed admin JS asset. |
| src/Bridge/Sylius/templates/admin/media/choose.html.twig | Adds the search form to the choose-media modal and forwards search to directory creation. |
| src/Bridge/Sylius/src/Admin/Controller/MediaAdminController.php | Parses search input, toggles recursive listing, and applies filters for directories/medias. |
| src/Bridge/Sylius/public/manifest.json | Updates admin JS asset mapping. |
| src/Bridge/Sylius/public/entrypoints.json | Updates admin JS entrypoint to the new hashed file. |
| src/Bridge/Sylius/public/joli-media-sylius-admin.dc8dd6d7.js | New built admin JS bundle including modal search logic. |
| src/Bridge/Sylius/public/joli-media-sylius-admin.0ec877e4.js | Removes the previous built admin JS bundle. |
| src/Bridge/Sylius/assets/js/components/mediaSelector.js | Implements client-side search interactions and propagates search across modal actions. |
Files not reviewed (1)
- src/Bridge/Sylius/public/joli-media-sylius-admin.dc8dd6d7.js: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+378
to
+380
| $searchValue = $request->query->all('criteria')['search']['value'] ?? $request->query->getString('search', ''); | ||
| $hasSearch = '' !== $searchValue; | ||
|
|
Comment on lines
+390
to
+396
| $dirFilter = null; | ||
| if ($hasSearch) { | ||
| $dirFilter = static fn (string $a): bool => str_contains(strtolower($a), strtolower($searchValue)); | ||
| } | ||
|
|
||
| $directories = $this->getOriginalStorage()->listDirectories($currentKey, recursive: $hasSearch, filter: $dirFilter); | ||
|
|
Comment on lines
+44
to
+46
| <form class="joli-media-search-form" data-component="media-search"> | ||
| <div class="input-group"> | ||
| <input type="search" class="form-control joli-media-search-input" placeholder="{{ 'media.search_label'|trans }}" value="{{ search }}" autocomplete="off"> |
Comment on lines
371
to
+407
| #[Route(path: '/choose/{key}', name: 'choose', requirements: ['key' => '.*'], methods: [Request::METHOD_GET])] | ||
| public function choose(Request $request, string $key = ''): Response | ||
| { | ||
| $currentKey = Resolver::normalizePath($key); | ||
| $request->attributes->set('currentKey', $currentKey); | ||
| $parentKey = '' !== $currentKey ? (($pos = strrpos($currentKey, '/')) !== false ? substr($currentKey, 0, $pos) : '') : ''; | ||
|
|
||
| $searchValue = $request->query->all('criteria')['search']['value'] ?? $request->query->getString('search', ''); | ||
| $hasSearch = '' !== $searchValue; | ||
|
|
||
| $perPage = $this->config->getPaginationSizes()[0] ?? 10; | ||
|
|
||
| try { | ||
| $trashPath = $this->getOriginalStorage()->getTrashPath(); | ||
|
|
||
| if ($trashPath === $currentKey || str_starts_with($currentKey, $trashPath . '/')) { | ||
| throw new ForbiddenPathException($trashPath); | ||
| } | ||
|
|
||
| $directories = $this->getOriginalStorage()->listDirectories($currentKey, recursive: false); | ||
| natcasesort($directories); | ||
| $dirFilter = null; | ||
| if ($hasSearch) { | ||
| $dirFilter = static fn (string $a): bool => str_contains(strtolower($a), strtolower($searchValue)); | ||
| } | ||
|
|
||
| $directories = $this->getOriginalStorage()->listDirectories($currentKey, recursive: $hasSearch, filter: $dirFilter); | ||
|
|
||
| if (!$hasSearch) { | ||
| natcasesort($directories); | ||
| } | ||
| } catch (ForbiddenPathException|PathTraversalDetected|UnableToListContents) { | ||
| $directories = []; | ||
| } | ||
|
|
||
| $mediaFilter = null; | ||
| if ($hasSearch) { | ||
| $mediaFilter = static fn ($media): bool => str_contains(strtolower($media->getPath()), strtolower($searchValue)); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
You're right, I've added a few tests.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
search-in-choose-modal.mov