-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable/Disable Tools/Toolbar (#1896)
* Customised Toolbar Approach --------- Co-authored-by: lrljoe <[email protected]>
- Loading branch information
Showing
9 changed files
with
338 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
title: Tools | ||
weight: 9 | ||
--- | ||
|
||
The Table offers additional configuration to show/hide the Tools/Toolbar sections: | ||
## Tools | ||
Contains: | ||
- Filter Pills | ||
- Sorting Pills | ||
- The Toolbar | ||
|
||
## Toolbar | ||
Contains: | ||
- Actions (if set to Toolbar) | ||
- Column Select dropdown | ||
- Configurable Areas for Toolbar | ||
- Filters Button/Dropdown/Popover | ||
- Pagination dropdown | ||
- Reorder Button | ||
- Search Input | ||
|
||
## Component Available Methods | ||
|
||
### setToolsEnabled | ||
The Default Behaviour, Tools Are Enabled. But will only be rendered if there are available/enabled elements. If the Toolbar is enabled, this takes into account any Toolbar elements that are present. | ||
```php | ||
public function configure(): void | ||
{ | ||
$this->setToolsEnabled(); | ||
} | ||
``` | ||
|
||
### setToolsDisabled | ||
Disables the Tools section, this includes the Toolbar, and Sort/Filter pills | ||
```php | ||
public function configure(): void | ||
{ | ||
$this->setToolsDisabled(); | ||
} | ||
``` | ||
|
||
### setToolBarEnabled | ||
The Default Behaviour, ToolBar is Enabled. But will only be rendered if there are available/enabled elements | ||
```php | ||
public function configure(): void | ||
{ | ||
$this->setToolBarEnabled(); | ||
} | ||
``` | ||
|
||
### setToolBarDisabled | ||
Disables the Toolbar, which contains the Reorder, Filters, Search, Column Select, Pagination buttons/options. Does not impact the Filter/Sort pills (if enabled) | ||
```php | ||
public function configure(): void | ||
{ | ||
$this->setToolBarDisabled(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits\Configuration; | ||
|
||
trait ToolsConfiguration | ||
{ | ||
public function setToolsStatus(bool $status): self | ||
{ | ||
$this->toolsStatus = $status; | ||
|
||
return $this; | ||
} | ||
|
||
public function setToolsEnabled(): self | ||
{ | ||
return $this->setToolsStatus(true); | ||
} | ||
|
||
public function setToolsDisabled(): self | ||
{ | ||
return $this->setToolsStatus(false); | ||
} | ||
|
||
public function setToolBarStatus(bool $status): self | ||
{ | ||
$this->toolBarStatus = $status; | ||
|
||
return $this; | ||
} | ||
|
||
public function setToolBarEnabled(): self | ||
{ | ||
return $this->setToolBarStatus(true); | ||
} | ||
|
||
public function setToolBarDisabled(): self | ||
{ | ||
return $this->setToolBarStatus(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits\Helpers; | ||
|
||
use Livewire\Attributes\Computed; | ||
|
||
trait ToolsHelpers | ||
{ | ||
public function getToolsStatus(): bool | ||
{ | ||
return $this->toolsStatus; | ||
} | ||
|
||
public function getToolBarStatus(): bool | ||
{ | ||
return $this->toolBarStatus; | ||
} | ||
|
||
#[Computed] | ||
public function shouldShowTools(): bool | ||
{ | ||
if ($this->getToolsStatus()) { | ||
if ($this->shouldShowToolBar()) { | ||
return true; | ||
} else { | ||
if ($this->showSortPillsSection()) { // Sort Pills Are Enabled | ||
return true; | ||
} elseif ($this->showFilterPillsSection()) { // Filter Pills Are Enable) | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
#[Computed] | ||
public function shouldShowToolBar(): bool | ||
{ | ||
if ($this->getToolsStatus() == false) { | ||
return false; | ||
} | ||
|
||
if ($this->getToolBarStatus()) { | ||
if ( | ||
$this->hasToolbarConfigurableAreas() || // Has Configured Toolbar Configurable Areas | ||
$this->hasToolbarActions() || // Actions Exist In Toolbar | ||
$this->hasToolbarReorder() || // If Reorder Is Enabled | ||
$this->hasToolbarColumnSelect() || // Column Select Enabled | ||
$this->displayToolbarSearch() || // If Search Is Enabled | ||
$this->displayToolbarFilters() || // If Filters Are Enabled | ||
$this->displayToolbarPagination() // Pagination Selection Is Enabled | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
#[Computed] | ||
public function displayToolbarPagination(): bool | ||
{ | ||
return $this->paginationIsEnabled() && $this->perPageVisibilityIsEnabled(); | ||
} | ||
|
||
#[Computed] | ||
public function displayToolbarSearch(): bool | ||
{ | ||
return $this->searchIsEnabled() && $this->searchVisibilityIsEnabled(); | ||
} | ||
|
||
#[Computed] | ||
public function displayToolbarFilters(): bool | ||
{ | ||
if ($this->filtersAreEnabled() && $this->filtersVisibilityIsEnabled() && $this->hasVisibleFilters()) { | ||
return true; | ||
} elseif ($this->filtersAreEnabled() && $this->showBulkActionsDropdownAlpine() && $this->shouldAlwaysHideBulkActionsDropdownOption() != true) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
protected function hasToolbarColumnSelect(): bool | ||
{ | ||
return $this->columnSelectIsEnabled(); | ||
} | ||
|
||
protected function hasToolbarReorder(): bool | ||
{ | ||
return $this->reorderIsEnabled(); | ||
} | ||
|
||
protected function hasToolbarConfigurableAreas(): bool | ||
{ | ||
return $this->hasConfigurableAreaFor('toolbar-left-end') || $this->hasConfigurableAreaFor('toolbar-left-start') || $this->hasConfigurableAreaFor('toolbar-right-start') || $this->hasConfigurableAreaFor('toolbar-right-end'); | ||
} | ||
|
||
protected function hasToolbarActions(): bool | ||
{ | ||
return $this->hasActions() && $this->showActionsInToolbar(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits; | ||
|
||
use Rappasoft\LaravelLivewireTables\Traits\Configuration\ToolsConfiguration; | ||
use Rappasoft\LaravelLivewireTables\Traits\Helpers\ToolsHelpers; | ||
|
||
trait WithTools | ||
{ | ||
use ToolsConfiguration, | ||
ToolsHelpers; | ||
|
||
protected bool $toolsStatus = true; | ||
|
||
protected bool $toolBarStatus = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests\Traits\Helpers; | ||
|
||
use Rappasoft\LaravelLivewireTables\Tests\TestCase; | ||
|
||
final class ToolsHelpersTest extends TestCase | ||
{ | ||
public function test_can_get_toolbar_status(): void | ||
{ | ||
$this->assertTrue($this->basicTable->getToolBarStatus()); | ||
$this->assertTrue($this->basicTable->getToolsStatus()); | ||
|
||
$this->basicTable->setToolBarDisabled(); | ||
|
||
$this->assertFalse($this->basicTable->getToolBarStatus()); | ||
$this->assertTrue($this->basicTable->getToolsStatus()); | ||
|
||
} | ||
|
||
public function test_can_get_tools_status(): void | ||
{ | ||
$this->assertTrue($this->basicTable->getToolsStatus()); | ||
$this->assertTrue($this->basicTable->getToolBarStatus()); | ||
|
||
$this->basicTable->setToolsDisabled(); | ||
|
||
$this->assertFalse($this->basicTable->getToolsStatus()); | ||
$this->assertTrue($this->basicTable->getToolBarStatus()); | ||
} | ||
|
||
public function test_can_get_tools_should_display(): void | ||
{ | ||
$this->assertTrue($this->basicTable->getToolsStatus()); | ||
$this->assertTrue($this->basicTable->getToolBarStatus()); | ||
$this->assertTrue($this->basicTable->shouldShowTools()); | ||
$this->assertTrue($this->basicTable->shouldShowToolBar()); | ||
|
||
$this->basicTable->setToolsDisabled(); | ||
|
||
$this->assertFalse($this->basicTable->getToolsStatus()); | ||
$this->assertTrue($this->basicTable->getToolBarStatus()); | ||
$this->assertFalse($this->basicTable->shouldShowTools()); | ||
$this->assertFalse($this->basicTable->shouldShowToolBar()); | ||
} | ||
|
||
public function test_can_get_toolbar_display(): void | ||
{ | ||
$this->assertTrue($this->basicTable->getToolsStatus()); | ||
$this->assertTrue($this->basicTable->getToolBarStatus()); | ||
$this->basicTable->setFiltersDisabled(); | ||
$this->basicTable->setSingleSortingDisabled(); | ||
$this->basicTable->setSearchDisabled(); | ||
$this->basicTable->setColumnSelectDisabled(); | ||
$this->basicTable->setPerPageVisibilityDisabled(); | ||
$this->basicTable->setSortingDisabled(); | ||
$this->basicTable->setSortingPillsDisabled(); | ||
|
||
$this->assertTrue($this->basicTable->getToolsStatus()); | ||
$this->assertTrue($this->basicTable->getToolBarStatus()); | ||
$this->assertFalse($this->basicTable->shouldShowToolBar()); | ||
|
||
} | ||
|
||
public function test_can_get_tools_display(): void | ||
{ | ||
$this->assertTrue($this->basicTable->getToolsStatus()); | ||
$this->assertTrue($this->basicTable->getToolBarStatus()); | ||
$this->basicTable->setSearchDisabled() | ||
->setColumnSelectDisabled() | ||
->setPerPageVisibilityDisabled(); | ||
$this->basicTable->setSorts(['id' => 'asc', 'name' => 'desc']); | ||
|
||
$this->assertTrue($this->basicTable->shouldShowToolBar()); | ||
$this->assertTrue($this->basicTable->shouldShowTools()); | ||
|
||
$this->basicTable->setFiltersDisabled(); | ||
|
||
$this->assertFalse($this->basicTable->shouldShowToolBar()); | ||
$this->assertTrue($this->basicTable->shouldShowTools()); | ||
|
||
$this->basicTable->setSortingDisabled(); | ||
|
||
$this->assertFalse($this->basicTable->shouldShowToolBar()); | ||
$this->assertFalse($this->basicTable->shouldShowTools()); | ||
|
||
$this->basicTable->setFiltersEnabled(); | ||
|
||
$this->assertTrue($this->basicTable->shouldShowToolBar()); | ||
$this->assertTrue($this->basicTable->shouldShowTools()); | ||
|
||
$this->basicTable->clearSorts(); | ||
|
||
$this->assertTrue($this->basicTable->shouldShowToolBar()); | ||
$this->assertTrue($this->basicTable->shouldShowTools()); | ||
|
||
$this->basicTable->setFiltersDisabled(); | ||
|
||
$this->assertFalse($this->basicTable->shouldShowToolBar()); | ||
$this->assertFalse($this->basicTable->shouldShowTools()); | ||
|
||
} | ||
} |