Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3-develop to v3-master #1399

Merged
merged 26 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1d1da19
Beta Fixes - Publishing Views/Localizations. Beta Improvements - Sea…
lrljoe Aug 31, 2023
135297e
Bulk Actions Fix - v3 (#1326)
lrljoe Sep 3, 2023
3967e15
Fix Column Select - Select All state (#1333)
lrljoe Sep 3, 2023
648a6ca
Merge branch 'v3-master' into v3-develop
lrljoe Sep 3, 2023
4ee351e
Add NonArray setAdditionalSelects Test (#1337)
lrljoe Sep 3, 2023
32556cd
Test Additions (#1339)
lrljoe Sep 3, 2023
9ec84f1
Add Third Party Tests (#1340)
lrljoe Sep 3, 2023
74b547c
Third Party Asset Tests (#1341)
lrljoe Sep 4, 2023
b68ab26
Lazy Loading Fix (#1355)
lrljoe Sep 17, 2023
e609f13
Spacing fixes
rappasoft Sep 18, 2023
d6e6512
v3 - Missing Tests - Pagination Related Tests (#1363)
lrljoe Sep 21, 2023
ae87ac2
v3 - Missing Tests - Broken Tables (Missing Primary Key/Builder) (#1362)
lrljoe Sep 21, 2023
e2a3199
v3 - Add setSearchFieldAttribute Options (#1361)
lrljoe Sep 22, 2023
e7c10c1
v3 - Column Select Fixes & Tweaks (#1360)
lrljoe Sep 22, 2023
62db217
Fix ServiceProvider Fault (#1366)
lrljoe Sep 23, 2023
65ce494
V3 Frontend Asset Tweaks (#1371)
lrljoe Sep 26, 2023
19b79b2
V3 - Reordering Fixes (#1373)
lrljoe Sep 26, 2023
9cdf451
Bundler Import Options (#1377)
lrljoe Sep 28, 2023
6c977c4
V3 Restore setTrAttributes (#1378)
lrljoe Oct 1, 2023
1e6c159
Update Reorder Documentation (#1381)
lrljoe Oct 3, 2023
32de139
Merge branch 'v3-master' into v3-develop
lrljoe Oct 3, 2023
66ece40
Update Docs - Advanced Example, Add Including Assets (#1383)
lrljoe Oct 4, 2023
154f726
Fix DateRangeFilter Blade Items (#1394)
lrljoe Oct 6, 2023
16ccfe1
Add setFilterLabelAttributes Capability (#1397)
lrljoe Oct 8, 2023
323deee
Merge branch 'v3-master' into v3-develop
lrljoe Oct 8, 2023
429b54f
v3 - Apply Reorder Sorting When Reordering (#1402)
lrljoe Oct 8, 2023
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
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

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

## [Unreleased] - 3.x Amends
## [3.0.0-beta.1] - 2023-10-08
- Removes superfluous @endphp from the DateRangeFilter blade
- Removes reference to remote/published 3rd party assets
- Add setFilterLabelAttributes Capability Per-Filter
- Fix for reorder sort not applying automatically

## [3.0.0-beta.0] - 3.x Initial Release
- Amending Documentation for Reordering
- Adding capabilities & tests for setTrAttributes
- Force calculation of even/odd only once in reorder mode
Expand All @@ -27,7 +33,6 @@ All notable changes to `laravel-livewire-tables` will be documented in this file

- Add setExcludeDeselectedColumnsFromQueryEnabled and setExcludeDeselectedColumnsFromQueryDisabled methods to configure()

## [Unreleased] - 3.x (beta-0)
- Requirements Change
- Requires LiveWire 3.x
- Requires PHP 8.1+
Expand Down
52 changes: 39 additions & 13 deletions docs/filters/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,26 +332,52 @@ SelectFilter::make('Active')
->setCustomFilterLabel('path.to.blade')
```

You will receive two properties to your blade, filter (the filter instance), and theme (your chosen theme). You may access the filter layout as shown below

Example blade:
You will receive several properties to your blade, explained here:
- $filter (the filter instance)
- $filterLayout ('slide-down' or 'popover')
- $tableName (the table name)
- $isTailwind (bool - is theme Tailwind)
- $isBootstrap (bool - is theme Bootstrap 4 or Bootstrap 5)
- $isBootstrap4 (bool - is theme Bootstrap 4)
- $isBootstrap5 (bool - is theme Bootstrap 5)
- $customLabelAttributes (array -> any customLabel attributes set using setFilterLabelAttributes())

Example label blade:
```php
@aware(['component'])
@props(['filter'])
@props(['filter', 'filterLayout' => 'popover', 'tableName' => 'table', 'isTailwind' => false, 'isBootstrap' => false, 'isBootstrap4' => false, 'isBootstrap5' => false, 'customLabelAttributes' => [])


<label for="{{ $tableName }}-filter-{{ $filter->getKey() }}"

{{
$attributes->merge($customLabelAttributes)
->class(['block text-sm font-medium leading-5 text-gray-700 dark:text-white' => $isTailwind && $customLabelAttributes['default'] ?? true])
->class(['d-block' => $isBootstrap && $filterLayout == 'slide-down' && $customLabelAttributes['default'] ?? true])
->class(['mb-2' => $isBootstrap && $filterLayout == 'popover' && $customLabelAttributes['default'] ?? true])
->except('default')
}}

<label for="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
@class([
'block text-sm font-large leading-5 text-red-700 dark:text-red-700' => $component->isTailwind(),
'd-block' => $component->isBootstrap4() && $component->isFilterLayoutSlideDown(),
'mb-2' => $component->isBootstrap4() && $component->isFilterLayoutPopover(),
'd-block display-4' => $component->isBootstrap5() && $component->isFilterLayoutSlideDown(),
'mb-2 display-4' => $component->isBootstrap5() && $component->isFilterLayoutPopover(),
])
>
{{ $filter->getName() }}
</label>
```

### setFilterLabelAttributes
Set custom attributes for a Filter Label. At present it is recommended to only use this for "class" and "style" attributes to avoid conflicts.

By default, this replaces the default classes on the Filter Label wrapper, if you would like to keep them, set the default flag to true.

```php
TextFilter::make('Name')
->setFilterLabelAttributes(
[
'class' => 'text-xl',
'default' => true,
]
),
```


### Config

If the filter takes any config options, you can set them with the `config` method:
Expand Down
35 changes: 24 additions & 11 deletions resources/views/components/tools/filter-label.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
@aware(['component', 'tableName'])
@props(['filter', 'filterLayout' => 'popover', 'tableName' => 'table'])

<label for="{{ $tableName }}-filter-{{ $filter->getKey() }}"
@class([
'block text-sm font-medium leading-5 text-gray-700 dark:text-white' => $component->isTailwind(),
'd-block' => $component->isBootstrap() && $filterLayout == 'slide-down',
'mb-2' => $component->isBootstrap() && $filterLayout == 'popover',
])
>
{{ $filter->getName() }}
</label>
@props(['filter', 'filterLayout' => 'popover', 'tableName' => 'table', 'isTailwind' => false, 'isBootstrap' => false, 'isBootstrap4' => false, 'isBootstrap5' => false])

@php
$customLabelAttributes = $filter->getFilterLabelAttributes();
@endphp

@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName, 'isTailwind' => $isTailwind, 'isBootstrap' => $isBootstrap, 'isBootstrap4' => $isBootstrap4, 'isBootstrap5' => $isBootstrap5, 'customLabelAttributes' => $customLabelAttributes])
@elseif(!$filter->hasCustomPosition())
<label for="{{ $tableName }}-filter-{{ $filter->getKey() }}"

{{
$attributes->merge($customLabelAttributes)
->class(['block text-sm font-medium leading-5 text-gray-700 dark:text-white' => $isTailwind && $customLabelAttributes['default'] ?? true])
->class(['d-block' => $isBootstrap && $filterLayout == 'slide-down' && $customLabelAttributes['default'] ?? true])
->class(['mb-2' => $isBootstrap && $filterLayout == 'popover' && $customLabelAttributes['default'] ?? true])
->except('default')
}}

>
{{ $filter->getName() }}
</label>

@endif
23 changes: 3 additions & 20 deletions resources/views/components/tools/filters/date-range.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,14 @@
}
}



@endphp

<div x-cloak id="{{ $tableName }}-dateRangeFilter-{{ $filterKey }}" x-data="flatpickrFilter($wire, '{{ $filterKey }}', @js($filter->getConfigs()), $refs.dateRangeInput, '{{ App::currentLocale() }}')" >
@if(config('livewire-tables.remote_third_party_assets'))
@once
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
@endonce
@elseif(config('livewire-tables.published_third_party_assets'))
@once
<script src="/vendor/rappasoft/livewire-tables/js/flatpickr.min.js"></script>
<link rel="stylesheet" href="/vendor/rappasoft/livewire-tables/css/flatpickr.css">
@endonce
@endif


@endphp
<div>
@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(), ['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName])
@elseif(!$filter->hasCustomPosition())
<x-livewire-tables::tools.filter-label :filter="$filter" :filterLayout="$filterLayout" :tableName="$tableName" />
@endif
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />


<div
@class([
Expand All @@ -67,4 +50,4 @@
</div>

</div>
</div>
</div>
9 changes: 3 additions & 6 deletions resources/views/components/tools/filters/date.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<div>
@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(), ['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName])
@elseif(!$filter->hasCustomPosition())
<x-livewire-tables::tools.filter-label :filter="$filter" :filterLayout="$filterLayout" :tableName="$tableName" />
@endif
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />


<div @class([
"rounded-md shadow-sm" => $isTailwind,
Expand All @@ -22,4 +19,4 @@
])
/>
</div>
</div>
</div>
8 changes: 2 additions & 6 deletions resources/views/components/tools/filters/datetime.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<div>
@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(), ['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName])
@elseif(!$filter->hasCustomPosition())
<x-livewire-tables::tools.filter-label :filter="$filter" :filterLayout="$filterLayout" :tableName="$tableName" />
@endif
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />

<div @class([
"rounded-md shadow-sm" => $isTailwind,
Expand All @@ -22,4 +18,4 @@
])
/>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<div>
@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName])
@elseif(!$filter->hasCustomPosition())
<x-livewire-tables::tools.filter-label :filter="$filter" :filterLayout="$filterLayout" :tableName="$tableName" />
@endif
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />


@if ($isTailwind)
<div class="rounded-md shadow-sm">
Expand Down Expand Up @@ -52,4 +49,4 @@ class="{{ $isBootstrap4 ? 'form-control' : 'form-select' }}"
@endforeach
</select>
@endif
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<div>
@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName])
@elseif(!$filter->hasCustomPosition())
<x-livewire-tables::tools.filter-label :filter="$filter" :filterLayout="$filterLayout" :tableName="$tableName" />
@endif
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />


@if ($isTailwind)
<div class="rounded-md">
Expand Down Expand Up @@ -62,4 +59,4 @@ class="form-check-input"
</div>
@endforeach
@endif
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
$currentMax = $maxRange = $filter->getConfig('maxRange');
@endphp
<div id="{{ $tableName }}-numberRange-{{ $filterKey }}" x-data="numberRangeFilter($wire,'{{ $filterKey }}', '{{ $tableName }}-numberRange-{{ $filterKey }}-wrapper', @js($filter->getConfigs()), '{{ $tableName }}-numberRange-{{ $filterKey }}')" x-on:mousedown.away.throttle.2000ms="updateWireable" x-on:touchstart.away.throttle.2000ms="updateWireable" x-on:mouseleave.throttle.2000ms="updateWireable">
@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName ])
@elseif(!$filter->hasCustomPosition())
<x-livewire-tables::tools.filter-label :filter="$filter" :filterLayout="$filterLayout" :tableName="$tableName" />
@endif
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />


<div @class([
'mt-4 h-22 pt-8 pb-4 grid gap-10' => $isTailwind,
Expand Down Expand Up @@ -38,4 +35,4 @@
<div class='range-slider__progress'></div>
</div>
</div>
</div>
</div>
9 changes: 3 additions & 6 deletions resources/views/components/tools/filters/number.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<div>
@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName])
@elseif(!$filter->hasCustomPosition())
<x-livewire-tables::tools.filter-label :filter="$filter" :filterLayout="$filterLayout" :tableName="$tableName" />
@endif
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />


<div @class([
"rounded-md shadow-sm" => $isTailwind,
Expand All @@ -22,4 +19,4 @@
])
/>
</div>
</div>
</div>
8 changes: 2 additions & 6 deletions resources/views/components/tools/filters/select.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<div>
@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName])
@elseif(!$filter->hasCustomPosition())
<x-livewire-tables::tools.filter-label :filter="$filter" :filterLayout="$filterLayout" :tableName="$tableName" />
@endif
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />

<div @class([
'rounded-md shadow-sm' => $isTailwind,
Expand Down Expand Up @@ -32,4 +28,4 @@
@endforeach
</select>
</div>
</div>
</div>
8 changes: 2 additions & 6 deletions resources/views/components/tools/filters/text-field.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<div>
@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName])
@elseif(!$filter->hasCustomPosition())
<x-livewire-tables::tools.filter-label :filter="$filter" :filterLayout="$filterLayout" :tableName="$tableName" />
@endif
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />

<div @class([
"rounded-md shadow-sm" => $isTailwind,
Expand All @@ -22,4 +18,4 @@
])
/>
</div>
</div>
</div>
7 changes: 6 additions & 1 deletion src/Traits/WithData.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ protected function executeQuery(): Collection|CursorPaginator|Paginator|LengthAw
// Moved these from baseQuery to here to avoid pulling all fields when cloning baseQuery.
$this->setBuilder($this->selectFields());

$this->applySorting();
if ($this->currentlyReorderingIsEnabled()) {
$this->setBuilder($this->getBuilder()->orderBy($this->getDefaultReorderColumn(), $this->getDefaultReorderDirection()));
} else {
$this->applySorting();

}

if ($this->paginationIsEnabled()) {
if ($this->isPaginationMethod('standard')) {
Expand Down
2 changes: 2 additions & 0 deletions src/Views/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ abstract class Filter

protected ?string $filterCustomLabel = null;

protected array $filterLabelAttributes = [];

protected ?int $filterSlidedownRow = null;

protected ?int $filterSlidedownColspan = null;
Expand Down
7 changes: 7 additions & 0 deletions src/Views/Traits/Configuration/FilterConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,11 @@ public function setFilterDefaultValue($value): self

return $this;
}

public function setFilterLabelAttributes(array $filterLabelAttributes): self
{
$this->filterLabelAttributes = [...['default' => false], ...$filterLabelAttributes];

return $this;
}
}
10 changes: 10 additions & 0 deletions src/Views/Traits/Helpers/FilterHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,14 @@ public function hasFilterDefaultValue(): bool
{
return ! is_null($this->filterDefaultValue);
}

public function getFilterLabelAttributes(): array
{
return [...['default' => true], ...$this->filterLabelAttributes];
}

public function hasFilterLabelAttributes(): bool
{
return $this->getFilterLabelAttributes() != ['default' => true] && $this->getFilterLabelAttributes() != ['default' => false];
}
}
27 changes: 27 additions & 0 deletions tests/Views/Traits/Helpers/FilterHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,31 @@ public function can_get_filter_custom_filter_pills_blade(): void
$this->assertTrue($filter->hasCustomPillBlade());
$this->assertSame('foo', $filter->getCustomPillBlade());
}

/** @test */
public function can_get_filter_label_attributes(): void
{
$filter1 = TextFilter::make('Filter1');
$filter2 = TextFilter::make('Filter2')->setFilterLabelAttributes(
['class' => 'text-xl', 'default' => true]
);
$filter3 = TextFilter::make('Filter3')->setFilterLabelAttributes(
['class' => 'text-2xl', 'default' => false]
);

$this->assertFalse($filter1->hasFilterLabelAttributes());
$this->assertTrue($filter2->hasFilterLabelAttributes());
$this->assertTrue($filter3->hasFilterLabelAttributes());

$this->assertSame($filter1->getFilterLabelAttributes(), ['default' => true]);
$this->assertSame($filter2->getFilterLabelAttributes(), ['default' => true, 'class' => 'text-xl']);
$this->assertSame($filter3->getFilterLabelAttributes(), ['default' => false, 'class' => 'text-2xl']);

$filter1->setFilterLabelAttributes(
['class' => 'text-3xl', 'default' => false]
);
$this->assertTrue($filter1->hasFilterLabelAttributes());
$this->assertSame($filter1->getFilterLabelAttributes(), ['default' => false, 'class' => 'text-3xl']);

}
}