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)) -