Skip to content

Commit a994759

Browse files
committed
Hide filter button if no visible filters
- Add to other templates
1 parent 3c23555 commit a994759

File tree

2 files changed

+48
-34
lines changed

2 files changed

+48
-34
lines changed

resources/views/components/tools/toolbar.blade.php

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class="block w-full border-gray-300 rounded-md shadow-sm transition duration-150
4848
</div>
4949
@endif
5050

51-
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasFilters())
51+
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasVisibleFilters())
5252
<div
5353
@if ($component->isFilterLayoutPopover())
5454
x-data="{ open: false }"
@@ -294,7 +294,7 @@ class="block w-full border-gray-300 rounded-md shadow-sm transition duration-150
294294
</div>
295295
</div>
296296

297-
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasFilters() && $component->isFilterLayoutSlideDown())
297+
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasVisibleFilters() && $component->isFilterLayoutSlideDown())
298298
<div
299299
x-cloak
300300
x-show="filtersOpen"
@@ -365,7 +365,7 @@ class="form-control"
365365
</div>
366366
@endif
367367

368-
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasFilters())
368+
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasVisibleFilters())
369369
<div class="ml-0 ml-md-2 mb-3 mb-md-0">
370370
<div
371371
@if ($component->isFilterLayoutPopover())
@@ -412,13 +412,15 @@ class="dropdown-menu w-100 mt-md-5"
412412
role="menu"
413413
>
414414
@foreach($component->getFilters() as $filter)
415-
<div wire:key="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}" class="p-2">
416-
<label for="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}" class="mb-2">
417-
{{ $filter->getName() }}
418-
</label>
415+
@if($filter->isVisible())
416+
<div wire:key="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}" class="p-2">
417+
<label for="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}" class="mb-2">
418+
{{ $filter->getName() }}
419+
</label>
419420

420-
{{ $filter->render($component) }}
421-
</div>
421+
{{ $filter->render($component) }}
422+
</div>
423+
@endif
422424
@endforeach
423425

424426
@if ($component->hasAppliedFiltersWithValues())
@@ -541,22 +543,24 @@ class="form-control"
541543
</div>
542544
</div>
543545

544-
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasFilters() && $component->isFilterLayoutSlideDown())
546+
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasVisibleFilters() && $component->isFilterLayoutSlideDown())
545547
<div
546548
x-cloak
547549
x-show="filtersOpen"
548550
>
549551
<div class="container">
550552
<div class="row">
551553
@foreach($component->getFilters() as $filter)
552-
<div class="col-12 col-sm-6 col-md-4 col-lg-3 mb-4">
553-
<label for="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
554-
class="d-block">
555-
{{ $filter->getName() }}
556-
</label>
557-
558-
{{ $filter->render($component) }}
559-
</div>
554+
@if($filter->isVisible())
555+
<div class="col-12 col-sm-6 col-md-4 col-lg-3 mb-4">
556+
<label for="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
557+
class="d-block">
558+
{{ $filter->getName() }}
559+
</label>
560+
561+
{{ $filter->render($component) }}
562+
</div>
563+
@endif
560564
@endforeach
561565
</div>
562566
</div>
@@ -604,7 +608,7 @@ class="form-control"
604608
</div>
605609
@endif
606610

607-
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasFilters())
611+
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasVisibleFilters())
608612
<div class="{{ $component->searchIsEnabled() ? 'ms-0 ms-md-2' : '' }} mb-3 mb-md-0">
609613
<div
610614
@if ($component->isFilterLayoutPopover())
@@ -651,13 +655,15 @@ class="dropdown-menu w-100"
651655
role="menu"
652656
>
653657
@foreach($component->getFilters() as $filter)
654-
<div wire:key="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}" class="p-2">
655-
<label for="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}" class="mb-2">
656-
{{ $filter->getName() }}
657-
</label>
658+
@if($filter->isVisible())
659+
<div wire:key="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}" class="p-2">
660+
<label for="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}" class="mb-2">
661+
{{ $filter->getName() }}
662+
</label>
658663

659-
{{ $filter->render($component) }}
660-
</div>
664+
{{ $filter->render($component) }}
665+
</div>
666+
@endif
661667
@endforeach
662668

663669
@if ($component->hasAppliedFiltersWithValues())
@@ -780,22 +786,24 @@ class="form-control"
780786
</div>
781787
</div>
782788

783-
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasFilters() && $component->isFilterLayoutSlideDown())
789+
@if ($component->filtersAreEnabled() && $component->filtersVisibilityIsEnabled() && $component->hasVisibleFilters() && $component->isFilterLayoutSlideDown())
784790
<div
785791
x-cloak
786792
x-show="filtersOpen"
787793
>
788794
<div class="container">
789795
<div class="row">
790796
@foreach($component->getFilters() as $filter)
791-
<div class="col-12 col-sm-6 col-md-4 col-lg-3 mb-4">
792-
<label for="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
793-
class="d-block">
794-
{{ $filter->getName() }}
795-
</label>
796-
797-
{{ $filter->render($component) }}
798-
</div>
797+
@if($filter->isVisible())
798+
<div class="col-12 col-sm-6 col-md-4 col-lg-3 mb-4">
799+
<label for="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
800+
class="d-block">
801+
{{ $filter->getName() }}
802+
</label>
803+
804+
{{ $filter->render($component) }}
805+
</div>
806+
@endif
799807
@endforeach
800808
</div>
801809
</div>

src/Traits/Helpers/FilterHelpers.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ public function hasFilters(): bool
5858
return $this->getFilters()->count();
5959
}
6060

61+
// TODO: Test
62+
public function hasVisibleFilters(): bool
63+
{
64+
return $this->getFilters()->reject(fn(Filter $filter) => $filter->isHidden())->count();
65+
}
66+
6167
public function getFilters(): Collection
6268
{
6369
return collect($this->filters());

0 commit comments

Comments
 (0)