Fix: Address 'Too few arguments' error in settings catalog view

This commit is contained in:
Ahmed Darrazi 2025-12-13 22:56:45 +01:00
parent 79636c13c5
commit 06382aed01

View File

@ -0,0 +1,160 @@
@php
use Illuminate\Support\Str;
use function Filament\Support\evaluate;
// Normalize incoming state from Filament ViewEntry. Accept multiple shapes:
// - $groups passed directly
// - $state as array with ['groups' => [...]]
// - $state as JSON string
// - $state as a Closure
$groups = [];
$searchQuery = $searchQuery ?? '';
// If $state is a closure, resolve it first.
$state = evaluate($state);
if (isset($groups) && is_array($groups) && count($groups) > 0) {
// $groups already provided by caller
// leave as-is
} elseif (isset($state)) {
if (is_string($state) && Str::startsWith(trim($state), '{')) {
$decoded = json_decode($state, true);
if (is_array($decoded)) {
$groups = $decoded['groups'] ?? $decoded;
}
} elseif (is_array($state)) {
$groups = $state['groups'] ?? $state;
} elseif (is_object($state)) {
$arr = (array) $state;
$groups = $arr['groups'] ?? $arr;
}
}
// Ensure groups is an array
if (! is_array($groups)) {
$groups = [];
}
@endphp
<div class="space-y-4">
@if(empty($groups))
<div class="text-center py-8">
<p class="text-gray-500 dark:text-gray-400">No settings available</p>
</div>
@else
@foreach($groups as $groupIndex => $group)
@php
// Filter settings by search query
$filteredSettings = collect($group['settings'] ?? [])->filter(function($setting) use ($searchQuery) {
if (empty($searchQuery)) {
return true;
}
$searchLower = strtolower($searchQuery);
return str_contains(strtolower($setting['label'] ?? ''), $searchLower) ||
str_contains(strtolower($setting['value_display'] ?? ''), $searchLower);
})->all();
$settingCount = count($filteredSettings);
@endphp
@if($settingCount > 0)
<x-filament::section
:heading="$group['title'] ?? 'Settings'"
:description="$group['description'] ?? null"
collapsible
:collapsed="$groupIndex > 0"
>
<x-slot name="headerEnd">
<span class="text-sm text-gray-500 dark:text-gray-400">
{{ $settingCount }} {{ Str::plural('setting', $settingCount) }}
</span>
</x-slot>
<div class="space-y-3">
@foreach($filteredSettings as $setting)
<div class="flex items-start justify-between py-2 border-b border-gray-200 dark:border-gray-700 last:border-0">
<div class="flex-1 pr-4">
<div class="flex items-center gap-2">
<span class="font-medium text-gray-900 dark:text-gray-100">
{{ $setting['label'] }}
</span>
@if($setting['is_fallback'] ?? false)
<x-filament::badge color="warning" size="sm">
Definition not cached
</x-filament::badge>
@endif
</div>
@if(!empty($setting['help_text']))
<p class="text-sm text-gray-600 dark:text-gray-400 mt-1">
{{ Str::limit($setting['help_text'], 200) }}
</p>
@endif
</div>
<div class="flex items-center gap-2">
<div class="text-right">
@if(is_bool($setting['value_raw']))
<x-filament::badge :color="$setting['value_raw'] ? 'success' : 'gray'">
{{ $setting['value_display'] }}
</x-filament::badge>
@elseif(is_int($setting['value_raw']))
<span class="font-mono text-sm text-gray-900 dark:text-gray-100">
{{ $setting['value_display'] }}
</span>
@else
<span class="text-sm text-gray-900 dark:text-gray-100">
{{ $setting['value_display'] }}
</span>
@endif
</div>
@if(strlen($setting['value_display'] ?? '') > 50)
<button
type="button"
x-data="{ copied: false }"
x-on:click="
navigator.clipboard.writeText('{{ addslashes($setting['value_display']) }}');
copied = true;
setTimeout(() => copied = false, 2000);
"
class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300"
title="Copy value"
>
<svg x-show="!copied" class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
<svg x-show="copied" class="w-4 h-4 text-success-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
</svg>
</button>
@endif
</div>
</div>
@endforeach
</div>
</x-filament::section>
@endif
@endforeach
@if(collect($groups)->sum(fn($g) => count(collect($g['settings'] ?? [])->filter(function($s) use ($searchQuery) {
if (empty($searchQuery)) return true;
$searchLower = strtolower($searchQuery);
return str_contains(strtolower($s['label'] ?? ''), $searchLower) ||
str_contains(strtolower($s['value_display'] ?? ''), $searchLower);
}))) === 0)
<div class="text-center py-8">
<p class="text-gray-500 dark:text-gray-400">No settings match your search</p>
<button
type="button"
wire:click="$set('search', '')"
class="mt-2 text-sm text-primary-600 hover:text-primary-700 dark:text-primary-400"
>
Clear search
</button>
</div>
@endif
@endif
</div>