Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/datatable/configurable-areas.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions resources/views/datatable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
</x-livewire-tables::tools>
@endif

@includeWhen(
$this->hasConfigurableAreaFor('after-tools'),
$this->getConfigurableAreaFor('after-tools'),
$this->getParametersForConfigurableArea('after-tools')
)

<x-livewire-tables::table>

<x-slot name="thead">
Expand Down
7 changes: 7 additions & 0 deletions src/Traits/Configuration/ConfigurableAreasConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
trait ConfigurableAreasConfiguration
{
/**
* Set all configurable areas to this array of configuration data
*
* @param array<mixed> $areas
*/
public function setConfigurableAreas(array $areas): self
Expand All @@ -14,6 +16,11 @@ public function setConfigurableAreas(array $areas): self
return $this;
}

/**
* Configure a specific Configurable Area
*
* @param array<mixed> $config
*/
public function setConfigurableArea(string $configurableArea, mixed $config): self
{
if (array_key_exists($configurableArea, $this->configurableAreas)) {
Expand Down
1 change: 1 addition & 0 deletions src/Traits/WithConfigurableAreas.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand Down
21 changes: 0 additions & 21 deletions tests/Unit/Traits/Configuration/ComponentConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
61 changes: 0 additions & 61 deletions tests/Unit/Traits/Helpers/ComponentHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
// {
Expand Down
71 changes: 71 additions & 0 deletions tests/Unit/Traits/Helpers/ConfigurableAreaHelpersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Helpers;

use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
use Rappasoft\LaravelLivewireTables\Tests\TestCase;

final class ConfigurableAreaHelpersTest extends TestCase
{
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,
'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());
}
}