Skip to content

Commit

Permalink
Limit on 1000 results and display warning if reached in modal
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Apr 9, 2024
1 parent ed4c790 commit 1725e5b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Provider/AbstractUrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

abstract class AbstractUrlProvider implements UrlProviderInterface
{
protected int $maxResults = 1000;

protected string $code;

protected string $icon = 'angle right';
Expand Down Expand Up @@ -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[] = [
Expand Down
2 changes: 2 additions & 0 deletions src/Provider/ProductUrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ protected function getResults(string $locale, string $search = ''): iterable
;
}

$queryBuilder->setMaxResults($this->getMaxResults());

return $queryBuilder->getQuery()->getResult();
}

Expand Down
2 changes: 2 additions & 0 deletions src/Provider/TaxonUrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ protected function getResults(string $locale, string $search = ''): iterable
;
}

$queryBuilder->setMaxResults($this->getMaxResults());

return $queryBuilder->getQuery()->getResult();
}

Expand Down
1 change: 1 addition & 0 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions src/Resources/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
11 changes: 10 additions & 1 deletion src/Resources/views/Admin/Browser/Modal/Content/_items.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{% set items = urlProvider.items(locale, search) %}
{% set maxResults = urlProvider.maxResults %}

{% if (items | length) >= maxResults %}
<div class="ui message">
<p>{{ 'monsieurbiz_menu.ui.too_many_results'|trans({'%maxResults%': maxResults }) }}</p>
</div>
{% 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 %}
<div class="item">
<div class="right floated content">
{% include '@MonsieurBizSyliusMenuPlugin/Admin/Browser/Modal/Content/Item/_showLink.html.twig' %}
Expand Down

0 comments on commit 1725e5b

Please sign in to comment.