|
6 | 6 | new class extends Component |
7 | 7 | { |
8 | 8 | /** |
9 | | - * @return array<string, bool> |
| 9 | + * @return array{toggles: Illuminate\Support\Collection<int, array{name: string, title: string, description: string|null, active: bool}>|null} |
10 | 10 | */ |
11 | 11 | public function with(): array |
12 | 12 | { |
13 | 13 | return [ |
14 | | - 'toggles' => auth()->user()->id === 1 ? Toggle::all() : null, |
| 14 | + 'toggles' => auth()->user()->id === 1 |
| 15 | + ? collect(Toggle::all())->map(function (bool $active, string $name): array { |
| 16 | + $experiment = config("toggle.experiments.{$name}", []); |
| 17 | +
|
| 18 | + return [ |
| 19 | + 'name' => $name, |
| 20 | + 'title' => $experiment['title'] ?? $name, |
| 21 | + 'description' => $experiment['description'] ?? null, |
| 22 | + 'active' => $active, |
| 23 | + ]; |
| 24 | + })->values() |
| 25 | + : null, |
15 | 26 | ]; |
16 | 27 | } |
17 | 28 |
|
@@ -52,12 +63,15 @@ public function toggle(string $name, bool $active): void |
52 | 63 | <flux:separator /> |
53 | 64 |
|
54 | 65 | <div class="space-y-4"> |
55 | | - @forelse ($toggles as $name => $active) |
56 | | - <flux:field variant="inline"> |
57 | | - <flux:label class="flex-1">{{ $name }}</flux:label> |
| 66 | + @forelse ($toggles as $toggle) |
| 67 | + <flux:field variant="inline" wire:key="{{ $toggle['name'] }}"> |
| 68 | + <flux:label class="flex-1">{{ $toggle['title'] }}</flux:label> |
| 69 | + @if ($toggle['description']) |
| 70 | + <flux:description>{{ $toggle['description'] }}</flux:description> |
| 71 | + @endif |
58 | 72 | <flux:switch |
59 | | - :checked="$active" |
60 | | - wire:change="toggle('{{ $name }}', $event.target.checked)" |
| 73 | + :checked="$toggle['active']" |
| 74 | + wire:change="toggle('{{ $toggle['name'] }}', $event.target.checked)" |
61 | 75 | /> |
62 | 76 | </flux:field> |
63 | 77 | @empty |
|
0 commit comments