fix: rework labor tree/list toggle — use Livewire wire:click not Alpine

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 <noreply@anthropic.com>
This commit is contained in:
2026-09-11 05:08:53 +00:00
parent 0180f29023
commit f885c04f90
2 changed files with 149 additions and 145 deletions
@@ -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();
}
}