diff --git a/docs/datatable/configurable-areas.md b/docs/datatable/configurable-areas.md index 4661be63b..489a42cd6 100644 --- a/docs/datatable/configurable-areas.md +++ b/docs/datatable/configurable-areas.md @@ -34,6 +34,7 @@ public function configure(): void 'toolbar-right-end' => 'path.to.my.view', 'before-toolbar' => 'path.to.my.view', 'after-toolbar' => 'path.to.my.view', + 'after-tools' => 'path.to.my.view', 'before-pagination' => 'path.to.my.view', 'after-pagination' => 'path.to.my.view', 'after-wrapper' => 'path.to.my.view', diff --git a/resources/views/datatable.blade.php b/resources/views/datatable.blade.php index 4b4feab5a..5a089ce88 100644 --- a/resources/views/datatable.blade.php +++ b/resources/views/datatable.blade.php @@ -54,6 +54,12 @@ @endif + @includeWhen( + $this->hasConfigurableAreaFor('after-tools'), + $this->getConfigurableAreaFor('after-tools'), + $this->getParametersForConfigurableArea('after-tools') + ) + diff --git a/src/Traits/Configuration/ConfigurableAreasConfiguration.php b/src/Traits/Configuration/ConfigurableAreasConfiguration.php index 043c2964c..aa3f7def6 100644 --- a/src/Traits/Configuration/ConfigurableAreasConfiguration.php +++ b/src/Traits/Configuration/ConfigurableAreasConfiguration.php @@ -5,6 +5,8 @@ trait ConfigurableAreasConfiguration { /** + * Set all configurable areas to this array of configuration data + * * @param array $areas */ public function setConfigurableAreas(array $areas): self @@ -14,6 +16,11 @@ public function setConfigurableAreas(array $areas): self return $this; } + /** + * Configure a specific Configurable Area + * + * @param array $config + */ public function setConfigurableArea(string $configurableArea, mixed $config): self { if (array_key_exists($configurableArea, $this->configurableAreas)) { diff --git a/src/Traits/WithConfigurableAreas.php b/src/Traits/WithConfigurableAreas.php index 4fcf55634..f6956484c 100644 --- a/src/Traits/WithConfigurableAreas.php +++ b/src/Traits/WithConfigurableAreas.php @@ -20,6 +20,7 @@ trait WithConfigurableAreas 'toolbar-right-end' => null, 'before-toolbar' => null, 'after-toolbar' => null, + 'after-tools' => null, 'before-pagination' => null, 'after-pagination' => null, ]; diff --git a/tests/Unit/Traits/Configuration/ComponentConfigurationTest.php b/tests/Unit/Traits/Configuration/ComponentConfigurationTest.php index bd593eeab..901bb04d1 100644 --- a/tests/Unit/Traits/Configuration/ComponentConfigurationTest.php +++ b/tests/Unit/Traits/Configuration/ComponentConfigurationTest.php @@ -294,27 +294,6 @@ public function test_can_set_tr_url_target_advanced(): void $this->assertSame($this->basicTable->getTableRowUrlTarget(2), 'navigate'); } - public function test_can_set_hide_configurable_areas_when_reordering_status(): void - { - $this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus()); - - $this->basicTable->setHideConfigurableAreasWhenReorderingStatus(false); - - $this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus()); - - $this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true); - - $this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus()); - - $this->basicTable->setHideConfigurableAreasWhenReorderingDisabled(); - - $this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus()); - - $this->basicTable->setHideConfigurableAreasWhenReorderingEnabled(); - - $this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true); - } - public function test_no_extra_withs_by_default(): void { $this->assertFalse($this->basicTable->hasExtraWiths()); diff --git a/tests/Unit/Traits/Configuration/ConfigurableAreaConfigurationTest.php b/tests/Unit/Traits/Configuration/ConfigurableAreaConfigurationTest.php index 1be72604e..fd8265783 100644 --- a/tests/Unit/Traits/Configuration/ConfigurableAreaConfigurationTest.php +++ b/tests/Unit/Traits/Configuration/ConfigurableAreaConfigurationTest.php @@ -2,16 +2,97 @@ namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Configuration; +use PHPUnit\Framework\Attributes\DataProvider; use Rappasoft\LaravelLivewireTables\Tests\TestCase; final class ConfigurableAreaConfigurationTest extends TestCase { - public function test_can_set_configurable_area(): void + public static function configurableAreaProvider(): array { + return [ + ['before-tools', 'path.to.my.before-tools.view'], + ['toolbar-left-start', 'path.to.my.toolbar-left-start.view'], + ['toolbar-left-end', 'path.to.my.toolbar-left-end.view'], + ['toolbar-right-start', 'path.to.my.toolbar-right-start.view'], + ['toolbar-right-end', 'path.to.my.toolbar-right-end.view'], + ['before-toolbar', 'path.to.my.before-toolbar.view'], + ['after-toolbar', 'path.to.my.after-toolbar.view'], + ['after-tools', 'path.to.my.after-tools.view'], + ['before-pagination', 'path.to.my.before-pagination.view'], + ['after-pagination', 'path.to.my.after-pagination.view'], + ]; + } + + #[DataProvider('configurableAreaProvider')] + public function test_can_set_configurable_area(string $configurableArea, string $configurableAreaViewPath): void + { + $defaults = [ + 'before-tools' => null, + 'toolbar-left-start' => null, + 'toolbar-left-end' => null, + 'toolbar-right-start' => null, + 'toolbar-right-end' => null, + 'before-toolbar' => null, + 'after-toolbar' => null, + 'after-tools' => null, + 'before-pagination' => null, + 'after-pagination' => null, + ]; + $this->basicTable->setConfigurableAreas($defaults); + + $this->assertNull($this->basicTable->getConfigurableAreaFor($configurableArea)); + + $this->basicTable->setConfigurableArea($configurableArea, $configurableAreaViewPath); + + $this->assertSame($configurableAreaViewPath, $this->basicTable->getConfigurableAreaFor($configurableArea)); + } + + public function test_can_set_multiple_configurable_areas(): void + { + $defaults = [ + 'before-tools' => null, + 'toolbar-left-start' => null, + 'toolbar-left-end' => null, + 'toolbar-right-start' => null, + 'toolbar-right-end' => null, + 'before-toolbar' => null, + 'after-toolbar' => null, + 'after-tools' => null, + 'before-pagination' => null, + 'after-pagination' => null, + ]; + $this->basicTable->setConfigurableAreas($defaults); + $this->assertNull($this->basicTable->getConfigurableAreaFor('before-tools')); + $this->assertNull($this->basicTable->getConfigurableAreaFor('after-toolbar')); + + $this->basicTable->setConfigurableArea('before-tools', 'path.to.before-tools.view'); + $this->assertSame('path.to.before-tools.view', $this->basicTable->getConfigurableAreaFor('before-tools')); + + $this->basicTable->setConfigurableArea('after-toolbar', 'path.to.after-toolbar.view'); + $this->assertSame('path.to.after-toolbar.view', $this->basicTable->getConfigurableAreaFor('after-toolbar')); + $this->assertSame('path.to.before-tools.view', $this->basicTable->getConfigurableAreaFor('before-tools')); + + } + + public function test_can_set_hide_configurable_areas_when_reordering_status(): void + { + $this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus()); + + $this->basicTable->setHideConfigurableAreasWhenReorderingStatus(false); + + $this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus()); + + $this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true); + + $this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus()); + + $this->basicTable->setHideConfigurableAreasWhenReorderingDisabled(); + + $this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus()); - $this->basicTable->setConfigurableArea('before-tools', 'path.to.my.view'); + $this->basicTable->setHideConfigurableAreasWhenReorderingEnabled(); - $this->assertSame('path.to.my.view', $this->basicTable->getConfigurableAreaFor('before-tools')); + $this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true); } } diff --git a/tests/Unit/Traits/Helpers/ComponentHelpersTest.php b/tests/Unit/Traits/Helpers/ComponentHelpersTest.php index d9deb58f4..9a7307c0b 100644 --- a/tests/Unit/Traits/Helpers/ComponentHelpersTest.php +++ b/tests/Unit/Traits/Helpers/ComponentHelpersTest.php @@ -181,67 +181,6 @@ public function test_can_add_additional_selects_nonarray(): void $this->assertEquals(['name', 'updated_at'], $this->basicTable->getAdditionalSelects()); } - public function test_can_get_configurable_areas(): void - { - $this->assertEquals([ - 'before-tools' => null, - 'toolbar-left-start' => null, - 'toolbar-left-end' => null, - 'toolbar-right-start' => null, - 'toolbar-right-end' => null, - 'before-toolbar' => null, - 'after-toolbar' => null, - 'before-pagination' => null, - 'after-pagination' => null, - ], $this->basicTable->getConfigurableAreas()); - - $this->basicTable->setConfigurableAreas([ - 'toolbar-left-start' => 'includes.areas.toolbar-left-start', - ]); - - $this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start')); - - $this->basicTable->setConfigurableAreas([ - 'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']], - ]); - - $this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start')); - } - - public function test_can_get_configurable_area_parameters(): void - { - $this->basicTable->setConfigurableAreas([ - 'toolbar-left-start' => 'includes.areas.toolbar-left-start', - ]); - - $this->assertEquals([], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start')); - - $this->basicTable->setConfigurableAreas([ - 'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']], - ]); - - $this->assertEquals(['param1' => 'hello'], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start')); - } - - public function test_can_get_hide_configurable_areas_when_reordering_status(): void - { - $this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus()); - - $this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled()); - - $this->basicTable->setHideConfigurableAreasWhenReorderingDisabled(); - - $this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled()); - - $this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled()); - - $this->basicTable->setHideConfigurableAreasWhenReorderingEnabled(); - - $this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled()); - - $this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled()); - } - // Exists in DataTableComponentTest // public function test_can_get_dataTable_fingerprint(): void // { diff --git a/tests/Unit/Traits/Helpers/ConfigurableAreaHelpersTest.php b/tests/Unit/Traits/Helpers/ConfigurableAreaHelpersTest.php new file mode 100644 index 000000000..22ef65970 --- /dev/null +++ b/tests/Unit/Traits/Helpers/ConfigurableAreaHelpersTest.php @@ -0,0 +1,71 @@ +assertEquals([ + 'before-tools' => null, + 'toolbar-left-start' => null, + 'toolbar-left-end' => null, + 'toolbar-right-start' => null, + 'toolbar-right-end' => null, + 'before-toolbar' => null, + 'after-toolbar' => null, + 'after-tools' => null, + 'before-pagination' => null, + 'after-pagination' => null, + ], $this->basicTable->getConfigurableAreas()); + + $this->basicTable->setConfigurableAreas([ + 'toolbar-left-start' => 'includes.areas.toolbar-left-start', + ]); + + $this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start')); + + $this->basicTable->setConfigurableAreas([ + 'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']], + ]); + + $this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start')); + } + + public function test_can_get_configurable_area_parameters(): void + { + $this->basicTable->setConfigurableAreas([ + 'toolbar-left-start' => 'includes.areas.toolbar-left-start', + ]); + + $this->assertEquals([], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start')); + + $this->basicTable->setConfigurableAreas([ + 'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']], + ]); + + $this->assertEquals(['param1' => 'hello'], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start')); + } + + public function test_can_get_hide_configurable_areas_when_reordering_status(): void + { + $this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus()); + + $this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled()); + + $this->basicTable->setHideConfigurableAreasWhenReorderingDisabled(); + + $this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled()); + + $this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled()); + + $this->basicTable->setHideConfigurableAreasWhenReorderingEnabled(); + + $this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled()); + + $this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled()); + } +}