Skip to content

Enhancement: Introduces PagerInterface::isDeterministic (refs #8164)#8205

Open
mvhirsch wants to merge 1 commit intosonata-project:4.xfrom
mvhirsch:feature/8164-render-deterministic-count
Open

Enhancement: Introduces PagerInterface::isDeterministic (refs #8164)#8205
mvhirsch wants to merge 1 commit intosonata-project:4.xfrom
mvhirsch:feature/8164-render-deterministic-count

Conversation

@mvhirsch
Copy link
Contributor

Subject

This is my suggestion to indicate an enduser that the list doesn't know how many elements ("all elements") will be affected by now. I decided to use a universal + sign to indicate it.

Default behavior:

image

Behavior SimplePager:

image

I'm not sure if I should add this to abstract Pager class without finalizing it. I rather suggest to implement abstract function isDeterministic and force any implementation of Pager to set it. WDYT? As this is not BC, I didn't choose this path (any custom implementation might be broken after a patch/minor update).

This refs #8164 but does not finally closes it. I'll update the way SimplePager count results using thresholds in a separate MR. Together they will solve #8164.

I am targeting this branch, because it's BC.

Refs #8164

Changelog

### Added
- Introduces `PagerInterface::isDeterministic` to render yet unknown result count in `SimplePager` properly

@mvhirsch mvhirsch changed the title Enhancement: Introduces PagerInterface::isDeterministic (refs #8164) Enhancement: Introduces PagerInterface::isDeterministic (refs #8164) Aug 26, 2024
*/
public function getMaxPageLinks(): int;

public function isDeterministic(): bool;
Copy link
Member

Choose a reason for hiding this comment

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

This is a good idea but it's a BC break to add a method in an interface.

You have to do like this

* @method array getFormOptions();
* @method bool|null showFilter();
* @method array getLabelTranslationParameters();
* @method bool withAdvancedFilter();

By just adding a @method and it will be mandatory in next major.

<input type="checkbox" name="all_elements" id="{{ admin.uniqid }}_all_elements">
{{ 'all_elements'|trans({}, 'SonataAdminBundle') }}
({{ admin.datagrid.pager.countResults() }})
({{ admin.datagrid.pager.countResults() }}{% if not admin.datagrid.pager.deterministic %}+{% endif %})
Copy link
Member

Choose a reason for hiding this comment

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

Since the method is not mandatory, we might need an internal twig extension

public function isDeterministic(PagerInterface $pager): bool
{
     if (!method_exist($pager, 'isDeterministic')) {
         return true;
     }

     return $pager->isDeterministic();
}


public function isDeterministic(): bool
{
return false;
Copy link
Member

Choose a reason for hiding this comment

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

There is maybe something to compute, because if we are on the last page and there is no next page, we know the exact number of result and we can return true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds legit. I'll return this dynamically depending on currently known information!

@VincentLanglet
Copy link
Member

Hi, Do you encounter issue finishing this PR ?

@mvhirsch
Copy link
Contributor Author

mvhirsch commented Nov 7, 2024

Hi, Do you encounter issue finishing this PR ?

Hey, I wish to, yes. But I'm really busy at the moment, and I dunno when I have some spare time to fix it (maybe in Dec).
Feel free to finish it in the meantime, please.

@github-actions
Copy link

github-actions bot commented May 6, 2025

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 6, 2025
@mvhirsch
Copy link
Contributor Author

mvhirsch commented May 6, 2025

Will do!

@github-actions
Copy link

github-actions bot commented Nov 2, 2025

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 2, 2025
@mvhirsch
Copy link
Contributor Author

mvhirsch commented Nov 4, 2025

bump

@github-actions github-actions bot removed the stale label Nov 4, 2025
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