Skip to content

feat(Sylius): Search in the choose media modal#127

Merged
loic425 merged 3 commits into
jolicode:mainfrom
loic425:feat/search-in-choose-modal
May 21, 2026
Merged

feat(Sylius): Search in the choose media modal#127
loic425 merged 3 commits into
jolicode:mainfrom
loic425:feat/search-in-choose-modal

Conversation

@loic425
Copy link
Copy Markdown
Contributor

@loic425 loic425 commented May 21, 2026

search-in-choose-modal.mov

@loic425 loic425 force-pushed the feat/search-in-choose-modal branch from ae44333 to 744a863 Compare May 21, 2026 13:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread src/Bridge/Sylius/templates/admin/media/choose.html.twig Outdated
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));
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I've added a few tests.

loic425 and others added 2 commits May 21, 2026 17:06
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@loic425 loic425 merged commit df9487d into jolicode:main May 21, 2026
6 checks passed
@loic425 loic425 deleted the feat/search-in-choose-modal branch May 21, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants