Skip to content

Commit 894759d

Browse files
authored
Merge branch 'development' into TidyUpFilterTraits
2 parents 1a4f524 + 5b23dfb commit 894759d

File tree

9 files changed

+182
-89
lines changed

9 files changed

+182
-89
lines changed

docs/datatable/configurable-areas.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function configure(): void
3434
'toolbar-right-end' => 'path.to.my.view',
3535
'before-toolbar' => 'path.to.my.view',
3636
'after-toolbar' => 'path.to.my.view',
37+
'after-tools' => 'path.to.my.view',
3738
'before-pagination' => 'path.to.my.view',
3839
'after-pagination' => 'path.to.my.view',
3940
'after-wrapper' => 'path.to.my.view',

resources/views/components/tools/toolbar/items/search-field.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@class([
55
'mb-3 mb-md-0 input-group' => $isBootstrap,
66
'rounded-md shadow-sm' => $isTailwind,
7-
'flex' => !$this->hasSearchIcon,
7+
'flex' => ($isTailwind && !$this->hasSearchIcon),
88
'relative inline-flex flex-row' => $this->hasSearchIcon,
99
])>
1010

resources/views/datatable.blade.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,23 @@
2828
)
2929

3030
@if($this->shouldShowTools)
31-
<x-livewire-tables::tools>
32-
@if ($this->showSortPillsSection)
33-
<x-livewire-tables::tools.sorting-pills />
31+
<x-livewire-tables::tools>
32+
@if ($this->showSortPillsSection)
33+
<x-livewire-tables::tools.sorting-pills />
34+
</x-livewire-tables::tools>
35+
@endif
36+
37+
@includeWhen(
38+
$this->hasConfigurableAreaFor('after-tools'),
39+
$this->getConfigurableAreaFor('after-tools'),
40+
$this->getParametersForConfigurableArea('after-tools')
41+
)
42+
43+
<x-livewire-tables::table>
44+
45+
<x-slot name="thead">
46+
@if($this->getCurrentlyReorderingStatus)
47+
<x-livewire-tables::table.th.reorder x-cloak x-show="currentlyReorderingStatus" />
3448
@endif
3549
@if($this->showFilterPillsSection)
3650
<x-livewire-tables::tools.filter-pills />

src/Traits/Configuration/ConfigurableAreasConfiguration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
trait ConfigurableAreasConfiguration
66
{
77
/**
8+
* Set all configurable areas to this array of configuration data
9+
*
810
* @param array<mixed> $areas
911
*/
1012
public function setConfigurableAreas(array $areas): self
@@ -14,6 +16,11 @@ public function setConfigurableAreas(array $areas): self
1416
return $this;
1517
}
1618

19+
/**
20+
* Configure a specific Configurable Area
21+
*
22+
* @param array<mixed> $config
23+
*/
1724
public function setConfigurableArea(string $configurableArea, mixed $config): self
1825
{
1926
if (array_key_exists($configurableArea, $this->configurableAreas)) {

src/Traits/WithConfigurableAreas.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ trait WithConfigurableAreas
2020
'toolbar-right-end' => null,
2121
'before-toolbar' => null,
2222
'after-toolbar' => null,
23+
'after-tools' => null,
2324
'before-pagination' => null,
2425
'after-pagination' => null,
2526
];

tests/Unit/Traits/Configuration/ComponentConfigurationTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -294,27 +294,6 @@ public function test_can_set_tr_url_target_advanced(): void
294294
$this->assertSame($this->basicTable->getTableRowUrlTarget(2), 'navigate');
295295
}
296296

297-
public function test_can_set_hide_configurable_areas_when_reordering_status(): void
298-
{
299-
$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());
300-
301-
$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(false);
302-
303-
$this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());
304-
305-
$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true);
306-
307-
$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());
308-
309-
$this->basicTable->setHideConfigurableAreasWhenReorderingDisabled();
310-
311-
$this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());
312-
313-
$this->basicTable->setHideConfigurableAreasWhenReorderingEnabled();
314-
315-
$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true);
316-
}
317-
318297
public function test_no_extra_withs_by_default(): void
319298
{
320299
$this->assertFalse($this->basicTable->hasExtraWiths());

tests/Unit/Traits/Configuration/ConfigurableAreaConfigurationTest.php

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,97 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Configuration;
44

5+
use PHPUnit\Framework\Attributes\DataProvider;
56
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
67

78
final class ConfigurableAreaConfigurationTest extends TestCase
89
{
9-
public function test_can_set_configurable_area(): void
10+
public static function configurableAreaProvider(): array
1011
{
12+
return [
13+
['before-tools', 'path.to.my.before-tools.view'],
14+
['toolbar-left-start', 'path.to.my.toolbar-left-start.view'],
15+
['toolbar-left-end', 'path.to.my.toolbar-left-end.view'],
16+
['toolbar-right-start', 'path.to.my.toolbar-right-start.view'],
17+
['toolbar-right-end', 'path.to.my.toolbar-right-end.view'],
18+
['before-toolbar', 'path.to.my.before-toolbar.view'],
19+
['after-toolbar', 'path.to.my.after-toolbar.view'],
20+
['after-tools', 'path.to.my.after-tools.view'],
21+
['before-pagination', 'path.to.my.before-pagination.view'],
22+
['after-pagination', 'path.to.my.after-pagination.view'],
23+
];
24+
}
25+
26+
#[DataProvider('configurableAreaProvider')]
27+
public function test_can_set_configurable_area(string $configurableArea, string $configurableAreaViewPath): void
28+
{
29+
$defaults = [
30+
'before-tools' => null,
31+
'toolbar-left-start' => null,
32+
'toolbar-left-end' => null,
33+
'toolbar-right-start' => null,
34+
'toolbar-right-end' => null,
35+
'before-toolbar' => null,
36+
'after-toolbar' => null,
37+
'after-tools' => null,
38+
'before-pagination' => null,
39+
'after-pagination' => null,
40+
];
41+
$this->basicTable->setConfigurableAreas($defaults);
42+
43+
$this->assertNull($this->basicTable->getConfigurableAreaFor($configurableArea));
44+
45+
$this->basicTable->setConfigurableArea($configurableArea, $configurableAreaViewPath);
46+
47+
$this->assertSame($configurableAreaViewPath, $this->basicTable->getConfigurableAreaFor($configurableArea));
48+
}
49+
50+
public function test_can_set_multiple_configurable_areas(): void
51+
{
52+
$defaults = [
53+
'before-tools' => null,
54+
'toolbar-left-start' => null,
55+
'toolbar-left-end' => null,
56+
'toolbar-right-start' => null,
57+
'toolbar-right-end' => null,
58+
'before-toolbar' => null,
59+
'after-toolbar' => null,
60+
'after-tools' => null,
61+
'before-pagination' => null,
62+
'after-pagination' => null,
63+
];
64+
$this->basicTable->setConfigurableAreas($defaults);
65+
1166
$this->assertNull($this->basicTable->getConfigurableAreaFor('before-tools'));
67+
$this->assertNull($this->basicTable->getConfigurableAreaFor('after-toolbar'));
68+
69+
$this->basicTable->setConfigurableArea('before-tools', 'path.to.before-tools.view');
70+
$this->assertSame('path.to.before-tools.view', $this->basicTable->getConfigurableAreaFor('before-tools'));
71+
72+
$this->basicTable->setConfigurableArea('after-toolbar', 'path.to.after-toolbar.view');
73+
$this->assertSame('path.to.after-toolbar.view', $this->basicTable->getConfigurableAreaFor('after-toolbar'));
74+
$this->assertSame('path.to.before-tools.view', $this->basicTable->getConfigurableAreaFor('before-tools'));
75+
76+
}
77+
78+
public function test_can_set_hide_configurable_areas_when_reordering_status(): void
79+
{
80+
$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());
81+
82+
$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(false);
83+
84+
$this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());
85+
86+
$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true);
87+
88+
$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());
89+
90+
$this->basicTable->setHideConfigurableAreasWhenReorderingDisabled();
91+
92+
$this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());
1293

13-
$this->basicTable->setConfigurableArea('before-tools', 'path.to.my.view');
94+
$this->basicTable->setHideConfigurableAreasWhenReorderingEnabled();
1495

15-
$this->assertSame('path.to.my.view', $this->basicTable->getConfigurableAreaFor('before-tools'));
96+
$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true);
1697
}
1798
}

tests/Unit/Traits/Helpers/ComponentHelpersTest.php

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -181,67 +181,6 @@ public function test_can_add_additional_selects_nonarray(): void
181181
$this->assertEquals(['name', 'updated_at'], $this->basicTable->getAdditionalSelects());
182182
}
183183

184-
public function test_can_get_configurable_areas(): void
185-
{
186-
$this->assertEquals([
187-
'before-tools' => null,
188-
'toolbar-left-start' => null,
189-
'toolbar-left-end' => null,
190-
'toolbar-right-start' => null,
191-
'toolbar-right-end' => null,
192-
'before-toolbar' => null,
193-
'after-toolbar' => null,
194-
'before-pagination' => null,
195-
'after-pagination' => null,
196-
], $this->basicTable->getConfigurableAreas());
197-
198-
$this->basicTable->setConfigurableAreas([
199-
'toolbar-left-start' => 'includes.areas.toolbar-left-start',
200-
]);
201-
202-
$this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start'));
203-
204-
$this->basicTable->setConfigurableAreas([
205-
'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']],
206-
]);
207-
208-
$this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start'));
209-
}
210-
211-
public function test_can_get_configurable_area_parameters(): void
212-
{
213-
$this->basicTable->setConfigurableAreas([
214-
'toolbar-left-start' => 'includes.areas.toolbar-left-start',
215-
]);
216-
217-
$this->assertEquals([], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start'));
218-
219-
$this->basicTable->setConfigurableAreas([
220-
'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']],
221-
]);
222-
223-
$this->assertEquals(['param1' => 'hello'], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start'));
224-
}
225-
226-
public function test_can_get_hide_configurable_areas_when_reordering_status(): void
227-
{
228-
$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());
229-
230-
$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());
231-
232-
$this->basicTable->setHideConfigurableAreasWhenReorderingDisabled();
233-
234-
$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled());
235-
236-
$this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());
237-
238-
$this->basicTable->setHideConfigurableAreasWhenReorderingEnabled();
239-
240-
$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());
241-
242-
$this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled());
243-
}
244-
245184
// Exists in DataTableComponentTest
246185
// public function test_can_get_dataTable_fingerprint(): void
247186
// {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Helpers;
4+
5+
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
6+
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
7+
8+
final class ConfigurableAreaHelpersTest extends TestCase
9+
{
10+
public function test_can_get_configurable_areas(): void
11+
{
12+
$this->assertEquals([
13+
'before-tools' => null,
14+
'toolbar-left-start' => null,
15+
'toolbar-left-end' => null,
16+
'toolbar-right-start' => null,
17+
'toolbar-right-end' => null,
18+
'before-toolbar' => null,
19+
'after-toolbar' => null,
20+
'after-tools' => null,
21+
'before-pagination' => null,
22+
'after-pagination' => null,
23+
], $this->basicTable->getConfigurableAreas());
24+
25+
$this->basicTable->setConfigurableAreas([
26+
'toolbar-left-start' => 'includes.areas.toolbar-left-start',
27+
]);
28+
29+
$this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start'));
30+
31+
$this->basicTable->setConfigurableAreas([
32+
'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']],
33+
]);
34+
35+
$this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start'));
36+
}
37+
38+
public function test_can_get_configurable_area_parameters(): void
39+
{
40+
$this->basicTable->setConfigurableAreas([
41+
'toolbar-left-start' => 'includes.areas.toolbar-left-start',
42+
]);
43+
44+
$this->assertEquals([], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start'));
45+
46+
$this->basicTable->setConfigurableAreas([
47+
'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']],
48+
]);
49+
50+
$this->assertEquals(['param1' => 'hello'], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start'));
51+
}
52+
53+
public function test_can_get_hide_configurable_areas_when_reordering_status(): void
54+
{
55+
$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());
56+
57+
$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());
58+
59+
$this->basicTable->setHideConfigurableAreasWhenReorderingDisabled();
60+
61+
$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled());
62+
63+
$this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());
64+
65+
$this->basicTable->setHideConfigurableAreasWhenReorderingEnabled();
66+
67+
$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());
68+
69+
$this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled());
70+
}
71+
}

0 commit comments

Comments
 (0)