From 1ae4d58b48ef1feefa8a26902f86028d9997bfe5 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 9 Apr 2026 08:30:14 +0700 Subject: [PATCH] refactor: restructure DataChangeInfolist to use Section component for improved organization and readability --- .../Infolists/DataChangeInfolist.php | 159 +++++++++--------- 1 file changed, 81 insertions(+), 78 deletions(-) diff --git a/app/Filament/Resources/Manage/DataChanges/Infolists/DataChangeInfolist.php b/app/Filament/Resources/Manage/DataChanges/Infolists/DataChangeInfolist.php index 1c2eb31..9bd7157 100644 --- a/app/Filament/Resources/Manage/DataChanges/Infolists/DataChangeInfolist.php +++ b/app/Filament/Resources/Manage/DataChanges/Infolists/DataChangeInfolist.php @@ -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 'Format data tidak valid.'; - } - - $renderValue = function ($value) { - if (empty($value)) { - return 'Kosong'; - } - - $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 'Format data tidak valid.'; } - } - if ($isProbablyPath) { - return collect($paths) - ->map(function ($path) { - if (! is_string($path)) { - return e(json_encode($path)); + $renderValue = function ($value) { + if (empty($value)) { + return 'Kosong'; + } + + $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 ""; - } + $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 ""; + } + + if ($extension === 'pdf') { + return "
↗️ Buka PDF di Tab Baru
"; - } + } - return "📎 Buka Dokumen (".strtoupper($extension).')'; - }) - ->implode('
'); - } + return "📎 Buka Dokumen (".strtoupper($extension).')'; + }) + ->implode('
'); + } - 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 "
".CheerfulNotification::getByKey('data_change.deletion_request_title')."

".CheerfulNotification::getByKey('data_change.deletion_request_desc').'

'; - } + } - // 2. New Addition Request - if (empty($old)) { - $rows = collect($new) - ->map(function ($value, $key) use ($renderValue) { - return sprintf( - "
+ // 2. New Addition Request + if (empty($old)) { + $rows = collect($new) + ->map(function ($value, $key) use ($renderValue) { + return sprintf( + "
%s
[BARU]
%s
", - e($key), - $renderValue($value) - ); - }) - ->implode(''); + e($key), + $renderValue($value) + ); + }) + ->implode(''); - return " + return "
".CheerfulNotification::getByKey('data_change.addition_request_title')."

".CheerfulNotification::getByKey('data_change.addition_request_desc')."

{$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( - "
+ // 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( + "
%s
@@ -129,15 +132,15 @@ public static function configure(Schema $schema): Schema
", - e($key), - $renderValue($oldValue), - $renderValue($newValue) - ); - }) - ->filter() - ->implode(''); - }) - ->columnSpanFull(), + e($key), + $renderValue($oldValue), + $renderValue($newValue) + ); + }) + ->filter() + ->implode(''); + }), + ]), ]) ->columns(1); }