From 1725e5be76ebf201fe1b0c2c6650971286b549eb Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Tue, 9 Apr 2024 19:31:59 +0200 Subject: [PATCH] Limit on 1000 results and display warning if reached in modal --- src/Provider/AbstractUrlProvider.php | 7 +++++++ src/Provider/ProductUrlProvider.php | 2 ++ src/Provider/TaxonUrlProvider.php | 2 ++ src/Resources/translations/messages.en.yaml | 1 + src/Resources/translations/messages.fr.yaml | 1 + .../Admin/Browser/Modal/Content/_items.html.twig | 11 ++++++++++- 6 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Provider/AbstractUrlProvider.php b/src/Provider/AbstractUrlProvider.php index 1bbce72..567056f 100644 --- a/src/Provider/AbstractUrlProvider.php +++ b/src/Provider/AbstractUrlProvider.php @@ -17,6 +17,8 @@ abstract class AbstractUrlProvider implements UrlProviderInterface { + protected int $maxResults = 1000; + protected string $code; protected string $icon = 'angle right'; @@ -45,6 +47,11 @@ public function getPriority(): int return $this->priority; } + public function getMaxResults(): int + { + return $this->maxResults; + } + protected function addItem(string $name, string $path): void { $this->items[] = [ diff --git a/src/Provider/ProductUrlProvider.php b/src/Provider/ProductUrlProvider.php index f9f2a2e..772fa0e 100644 --- a/src/Provider/ProductUrlProvider.php +++ b/src/Provider/ProductUrlProvider.php @@ -49,6 +49,8 @@ protected function getResults(string $locale, string $search = ''): iterable ; } + $queryBuilder->setMaxResults($this->getMaxResults()); + return $queryBuilder->getQuery()->getResult(); } diff --git a/src/Provider/TaxonUrlProvider.php b/src/Provider/TaxonUrlProvider.php index 7c8542d..e8404b6 100644 --- a/src/Provider/TaxonUrlProvider.php +++ b/src/Provider/TaxonUrlProvider.php @@ -52,6 +52,8 @@ protected function getResults(string $locale, string $search = ''): iterable ; } + $queryBuilder->setMaxResults($this->getMaxResults()); + return $queryBuilder->getQuery()->getResult(); } diff --git a/src/Resources/translations/messages.en.yaml b/src/Resources/translations/messages.en.yaml index f7571e2..f5656c8 100644 --- a/src/Resources/translations/messages.en.yaml +++ b/src/Resources/translations/messages.en.yaml @@ -25,6 +25,7 @@ monsieurbiz_menu: cancel: 'Cancel' go_back: 'Go back' search: 'Search' + too_many_results: 'This view is limited to %maxResults% results. Use search to filter on items.' provider: product: 'Product' taxon: 'Taxon' diff --git a/src/Resources/translations/messages.fr.yaml b/src/Resources/translations/messages.fr.yaml index 75e31ac..4696d83 100644 --- a/src/Resources/translations/messages.fr.yaml +++ b/src/Resources/translations/messages.fr.yaml @@ -25,6 +25,7 @@ monsieurbiz_menu: cancel: 'Annuler' go_back: 'Retour en arrière' search: 'Rechercher' + too_many_results: 'La vue est limitée à %maxResults% résultats. Veuillez affiner votre recherche.' provider: product: 'Produit' taxon: 'Taxon' diff --git a/src/Resources/views/Admin/Browser/Modal/Content/_items.html.twig b/src/Resources/views/Admin/Browser/Modal/Content/_items.html.twig index 12a8208..5874ac5 100644 --- a/src/Resources/views/Admin/Browser/Modal/Content/_items.html.twig +++ b/src/Resources/views/Admin/Browser/Modal/Content/_items.html.twig @@ -1,6 +1,15 @@ +{% set items = urlProvider.items(locale, search) %} +{% set maxResults = urlProvider.maxResults %} + +{% if (items | length) >= maxResults %} +
+

{{ 'monsieurbiz_menu.ui.too_many_results'|trans({'%maxResults%': maxResults }) }}

+
+{% endif %} + {% include '@MonsieurBizSyliusMenuPlugin/Admin/Browser/Modal/Content/_back.html.twig' %} {% include '@MonsieurBizSyliusMenuPlugin/Admin/Browser/Modal/Content/_search.html.twig' %} -{% for item in urlProvider.items(locale, search) %} +{% for item in items %}
{% include '@MonsieurBizSyliusMenuPlugin/Admin/Browser/Modal/Content/Item/_showLink.html.twig' %}