Skip to content

Commit c093efc

Browse files
mkrecek234mvorisek
andauthored
Fix Grid IPP selector (#2017)
Co-authored-by: Michael Voříšek <mvorisek@mvorisek.cz>
1 parent a78b335 commit c093efc

File tree

6 files changed

+36
-21
lines changed

6 files changed

+36
-21
lines changed

.php-cs-fixer.dist.php

-7
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@
5353
// fn => without curly brackets is less readable,
5454
// also prevent bounding of unwanted variables for GC
5555
'use_arrow_functions' => false,
56-
57-
// TODO remove once 3.17.1 is released
58-
// https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/6979
59-
// https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7011
60-
// fixes were merged
61-
'phpdoc_types' => ['groups' => ['simple', 'meta']],
62-
'phpdoc_var_without_name' => false,
6356
])
6457
->setFinder($finder)
6558
->setCacheFile(sys_get_temp_dir() . '/php-cs-fixer.' . md5(__DIR__) . '.cache');

demos/collection/grid.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@
7979
));
8080

8181
// Setting ipp with an array will add an ItemPerPageSelector to paginator.
82-
$grid->setIpp([10, 25, 50, 100]);
82+
$grid->setIpp([10, 100, 1000]);

src/Behat/Context.php

+7
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ function ($matches) {
231231
$selector
232232
);
233233

234+
// add NBSP support for normalize-space() xpath function
235+
$xpath = preg_replace(
236+
'~(?<![\w\-])normalize-space\([^()\'"]*\)~',
237+
'normalize-space(translate($0, \'' . "\u{00a0}" . '\', \' \'))',
238+
$xpath
239+
);
240+
234241
return ['xpath', $xpath];
235242
}
236243

src/Grid.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function setIpp($ipp, $label = 'Items per page:'): void
206206
*
207207
* @return $this
208208
*/
209-
public function addItemsPerPageSelector(array $items = [10, 25, 50, 100], $label = 'Items per page:')
209+
public function addItemsPerPageSelector(array $items = [10, 100, 1000], $label = 'Items per page:')
210210
{
211211
$ipp = (int) $this->container->stickyGet('ipp');
212212
if ($ipp) {

src/ItemsPerPageSelector.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Atk4\Ui;
66

7+
use Atk4\Data\Field;
78
use Atk4\Ui\Js\JsExpression;
89

910
/**
@@ -16,14 +17,9 @@ class ItemsPerPageSelector extends View
1617
public $ui = 'selection compact dropdown';
1718

1819
/** @var list<int> Default page length menu items. */
19-
public $pageLengthItems = [10, 25, 50, 100];
20+
public $pageLengthItems = [10, 100, 1000];
2021

21-
/**
22-
* Default button label.
23-
* - [ipp] will be replace by the number of pages selected.
24-
*
25-
* @var string
26-
*/
22+
/** @var string */
2723
public $label = 'Items per page:';
2824

2925
/** @var int The current number of item per page. */
@@ -32,6 +28,11 @@ class ItemsPerPageSelector extends View
3228
/** @var Callback|null The callback function. */
3329
public $cb;
3430

31+
private function formatInteger(int $value): string
32+
{
33+
return $this->getApp()->uiPersistence->typecastSaveField(new Field(['type' => 'integer']), $value);
34+
}
35+
3536
protected function init(): void
3637
{
3738
parent::init();
@@ -45,7 +46,7 @@ protected function init(): void
4546
if (!$this->currentIpp) {
4647
$this->currentIpp = $this->pageLengthItems[0];
4748
}
48-
$this->set((string) $this->currentIpp);
49+
$this->set($this->formatInteger($this->currentIpp));
4950
}
5051

5152
/**
@@ -59,8 +60,7 @@ public function onPageLengthSelect(\Closure $fx): void
5960
{
6061
$this->cb->set(function () use ($fx) {
6162
$ipp = isset($_GET['ipp']) ? (int) $_GET['ipp'] : null;
62-
// $this->pageLength->set(preg_replace("/\[ipp\]/", $ipp, $this->label));
63-
$this->set($ipp); // @phpstan-ignore-line TODO https://github.com/atk4/ui/issues/2016
63+
$this->set($this->formatInteger($ipp));
6464
$reload = $fx($ipp);
6565
if ($reload) {
6666
$this->getApp()->terminateJson($reload);
@@ -71,8 +71,8 @@ public function onPageLengthSelect(\Closure $fx): void
7171
protected function renderView(): void
7272
{
7373
$menuItems = [];
74-
foreach ($this->pageLengthItems as $key => $item) {
75-
$menuItems[] = ['name' => $item, 'value' => $item];
74+
foreach ($this->pageLengthItems as $item) {
75+
$menuItems[] = ['name' => $this->formatInteger($item), 'value' => $item];
7676
}
7777

7878
$function = new JsExpression('function (value, text, item) {

tests-behat/grid.feature

+15
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,18 @@ Feature: Grid
6161
When I click using selector "//th.sortable[//div[text()='Name']]"
6262
Then I should see "Andorra"
6363
Then I should not see "Zambia"
64+
65+
Scenario: IPP selector
66+
Then I should see "Andorra"
67+
Then I should not see "China"
68+
Then I should not see "Zambia"
69+
When I click using selector "//div.ui.dropdown.compact"
70+
When I click using selector "//div.ui.dropdown.compact//div.item[text()='100']"
71+
Then I should see "Andorra"
72+
Then I should see "China"
73+
Then I should not see "Zambia"
74+
When I click using selector "//div.ui.dropdown.compact"
75+
When I click using selector "//div.ui.dropdown.compact//div.item[text()[normalize-space()='1 000']]"
76+
Then I should see "Andorra"
77+
Then I should see "China"
78+
Then I should see "Zambia"

0 commit comments

Comments
 (0)