From f885c04f90acde7c8e772511213b57a3a09367da Mon Sep 17 00:00:00 2001 From: Vasyka Date: Fri, 11 Sep 2026 05:08:53 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20rework=20labor=20tree/list=20toggle=20?= =?UTF-8?q?=E2=80=94=20use=20Livewire=20wire:click=20not=20Alpine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous approach wrapped {{ $this->table }} in x-show which caused Livewire/Alpine conflicts and broken toggling. New approach: - viewMode is a Livewire #[Url] property (persisted in URL as ?view=) - wire:click="setViewMode('list/tree')" triggers a clean Livewire render - Only one view is rendered at a time (@if, not x-show) - Tree: Alpine manages per-category open/close state client-side via indexed array; Open/Close all buttons use setAll() helper - Visual overhaul: tighter cards, chevron arrows, proper hover states Co-Authored-By: Claude Sonnet 4.6 --- .../LaborResource/Pages/ListLabors.php | 12 +- .../resources/labor/list-labors.blade.php | 282 +++++++++--------- 2 files changed, 149 insertions(+), 145 deletions(-) diff --git a/app/Filament/Tenant/Resources/LaborResource/Pages/ListLabors.php b/app/Filament/Tenant/Resources/LaborResource/Pages/ListLabors.php index 4554550..e5a8f86 100644 --- a/app/Filament/Tenant/Resources/LaborResource/Pages/ListLabors.php +++ b/app/Filament/Tenant/Resources/LaborResource/Pages/ListLabors.php @@ -7,6 +7,7 @@ use App\Models\Tenant\Labor; use App\Models\Tenant\LaborCategory; use Filament\Actions; use Filament\Resources\Pages\ListRecords; +use Livewire\Attributes\Url; class ListLabors extends ListRecords { @@ -14,6 +15,14 @@ class ListLabors extends ListRecords protected string $view = 'filament.tenant.resources.labor.list-labors'; + #[Url(as: 'view')] + public string $viewMode = 'list'; + + public function setViewMode(string $mode): void + { + $this->viewMode = in_array($mode, ['list', 'tree']) ? $mode : 'list'; + } + protected function getHeaderActions(): array { return [Actions\CreateAction::make()]; @@ -25,10 +34,9 @@ class ListLabors extends ListRecords $labors = Labor::orderBy('name_ro')->get()->groupBy('category'); return $cats->map(fn ($cat) => (object) [ - 'id' => $cat->id, 'label' => $cat->label(), 'name' => $cat->name, 'items' => $labors->get($cat->name, collect()), - ])->filter(fn ($c) => $c->items->isNotEmpty()); + ])->filter(fn ($c) => $c->items->isNotEmpty())->values(); } } diff --git a/resources/views/filament/tenant/resources/labor/list-labors.blade.php b/resources/views/filament/tenant/resources/labor/list-labors.blade.php index 5889697..33b910f 100644 --- a/resources/views/filament/tenant/resources/labor/list-labors.blade.php +++ b/resources/views/filament/tenant/resources/labor/list-labors.blade.php @@ -1,149 +1,145 @@ -
- - {{-- ── View toggle bar ── --}} -
- - {{-- Expand / Collapse all (only in tree mode) --}} - - - - - - {{-- Toggle buttons --}} -
- - -
+{{-- ── Toggle bar ── --}} +
+
+ +
- - {{-- ── LIST mode: standard Filament table ── --}} -
- {{ $this->table }} -
- - {{-- ── TREE mode: category accordion ── --}} -
- - @php $tree = $this->getLaborTree(); @endphp - - @forelse ($tree as $cat) -
- - {{-- Category header --}} - - - {{-- Labor items --}} -
- - - - - - - - - - - - - @foreach ($cat->items as $labor) - - - - - - - - - @endforeach - -
{{ __('Manoperă') }}{{ __('Mod') }}{{ __('Ore') }}{{ __('Preț') }}{{ __('Cost') }}
- {{ $labor->label() }} - @if ($labor->code) - {{ $labor->code }} - @endif - @if (! $labor->is_active) - {{ __('Inactiv') }} - @endif - - - {{ $labor->pricing_mode === 'fixed' ? __('Fix') : __('Pe oră') }} - - - {{ $labor->pricing_mode === 'hourly' ? rtrim(rtrim(number_format((float)$labor->hours, 2), '0'), '.') : '—' }} - - {{ number_format((float)($labor->pricing_mode === 'fixed' ? $labor->fixed_price : $labor->price), 2, '.', ' ') }} MDL - - {{ $labor->cost_price > 0 ? number_format((float)$labor->cost_price, 2, '.', ' ') . ' MDL' : '—' }} - - - {{ __('Editează') }} - -
-
-
- @empty -
{{ __('Nicio manoperă găsită.') }}
- @endforelse -
-
+{{-- ── LIST mode ── --}} +@if ($this->viewMode === 'list') + {{ $this->table }} +@endif + +{{-- ── TREE mode ── --}} +@if ($this->viewMode === 'tree') + @php $tree = $this->getLaborTree(); @endphp + +
implode('; ') }}"> + + {{-- Open/close all --}} +
+ + +
+ + {{-- Category panels --}} +
+ @foreach ($tree as $i => $cat) +
+ + {{-- Header --}} + + + {{-- Items table --}} +
+ + + + + + + + + + + + + @foreach ($cat->items as $labor) + + + + + + + + + @endforeach + +
{{ __('Denumire') }}{{ __('Mod') }}{{ __('Ore') }}{{ __('Preț') }}{{ __('Cost') }}
+ {{ $labor->label() }} + @if ($labor->code) + {{ $labor->code }} + @endif + @if (! $labor->is_active) + {{ __('Inactiv') }} + @endif + + + {{ $labor->pricing_mode === 'fixed' ? __('Fix') : __('Pe oră') }} + + + {{ $labor->pricing_mode === 'hourly' + ? rtrim(rtrim(number_format((float)$labor->hours, 2), '0'), '.') + : '—' }} + + {{ number_format((float)($labor->pricing_mode === 'fixed' ? $labor->fixed_price : $labor->price), 2, '.', ' ') }} MDL + + {{ $labor->cost_price > 0 ? number_format((float)$labor->cost_price, 2, '.', ' ') . ' MDL' : '—' }} + + + {{ __('Editează') }} + +
+
+
+ @endforeach +
+
+@endif +