Skip to content

Commit

Permalink
Merge pull request #1579 from rappasoft/develop
Browse files Browse the repository at this point in the history
## [v3.1.4] - 2023-12-04
### New Features
- Add capability to hide Column Label by @lrljoe in #1512
- Add capability to set a custom script path for the scripts/styles by @lrljoe in #1557
- Added rowsRetrieved Lifecycle Hook, expanded documentation for Lifecycle Hooks

### Bug Fixes
- Added missing tailwind background colour class for when hovering over the clear button in dark mode by @slakbal in #1553
- Fixed extraneous space in config.php by @viliusvsx in in #1577
- Changed table default vertical overflow to auto by @dmyers in #1573
- Fix footer rendering issue with extra td displayed depending on bulk action statuses

### Tweaks
- Create additional Exception Classes (NoColumnsException, NoSearchableColumnsException, NoSortableColumnsException)
- Revert previous splitting of JS Files
- Add capability to customise Bulk Actions Styling with tests by @lrljoe in #1564
  - TH Classes
  - TH Checkbox Classes
  - TD Classes
  - TD Checkbox Classes
  • Loading branch information
lrljoe authored Dec 4, 2023
2 parents df31c86 + c12ce7c commit aec86d1
Show file tree
Hide file tree
Showing 19 changed files with 338 additions and 28 deletions.
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@

All notable changes to `laravel-livewire-tables` will be documented in this file

## UNRELEASED
## [v3.1.4] - 2023-12-04
### New Features
- Add capability to hide Column Label by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1512
- Add capability to set a custom script path for the scripts/styles by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1557
- Added rowsRetrieved Lifecycle Hook, expanded documentation for Lifecycle Hooks

### Bug Fixes
- Added missing tailwind background colour class for when hovering over the clear button in dark mode by @slakbal in https://github.com/rappasoft/laravel-livewire-tables/pull/1553
- Add capability to hide Column Label by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1512
- Fixed extraneous space in config.php by @viliusvsx in in https://github.com/rappasoft/laravel-livewire-tables/pull/1577
- Changed table default vertical overflow to auto by @dmyers in https://github.com/rappasoft/laravel-livewire-tables/pull/1573
- Fix footer rendering issue with extra td displayed depending on bulk action statuses

### Tweaks
- Create additional Exception Classes (NoColumnsException, NoSearchableColumnsException, NoSortableColumnsException)
- Revert previous splitting of JS Files
- Add capability to customise Bulk Actions Styling with tests by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1564
- TH Classes
- TH Checkbox Classes
- TD Classes
- TD Checkbox Classes

## [v3.1.3] - 2023-11-03
- Add additional Lifecycle Hook by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1534
Expand Down
2 changes: 1 addition & 1 deletion config/livewire-tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Enable Blade Directives (Not required if automatically injecting or using bundler approaches)
*/
'enable_blade_directives ' => false,
'enable_blade_directives' => false,

/**
* Customise Script & Styles Paths
Expand Down
55 changes: 55 additions & 0 deletions docs/bulk-actions/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,58 @@ public function configure(): void
}
```

## setBulkActionsThAttributes

You may pass an array to this method, which allows you to pass Custom Attributes into the table header

```php
public function configure(): void
{
$this->setBulkActionsThAttributes([
'class' => 'bg-red-500',
'default' => false
]);
}
```

## setBulkActionsThCheckboxAttributes

You may pass an array to this method, which allows you to pass Custom Attributes into the Select All/None checkbox in the Table Header

```php
public function configure(): void
{
$this->setBulkActionsThCheckboxAttributes([
'class' => 'bg-blue-500',
'default' => false
]);
}
```

## setBulkActionsTdAttributes

You may pass an array to this method, which allows you to pass Custom Attributes into the td containing the Bulk Actions Checkbox for the row

```php
public function configure(): void
{
$this->setBulkActionsTdAttributes([
'class' => 'bg-green-500',
'default' => true
]);
}
```

## setBulkActionsTdCheckboxAttributes

You may pass an array to this method, which allows you to pass Custom Attributes into the Bulk Actions Checkbox for the row

```php
public function configure(): void
{
$this->setBulkActionsTdCheckboxAttributes([
'class' => 'bg-green-500',
'default' => true
]);
}
```
25 changes: 25 additions & 0 deletions docs/misc/lifecycle-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ weight: 7

With the migration to Livewire 3, there we are implementing several Lifecycle Hooks to assist with re-using methods across multiple Table Components.

You may use these either in your Table Component, or in a trait

## configuring
This is called immediately prior to the configure() method being called

Expand All @@ -16,3 +18,26 @@ This is called prior to setting up the available Columns via the columns() metho

## columnsSet
This is called immediately after the Columns are set up

## rowsRetrieved
This is called immediately after the query is executed, and is passed the result from the executed query.

## Use in Traits
To use these in a trait, append the Lifecycle Hook with your trait name, e.g.

```php
trait StandardTableMethods
{

protected function configuringStandardTableMethods()
{
// Your standard configure() options go here, anything set here will be over-ridden by the configure() method
}

protected function configuredStandardTableMethods()
{
// Your standard configure() options go here, anything set here will override those set in the configure() method
}

}
```
2 changes: 1 addition & 1 deletion resources/views/components/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div
wire:key="{{ $tableName }}-twrap"
{{ $attributes->merge($customAttributes['wrapper'])
->class(['shadow overflow-y-scroll border-b border-gray-200 dark:border-gray-700 sm:rounded-lg' => $customAttributes['wrapper']['default'] ?? true])
->class(['shadow overflow-y-auto border-b border-gray-200 dark:border-gray-700 sm:rounded-lg' => $customAttributes['wrapper']['default'] ?? true])
->except('default') }}
>
<table
Expand Down
19 changes: 13 additions & 6 deletions resources/views/components/table/td/bulk-actions.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
@aware(['component', 'tableName'])
@props(['row', 'rowIndex'])

@php($theme = $component->getTheme())
@php
$customAttributes = $component->getBulkActionsTdAttributes();
$bulkActionsTdCheckboxAttributes = $component->getBulkActionsTdCheckboxAttributes();
$theme = $component->getTheme();
@endphp

@if ($component->bulkActionsAreEnabled() && $component->hasBulkActions())
<x-livewire-tables::table.td.plain wire:key="{{ $tableName }}-tbody-td-bulk-actions-td-{{ $row->{$this->getPrimaryKey()} }}" :displayMinimisedOnReorder="true" >
<x-livewire-tables::table.td.plain wire:key="{{ $tableName }}-tbody-td-bulk-actions-td-{{ $row->{$this->getPrimaryKey()} }}" :displayMinimisedOnReorder="true" :$customAttributes>
<div @class([
'inline-flex rounded-md shadow-sm' => $theme === 'tailwind',
'form-check' => $theme === 'bootstrap-5',
Expand All @@ -16,10 +20,13 @@
wire:loading.attr.delay="disabled"
value="{{ $row->{$this->getPrimaryKey()} }}"
type="checkbox"
@class([
'rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => $theme === 'tailwind',
'form-check-input' => $theme === 'bootstrap-5',
])
{{
$attributes->merge($bulkActionsTdCheckboxAttributes)->class([
'rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => ($theme === 'tailwind') && ($bulkActionsTdCheckboxAttributes['default'] ?? true),
'form-check-input' => ($theme === 'bootstrap-5') && ($bulkActionsTdCheckboxAttributes['default'] ?? true),
'except' => 'default',
])
}}
/>
</div>
</x-livewire-tables::table.td.plain>
Expand Down
20 changes: 13 additions & 7 deletions resources/views/components/table/th/bulk-actions.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
@aware(['component', 'tableName'])
@php($theme = $component->getTheme())
@php
$customAttributes = $component->getBulkActionsThAttributes();
$bulkActionsThCheckboxAttributes = $component->getBulkActionsThCheckboxAttributes();
$theme = $component->getTheme();
@endphp

@if ($component->bulkActionsAreEnabled() && $component->hasBulkActions())
<x-livewire-tables::table.th.plain wire:key="{{ $tableName }}-thead-bulk-actions" :displayMinimisedOnReorder="true">
<x-livewire-tables::table.th.plain wire:key="{{ $tableName }}-thead-bulk-actions" :displayMinimisedOnReorder="true" :$customAttributes>
<div
x-data="{newSelectCount: 0, indeterminateCheckbox: false, bulkActionHeaderChecked: false}"
x-init="$watch('selectedItems', value => indeterminateCheckbox = (value.length > 0 && value.length < paginationTotalItemCount))"
Expand All @@ -17,11 +21,13 @@
x-on:click="if(selectedItems.length == paginationTotalItemCount) { $el.indeterminate = false; $wire.clearSelected(); bulkActionHeaderChecked = false; } else { bulkActionHeaderChecked = true; $el.indeterminate = false; $wire.setAllSelected(); }"
type="checkbox"
:checked="selectedItems.length == paginationTotalItemCount"

@class([
'rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => $theme === 'tailwind',
'form-check-input' => $theme === 'bootstrap-5',
])
{{
$attributes->merge($bulkActionsThCheckboxAttributes)->class([
'rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => ($theme === 'tailwind') && ($bulkActionsThCheckboxAttributes['default'] ?? true),
'form-check-input' => ($theme === 'bootstrap-5') && ($bulkActionsThCheckboxAttributes['default'] ?? true),
'except' => 'default',
])
}}
/>
</div>
</x-livewire-tables::table.th.plain>
Expand Down
12 changes: 7 additions & 5 deletions resources/views/components/table/th/plain.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@aware(['component'])
@props(['displayMinimisedOnReorder' => false, 'hideUntilReorder' => false])
@props(['displayMinimisedOnReorder' => false, 'hideUntilReorder' => false, 'customAttributes' => ['default' => true]])

<th x-cloak {{ $attributes }} scope="col"
@class([
'table-cell px-3 py-2 md:px-6 md:py-3 text-center md:text-left bg-gray-50 dark:bg-gray-800 laravel-livewire-tables-reorderingMinimised' => $component->isTailwind(),
'laravel-livewire-tables-reorderingMinimised' => ($component->isBootstrap())
])
{{
$attributes->merge($customAttributes)->class([
'table-cell px-3 py-2 md:px-6 md:py-3 text-center md:text-left bg-gray-50 dark:bg-gray-800 laravel-livewire-tables-reorderingMinimised' => ($component->isTailwind()) && ($customAttributes['default'] ?? true),
'laravel-livewire-tables-reorderingMinimised' => ($component->isBootstrap()) && ($customAttributes['default'] ?? true),
])
}}
@if($hideUntilReorder) :class="!reorderDisplayColumn && 'w-0 p-0 hidden'" @endif
>
{{ $slot }}
Expand Down
12 changes: 7 additions & 5 deletions resources/views/components/table/tr/footer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
:customAttributes="$this->getFooterTrAttributes($rows)"
wire:key="{{ $tableName .'-footer' }}"
>
{{-- TODO: Remove --}}
<x-livewire-tables::table.td.plain x-cloak x-show="currentlyReorderingStatus" wire:key="{{ $tableName . '-footer-hidden-test' }}" />
{{-- Adds a Column For Bulk Actions--}}
@if (!$this->bulkActionsAreEnabled() || !$this->hasBulkActions())
<x-livewire-tables::table.td.plain x-cloak x-show="currentlyReorderingStatus" wire:key="{{ $tableName . '-footer-bulkactions-1' }}" />
@elseif ($this->bulkActionsAreEnabled() && $this->hasBulkActions())
<x-livewire-tables::table.td.plain wire:key="{{ $tableName . '-footer-bulkactions-2' }}" />
@endif

{{-- Adds a Column If Collapsing Columns Exist --}}
@if ($this->collapsingColumnsAreEnabled() && $this->hasCollapsedColumns())
<x-livewire-tables::table.td.collapsed-columns :displayMinimisedOnReorder="true" rowIndex="-1" :hidden="true" wire:key="{{ $tableName.'-footer-collapse' }}" />
@endif

{{-- TODO: Remove --}}
<x-livewire-tables::table.td.plain wire:key="{{ $tableName . '-footer-hidden-tes2t' }}" />

@foreach($this->getColumns() as $colIndex => $column)
@continue($column->isHidden())
@continue($this->columnSelectIsEnabled() && ! $this->columnSelectIsEnabledForColumn($column))
Expand Down
3 changes: 2 additions & 1 deletion src/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ abstract public function configure(): void;
abstract public function columns(): array;

/**
* The base query.
* The base query - typically overridden in child components
*/
public function builder(): Builder
{
if ($this->hasModel()) {
return $this->getModel()::query()->with($this->getRelationships());
}

// If model does not exist
throw new DataTableConfigurationException('You must either specify a model or implement the builder method.');
}

Expand Down
7 changes: 7 additions & 0 deletions src/Exceptions/NoColumnsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Exceptions;

class NoColumnsException extends \Exception
{
}
7 changes: 7 additions & 0 deletions src/Exceptions/NoSearchableColumnsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Exceptions;

class NoSearchableColumnsException extends \Exception
{
}
7 changes: 7 additions & 0 deletions src/Exceptions/NoSortableColumnsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Exceptions;

class NoSortableColumnsException extends \Exception
{
}
40 changes: 40 additions & 0 deletions src/Traits/Configuration/BulkActionsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,44 @@ public function setBulkActionDefaultConfirmationMessage(string $defaultConfirmat

return $this;
}

/**
* Used to set attributes for the <th> for Bulk Actions
*/
public function setBulkActionsThAttributes(array $bulkActionsThAttributes): self
{
$this->bulkActionsThAttributes = [...$this->bulkActionsThAttributes, ...$bulkActionsThAttributes];

return $this;
}

/**
* Used to set attributes for the Bulk Actions Checkbox in the <th>
*/
public function setBulkActionsThCheckboxAttributes(array $bulkActionsThCheckboxAttributes): self
{
$this->bulkActionsThCheckboxAttributes = [...$this->bulkActionsThCheckboxAttributes, ...$bulkActionsThCheckboxAttributes];

return $this;
}

/**
* Used to set attributes for the Bulk Actions TD in the Row
*/
public function setBulkActionsTdAttributes(array $bulkActionsTdAttributes): self
{
$this->bulkActionsTdAttributes = [...$this->bulkActionsTdAttributes, ...$bulkActionsTdAttributes];

return $this;
}

/**
* Used to set attributes for the Bulk Actions Checkbox in the Row
*/
public function setBulkActionsTdCheckboxAttributes(array $bulkActionsTdCheckboxAttributes): self
{
$this->bulkActionsTdCheckboxAttributes = [...$this->bulkActionsTdCheckboxAttributes, ...$bulkActionsTdCheckboxAttributes];

return $this;
}
}
40 changes: 40 additions & 0 deletions src/Traits/Helpers/BulkActionsHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,44 @@ public function getBulkActionDefaultConfirmationMessage(): string
{
return isset($this->bulkActionConfirmDefaultMessage) ? $this->bulkActionConfirmDefaultMessage : __('Bulk Actions Confirm');
}

/**
* Used to get attributes for the <th> for Bulk Actions
*
* @return array<mixed>
*/
public function getBulkActionsThAttributes(): array
{
return $this->bulkActionsThAttributes ?? ['default' => true];
}

/**
* Used to get attributes for the Checkbox for Bulk Actions TH
*
* @return array<mixed>
*/
public function getBulkActionsThCheckboxAttributes(): array
{
return $this->bulkActionsThCheckboxAttributes ?? ['default' => true];
}

/**
* Used to get attributes for the Bulk Actions TD
*
* @return array<mixed>
*/
public function getBulkActionsTdAttributes(): array
{
return $this->bulkActionsTdAttributes ?? ['default' => true];
}

/**
* Used to get attributes for the Bulk Actions TD
*
* @return array<mixed>
*/
public function getBulkActionsTdCheckboxAttributes(): array
{
return $this->bulkActionsTdCheckboxAttributes ?? ['default' => true];
}
}
Loading

0 comments on commit aec86d1

Please sign in to comment.