fix: render array values in policy settings
This commit is contained in:
parent
ea72ea106f
commit
70f8622171
@ -1,5 +1,6 @@
|
||||
@php
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Js;
|
||||
|
||||
// Extract state from Filament ViewEntry
|
||||
$state = $getState();
|
||||
@ -7,6 +8,34 @@
|
||||
$warnings = $state['warnings'] ?? [];
|
||||
$settings = $state['settings'] ?? [];
|
||||
$settingsTable = $state['settings_table'] ?? null;
|
||||
|
||||
$stringifyValue = function (mixed $value): string {
|
||||
if (is_null($value)) {
|
||||
return 'N/A';
|
||||
}
|
||||
|
||||
if (is_bool($value)) {
|
||||
return $value ? 'Enabled' : 'Disabled';
|
||||
}
|
||||
|
||||
if (is_scalar($value)) {
|
||||
return (string) $value;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
return Js::from($value)->toHtml();
|
||||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
if (method_exists($value, '__toString')) {
|
||||
return (string) $value;
|
||||
}
|
||||
|
||||
return Js::from((array) $value)->toHtml();
|
||||
}
|
||||
|
||||
return 'N/A';
|
||||
};
|
||||
@endphp
|
||||
|
||||
<div class="space-y-4">
|
||||
@ -96,7 +125,7 @@
|
||||
</span>
|
||||
@else
|
||||
<span class="text-sm text-gray-900 dark:text-white break-words">
|
||||
{{ Str::limit($row['value'] ?? 'N/A', 200) }}
|
||||
{{ Str::limit($stringifyValue($row['value'] ?? null), 200) }}
|
||||
</span>
|
||||
@endif
|
||||
</dd>
|
||||
@ -124,7 +153,7 @@
|
||||
</dt>
|
||||
<dd class="mt-1 sm:mt-0 sm:col-span-2">
|
||||
<span class="text-sm text-gray-900 dark:text-white break-words">
|
||||
{{ Str::limit($entry['value'] ?? 'N/A', 200) }}
|
||||
{{ Str::limit($stringifyValue($entry['value'] ?? null), 200) }}
|
||||
</span>
|
||||
</dd>
|
||||
</div>
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use App\Filament\Resources\PolicyResource;
|
||||
use App\Models\Policy;
|
||||
use App\Models\PolicyVersion;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('policy settings standard view renders array values without crashing', function () {
|
||||
$tenant = Tenant::create([
|
||||
'tenant_id' => 'tenant-arrays',
|
||||
'name' => 'Tenant Arrays',
|
||||
'metadata' => [],
|
||||
'is_current' => true,
|
||||
]);
|
||||
|
||||
$tenant->makeCurrent();
|
||||
|
||||
$policy = Policy::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'external_id' => 'policy-arrays-1',
|
||||
'policy_type' => 'windowsAutopilotDeploymentProfile',
|
||||
'display_name' => 'Autopilot Policy With Arrays',
|
||||
'platform' => 'windows',
|
||||
]);
|
||||
|
||||
PolicyVersion::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'policy_id' => $policy->id,
|
||||
'version_number' => 1,
|
||||
'policy_type' => $policy->policy_type,
|
||||
'platform' => $policy->platform,
|
||||
'created_by' => 'tester@example.com',
|
||||
'captured_at' => CarbonImmutable::now(),
|
||||
'snapshot' => [
|
||||
'@odata.type' => '#microsoft.graph.windowsAutopilotDeploymentProfile',
|
||||
'displayName' => 'Autopilot Policy With Arrays',
|
||||
'roleScopeTagIds' => ['0', '1'],
|
||||
'outOfBoxExperienceSettings' => [
|
||||
'hideEULA' => true,
|
||||
'userType' => 'standard',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->get(PolicyResource::getUrl('view', ['record' => $policy]).'?tab=settings');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertSee('Settings');
|
||||
$response->assertSee('Scope tag IDs');
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user