TenantAtlas/apps/platform/app/Filament/Support/NormalizedSettingsSurface.php
ahmido c0f4587d90 Spec 197: standardize shared detail family contracts (#237)
## Summary
- standardize the shared verification report family across operation detail, onboarding, and tenant verification widget hosts
- standardize normalized settings and normalized diff family wrappers across policy, policy version, and finding detail hosts
- add parity and guard coverage plus the full Spec 197 artifacts, including recorded manual smoke evidence

## Testing
- focused Sail regression pack from `specs/197-shared-detail-contract/quickstart.md`
- local integrated-browser manual smoke for SC-197-003 and SC-197-004

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #237
2026-04-15 09:51:42 +00:00

65 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Support;
final class NormalizedSettingsSurface
{
/**
* @param array<string, mixed> $normalized
* @return array<string, mixed>
*/
public static function build(array $normalized, string $hostKind): array
{
$warnings = collect($normalized['warnings'] ?? [])
->filter(static fn (mixed $warning): bool => is_string($warning) && trim($warning) !== '')
->map(static fn (string $warning): string => trim($warning))
->values()
->all();
$settingsTable = is_array($normalized['settings_table'] ?? null) ? $normalized['settings_table'] : null;
$settingsTableRows = is_array($settingsTable['rows'] ?? null) ? $settingsTable['rows'] : [];
$blocks = collect($normalized['settings'] ?? [])
->filter(static fn (mixed $block): bool => is_array($block))
->values()
->all();
$context = is_string($normalized['context'] ?? null) && $normalized['context'] !== ''
? (string) $normalized['context']
: 'policy';
$variant = $settingsTableRows !== [] ? 'settings_catalog_table' : 'standard_blocks';
return [
'hostKind' => $hostKind,
'context' => $context,
'variant' => $variant,
'warnings' => $warnings,
'settingsTable' => $settingsTableRows !== [] ? $settingsTable : null,
'blocks' => $blocks,
'sectionBehavior' => [
'preservesSectionOrder' => true,
'supportsExpansion' => true,
'ownsEmptyState' => true,
],
'renderExpectations' => [
'ownsWarningsInWrapper' => true,
'ownsSubtypeDelegation' => true,
'keepsHostFramingOutsideCore' => true,
],
'emptyState' => $settingsTableRows === [] && $blocks === []
? [
'title' => 'No settings available.',
'message' => 'No normalized settings payload is available for this host.',
]
: null,
'titlePolicy' => [
'showWrapperTitle' => false,
],
'recordId' => $normalized['record_id'] ?? null,
'policyType' => $normalized['policy_type'] ?? null,
];
}
}