Skip to content

Commit

Permalink
Always hide bulk actions option (#1752)
Browse files Browse the repository at this point in the history
* Add option to "Always Hide Bulk Actions"

* Fix styling

* Fix test function name clash

---------

Co-authored-by: lrljoe <[email protected]>
  • Loading branch information
lrljoe and lrljoe authored Jul 1, 2024
1 parent ea2c8fc commit 2acac1b
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 1 deletion.
35 changes: 35 additions & 0 deletions docs/bulk-actions/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,38 @@ public function configure(): void
]);
}
```

## setShouldAlwaysHideBulkActionsDropdownOption

Allows hiding the Bulk Actions button & menu, regardless of whether there are any items selected, or hideBulkActionsWhenEmptyEnabled behaviour

```php
public function configure(): void
{
$this->setShouldAlwaysHideBulkActionsDropdownOption(true);
}
```


## setShouldAlwaysHideBulkActionsDropdownOptionEnabled

Allows hiding the Bulk Actions button & menu, regardless of whether there are any items selected, or hideBulkActionsWhenEmptyEnabled behaviour

```php
public function configure(): void
{
$this->setShouldAlwaysHideBulkActionsDropdownOptionEnabled();
}
```


## setShouldAlwaysHideBulkActionsDropdownOptionDisabled

Restores the Bulk Actions to default functionality, so it will respect the hideBulkActionsWhenEmptyEnabled behaviour

```php
public function configure(): void
{
$this->setShouldAlwaysHideBulkActionsDropdownOptionDisabled();
}
```
2 changes: 1 addition & 1 deletion resources/views/components/tools/toolbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
@include($component->getConfigurableAreaFor('toolbar-right-start'), $component->getParametersForConfigurableArea('toolbar-right-start'))
@endif

@if ($component->showBulkActionsDropdownAlpine())
@if ($component->showBulkActionsDropdownAlpine() && $this->shouldAlwaysHideBulkActionsDropdownOption != true)
<x-livewire-tables::tools.toolbar.items.bulk-actions />
@endif

Expand Down
21 changes: 21 additions & 0 deletions src/Traits/Configuration/BulkActionsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,25 @@ public function setBulkActionsTdCheckboxAttributes(array $bulkActionsTdCheckboxA

return $this;
}

public function setShouldAlwaysHideBulkActionsDropdownOption(bool $status = false): self
{
$this->alwaysHideBulkActionsDropdownOption = $status;

return $this;
}

public function setShouldAlwaysHideBulkActionsDropdownOptionEnabled(): self
{
$this->setShouldAlwaysHideBulkActionsDropdownOption(true);

return $this;
}

public function setShouldAlwaysHideBulkActionsDropdownOptionDisabled(): self
{
$this->setShouldAlwaysHideBulkActionsDropdownOption(false);

return $this;
}
}
8 changes: 8 additions & 0 deletions src/Traits/Helpers/BulkActionsHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Rappasoft\LaravelLivewireTables\Traits\Helpers;

use Livewire\Attributes\Computed;

trait BulkActionsHelpers
{
public function getBulkActionsStatus(): bool
Expand Down Expand Up @@ -212,4 +214,10 @@ public function getBulkActionsTdCheckboxAttributes(): array
{
return $this->bulkActionsTdCheckboxAttributes ?? ['default' => true];
}

#[Computed]
public function shouldAlwaysHideBulkActionsDropdownOption(): bool
{
return $this->alwaysHideBulkActionsDropdownOption ?? false;
}
}
2 changes: 2 additions & 0 deletions src/Traits/WithBulkActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ trait WithBulkActions

protected array $bulkActionsTdCheckboxAttributes = ['default' => true];

protected bool $alwaysHideBulkActionsDropdownOption = false;

public function bulkActions(): array
{
return property_exists($this, 'bulkActions') ? $this->bulkActions : [];
Expand Down
109 changes: 109 additions & 0 deletions tests/Traits/Visuals/BulkActionsVisualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,113 @@ public function test_bulk_actions_row_shows_correct_for_select_some(): void
->assertSee('do you want to select all')
->assertDontSee('You are currently selecting all');
}*/

public function test_bulk_dropdown_shows_when_necessary_extended(): void
{
Livewire::test(new class extends PetsTable
{
public function configure(): void
{
$this->setPrimaryKey('id');
}

public function bulkActions(): array
{
return ['exportBulk' => 'exportBulk'];
}

public function exportBulk($items)
{
return $items;
}
})->assertSee('Bulk Actions');
}

public function test_bulk_dropdown_shows_when_not_permanently_hidden(): void
{
Livewire::test(new class extends PetsTable
{
public function configure(): void
{
$this->setPrimaryKey('id')
->setShouldAlwaysHideBulkActionsDropdownOption(false);
}

public function bulkActions(): array
{
return ['exportBulk' => 'exportBulk'];
}

public function exportBulk($items)
{
return $items;
}
})->assertSee('Bulk Actions');
}

public function test_bulk_dropdown_hides_when_permanently_hidden(): void
{
Livewire::test(new class extends PetsTable
{
public function configure(): void
{
$this->setPrimaryKey('id')
->setShouldAlwaysHideBulkActionsDropdownOption(true);
}

public function bulkActions(): array
{
return ['exportBulk' => 'exportBulk'];
}

public function exportBulk($items)
{
return $items;
}
})->assertDontSee('Bulk Actions');
}

public function test_bulk_dropdown_shows_when_not_permanently_hidden_disabled(): void
{
Livewire::test(new class extends PetsTable
{
public function configure(): void
{
$this->setPrimaryKey('id')
->setShouldAlwaysHideBulkActionsDropdownOptionDisabled();
}

public function bulkActions(): array
{
return ['exportBulk' => 'exportBulk'];
}

public function exportBulk($items)
{
return $items;
}
})->assertSee('Bulk Actions');
}

public function test_bulk_dropdown_hides_when_permanently_hidden_enabled(): void
{
Livewire::test(new class extends PetsTable
{
public function configure(): void
{
$this->setPrimaryKey('id')
->setShouldAlwaysHideBulkActionsDropdownOptionEnabled();
}

public function bulkActions(): array
{
return ['exportBulk' => 'exportBulk'];
}

public function exportBulk($items)
{
return $items;
}
})->assertDontSee('Bulk Actions');
}
}

0 comments on commit 2acac1b

Please sign in to comment.