diff --git a/app/Filament/Resources/PolicyResource.php b/app/Filament/Resources/PolicyResource.php index 871cfa5..c132df3 100644 --- a/app/Filament/Resources/PolicyResource.php +++ b/app/Filament/Resources/PolicyResource.php @@ -52,8 +52,25 @@ public static function infolist(Schema $schema): Schema // For Settings Catalog policies: Tabs with Settings table + JSON viewer Tabs::make('policy_content') + ->activeTab(1) + ->persistTabInQueryString() ->tabs([ + Tab::make('General') + ->id('general') + ->schema([ + ViewEntry::make('policy_general') + ->label('') + ->view('filament.infolists.entries.policy-general') + ->state(function (Policy $record) { + $normalized = static::normalizedPolicyState($record); + $split = static::splitGeneralBlock($normalized); + + return $split['general']; + }), + ]) + ->visible(fn (Policy $record) => $record->versions()->exists()), Tab::make('Settings') + ->id('settings') ->schema([ ViewEntry::make('settings_catalog') ->label('') @@ -87,20 +104,8 @@ public static function infolist(Schema $schema): Schema ->helperText('This policy has been inventoried but no configuration snapshot has been captured yet.') ->visible(fn (Policy $record) => ! $record->versions()->exists()), ]), - Tab::make('General') - ->schema([ - ViewEntry::make('policy_general') - ->label('') - ->view('filament.infolists.entries.policy-general') - ->state(function (Policy $record) { - $normalized = static::normalizedPolicyState($record); - $split = static::splitGeneralBlock($normalized); - - return $split['general']; - }), - ]) - ->visible(fn (Policy $record) => $record->versions()->exists()), Tab::make('JSON') + ->id('json') ->schema([ ViewEntry::make('snapshot_json') ->view('filament.infolists.entries.snapshot-json') @@ -336,12 +341,15 @@ private static function latestSnapshot(Policy $record): array */ private static function normalizedPolicyState(Policy $record): array { - static $cache = []; + $cacheKey = 'tenantpilot.normalizedPolicyState.'.(string) $record->getKey(); + $request = request(); - $cacheKey = (string) $record->getKey(); + if ($request->attributes->has($cacheKey)) { + $cached = $request->attributes->get($cacheKey); - if (isset($cache[$cacheKey])) { - return $cache[$cacheKey]; + if (is_array($cached)) { + return $cached; + } } $snapshot = static::latestSnapshot($record); @@ -355,7 +363,7 @@ private static function normalizedPolicyState(Policy $record): array $normalized['context'] = 'policy'; $normalized['record_id'] = (string) $record->getKey(); - $cache[$cacheKey] = $normalized; + $request->attributes->set($cacheKey, $normalized); return $normalized; } diff --git a/resources/views/filament/infolists/entries/normalized-settings.blade.php b/resources/views/filament/infolists/entries/normalized-settings.blade.php index 0e03699..aa374b0 100644 --- a/resources/views/filament/infolists/entries/normalized-settings.blade.php +++ b/resources/views/filament/infolists/entries/normalized-settings.blade.php @@ -25,8 +25,18 @@ @endif @if (! empty($settingsTableRows)) -
-
{{ is_array($settingsTable) ? ($settingsTable['title'] ?? 'Settings') : 'Settings' }}
+ @php + $settingsTableTitle = is_array($settingsTable) ? ($settingsTable['title'] ?? null) : null; + $shouldShowTitle = is_string($settingsTableTitle) + && $settingsTableTitle !== '' + && ! ($context === 'policy' && strtolower($settingsTableTitle) === 'settings'); + @endphp + +
+ @if ($shouldShowTitle) +
{{ $settingsTableTitle }}
+ @endif + +
-
+
{{ $entry['key'] ?? '-' }}
-
+
@if ($isListValue)
@foreach ($value as $item) @@ -121,11 +121,11 @@ {{ $boolLabel }} @elseif ($isNumericValue) -
+
{{ number_format((float) $value) }}
@else -
+
{{ is_string($value) ? $value : json_encode($value, JSON_PRETTY_PRINT) }}
@endif diff --git a/resources/views/filament/infolists/entries/snapshot-json.blade.php b/resources/views/filament/infolists/entries/snapshot-json.blade.php index ff08225..36b8c6e 100644 --- a/resources/views/filament/infolists/entries/snapshot-json.blade.php +++ b/resources/views/filament/infolists/entries/snapshot-json.blade.php @@ -4,6 +4,7 @@ // Normalize payload to array for the JSON viewer $payloadArray = is_string($payload) ? (json_decode($payload, true) ?? []) : ($payload ?? []); + $rawJson = json_encode($payloadArray, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); // Provide the small set of helpers the pepperfm json view expects $getState = fn () => $payloadArray; @@ -17,10 +18,51 @@ $getRenderMode = fn () => \PepperFM\FilamentJson\Enums\RenderModeEnum::Tree; $getInitiallyCollapsed = fn () => 1; $getExpandAllToggle = fn () => false; - $getCopyJsonAction = fn () => true; + $getCopyJsonAction = fn () => false; $getMaxDepth = fn () => 3; $applyLimit = fn ($v) => $v; @endphp -{{-- Render pepperfm filament-json viewer --}} -@include('filament-json::json') +
+
+ + Copy JSON + +
+ + {{-- Render pepperfm filament-json viewer --}} + @include('filament-json::json') +
diff --git a/tests/Feature/Filament/PolicyViewSettingsCatalogReadableTest.php b/tests/Feature/Filament/PolicyViewSettingsCatalogReadableTest.php index 1e14ed1..587329c 100644 --- a/tests/Feature/Filament/PolicyViewSettingsCatalogReadableTest.php +++ b/tests/Feature/Filament/PolicyViewSettingsCatalogReadableTest.php @@ -80,7 +80,8 @@ $response->assertSee('Settings'); // Settings tab should appear for Settings Catalog $response->assertSee('General'); $response->assertSee('JSON'); - $response->assertSee('bg-gradient-to-br'); + $response->assertSee('tp-policy-general-card'); + $response->assertSee('Copy JSON'); }); it('shows display names instead of definition IDs', function () { diff --git a/tests/Feature/Filament/SettingsCatalogSettingsTableRenderTest.php b/tests/Feature/Filament/SettingsCatalogSettingsTableRenderTest.php index 7d500b9..9ee2573 100644 --- a/tests/Feature/Filament/SettingsCatalogSettingsTableRenderTest.php +++ b/tests/Feature/Filament/SettingsCatalogSettingsTableRenderTest.php @@ -59,7 +59,7 @@ $user = User::factory()->create(); $policyResponse = $this->actingAs($user) - ->get(PolicyResource::getUrl('view', ['record' => $policy])); + ->get(PolicyResource::getUrl('view', ['record' => $policy]).'?tab=settings'); $policyResponse->assertOk(); $policyResponse->assertSee('fi-width-full');