refactor: restructure DataChangeInfolist to use Section component for improved organization and readability
This commit is contained in:
parent
30d8432cf5
commit
1ae4d58b48
@ -5,6 +5,7 @@
|
||||
use App\Filament\Support\CheerfulNotification;
|
||||
use App\Models\DataChangeRequest;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
@ -14,109 +15,111 @@ public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->schema([
|
||||
TextEntry::make('comparison')
|
||||
->hiddenLabel()
|
||||
->html()
|
||||
->state(function (DataChangeRequest $record): string {
|
||||
$old = $record->old_data ?? [];
|
||||
$new = $record->new_data ?? [];
|
||||
Section::make()
|
||||
->schema([
|
||||
TextEntry::make('comparison')
|
||||
->hiddenLabel()
|
||||
->html()
|
||||
->state(function (DataChangeRequest $record): string {
|
||||
$old = $record->old_data ?? [];
|
||||
$new = $record->new_data ?? [];
|
||||
|
||||
if (! is_array($old) || ! is_array($new)) {
|
||||
return '<em>Format data tidak valid.</em>';
|
||||
}
|
||||
|
||||
$renderValue = function ($value) {
|
||||
if (empty($value)) {
|
||||
return '<em>Kosong</em>';
|
||||
}
|
||||
|
||||
$paths = is_array($value) ? $value : [$value];
|
||||
$isProbablyPath = false;
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (is_string($path) && (str_contains($path, '/') || str_contains($path, '\\'))) {
|
||||
$isProbablyPath = true;
|
||||
break;
|
||||
if (! is_array($old) || ! is_array($new)) {
|
||||
return '<em>Format data tidak valid.</em>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($isProbablyPath) {
|
||||
return collect($paths)
|
||||
->map(function ($path) {
|
||||
if (! is_string($path)) {
|
||||
return e(json_encode($path));
|
||||
$renderValue = function ($value) {
|
||||
if (empty($value)) {
|
||||
return '<em>Kosong</em>';
|
||||
}
|
||||
|
||||
$paths = is_array($value) ? $value : [$value];
|
||||
$isProbablyPath = false;
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (is_string($path) && (str_contains($path, '/') || str_contains($path, '\\'))) {
|
||||
$isProbablyPath = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$url = Storage::disk(config('filesystems.default'))->url($path);
|
||||
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||
if ($isProbablyPath) {
|
||||
return collect($paths)
|
||||
->map(function ($path) {
|
||||
if (! is_string($path)) {
|
||||
return e(json_encode($path));
|
||||
}
|
||||
|
||||
if (in_array($extension, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'])) {
|
||||
return "<a href='{$url}' target='_blank'><img src='{$url}' style='max-height:100px; border-radius:8px; margin-top:4px; border:1px solid #e5e7eb;'></a>";
|
||||
}
|
||||
$url = Storage::disk(config('filesystems.default'))->url($path);
|
||||
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||
|
||||
if ($extension === 'pdf') {
|
||||
return "
|
||||
if (in_array($extension, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'])) {
|
||||
return "<a href='{$url}' target='_blank'><img src='{$url}' style='max-height:100px; border-radius:8px; margin-top:4px; border:1px solid #e5e7eb;'></a>";
|
||||
}
|
||||
|
||||
if ($extension === 'pdf') {
|
||||
return "
|
||||
<div style='margin-top:4px;'>
|
||||
<iframe src='{$url}' style='width:100%; height:300px; border:1px solid #e5e7eb; border-radius:8px;'></iframe>
|
||||
<a href='{$url}' target='_blank' style='display:block; margin-top:4px; color:#3b82f6; text-decoration:underline; font-size:0.75rem;'>↗️ Buka PDF di Tab Baru</a>
|
||||
</div>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
return "<a href='{$url}' target='_blank' style='color:#3b82f6; text-decoration:underline; font-size:0.875rem;'>📎 Buka Dokumen (".strtoupper($extension).')</a>';
|
||||
})
|
||||
->implode('<br>');
|
||||
}
|
||||
return "<a href='{$url}' target='_blank' style='color:#3b82f6; text-decoration:underline; font-size:0.875rem;'>📎 Buka Dokumen (".strtoupper($extension).')</a>';
|
||||
})
|
||||
->implode('<br>');
|
||||
}
|
||||
|
||||
return e(is_scalar($value) ? $value : json_encode($value));
|
||||
};
|
||||
return e(is_scalar($value) ? $value : json_encode($value));
|
||||
};
|
||||
|
||||
// 1. Deletion Request
|
||||
if (isset($new['__delete_request__']) && $new['__delete_request__'] === true) {
|
||||
return "
|
||||
// 1. Deletion Request
|
||||
if (isset($new['__delete_request__']) && $new['__delete_request__'] === true) {
|
||||
return "
|
||||
<div style='background-color:#fee2e2; border:1px solid #f87171; color:#991b1b; padding:16px; border-radius:8px; margin-bottom:16px;'>
|
||||
<div style='font-weight:700; font-size:1.125rem; margin-bottom:4px;'>".CheerfulNotification::getByKey('data_change.deletion_request_title')."</div>
|
||||
<p style='font-size:0.875rem;'>".CheerfulNotification::getByKey('data_change.deletion_request_desc').'</p>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
}
|
||||
|
||||
// 2. New Addition Request
|
||||
if (empty($old)) {
|
||||
$rows = collect($new)
|
||||
->map(function ($value, $key) use ($renderValue) {
|
||||
return sprintf(
|
||||
"<div style='margin-bottom:12px; border-bottom:1px solid #f3f4f6; padding-bottom:8px'>
|
||||
// 2. New Addition Request
|
||||
if (empty($old)) {
|
||||
$rows = collect($new)
|
||||
->map(function ($value, $key) use ($renderValue) {
|
||||
return sprintf(
|
||||
"<div style='margin-bottom:12px; border-bottom:1px solid #f3f4f6; padding-bottom:8px'>
|
||||
<div style='font-weight:600; color:#374151; margin-bottom:4px'>%s</div>
|
||||
<div style='color:#16a34a; font-weight:500;'>[BARU]</div>
|
||||
<div style='margin-top:4px'>%s</div>
|
||||
</div>",
|
||||
e($key),
|
||||
$renderValue($value)
|
||||
);
|
||||
})
|
||||
->implode('');
|
||||
e($key),
|
||||
$renderValue($value)
|
||||
);
|
||||
})
|
||||
->implode('');
|
||||
|
||||
return "
|
||||
return "
|
||||
<div style='background-color:#f0fdf4; border:1px solid #bbf7d0; color:#166534; padding:16px; border-radius:8px; margin-bottom:16px;'>
|
||||
<div style='font-weight:700; font-size:1.125rem; margin-bottom:4px;'>".CheerfulNotification::getByKey('data_change.addition_request_title')."</div>
|
||||
<p style='font-size:0.875rem;'>".CheerfulNotification::getByKey('data_change.addition_request_desc')."</p>
|
||||
</div>
|
||||
{$rows}
|
||||
";
|
||||
}
|
||||
|
||||
// 3. Standard Comparison (Update)
|
||||
return collect($new)
|
||||
->map(function ($newValue, $key) use ($old, $renderValue) {
|
||||
$oldValue = $old[$key] ?? null;
|
||||
|
||||
if ($oldValue === $newValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
"<div style='margin-bottom:16px; border-bottom:1px solid #f3f4f6; padding-bottom:12px'>
|
||||
// 3. Standard Comparison (Update)
|
||||
return collect($new)
|
||||
->map(function ($newValue, $key) use ($old, $renderValue) {
|
||||
$oldValue = $old[$key] ?? null;
|
||||
|
||||
if ($oldValue === $newValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
"<div style='margin-bottom:16px; border-bottom:1px solid #f3f4f6; padding-bottom:12px'>
|
||||
<div style='font-weight:600; color:#374151; margin-bottom:4px'>%s</div>
|
||||
<div style='display:grid; grid-template-columns: 1fr 1fr; gap:16px'>
|
||||
<div>
|
||||
@ -129,15 +132,15 @@ public static function configure(Schema $schema): Schema
|
||||
</div>
|
||||
</div>
|
||||
</div>",
|
||||
e($key),
|
||||
$renderValue($oldValue),
|
||||
$renderValue($newValue)
|
||||
);
|
||||
})
|
||||
->filter()
|
||||
->implode('');
|
||||
})
|
||||
->columnSpanFull(),
|
||||
e($key),
|
||||
$renderValue($oldValue),
|
||||
$renderValue($newValue)
|
||||
);
|
||||
})
|
||||
->filter()
|
||||
->implode('');
|
||||
}),
|
||||
]),
|
||||
])
|
||||
->columns(1);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user