Skip to content

Commit

Permalink
Optimize log activity query and beneficiary view page
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 committed Dec 5, 2024
1 parent dea2adb commit 0727084
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/Concerns/LogsActivityOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ trait LogsActivityOptions
{
use LogsActivity;

protected static $recordEvents = ['created', 'updated', 'deleted', 'retrieved'];
protected static $recordEvents = [
'created',
'updated',
'deleted',
// 'retrieved'
];

public function getActivitylogOptions(): LogOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Organizations\Resources\BeneficiaryResource\Pages;

use App\Enums\ActivityDescription;
use App\Enums\AddressType;
use App\Enums\CaseStatus;
use App\Enums\Ternary;
Expand All @@ -17,6 +18,7 @@
use App\Filament\Organizations\Resources\MonitoringResource\Widgets\MonitoringWidget;
use App\Infolists\Components\EnumEntry;
use App\Infolists\Components\Location;
use App\Models\Activity;
use App\Models\Beneficiary;
use App\Services\Breadcrumb\BeneficiaryBreadcrumb;
use Filament\Actions\Action;
Expand All @@ -43,6 +45,22 @@ class ViewBeneficiary extends ViewRecord
{
protected static string $resource = BeneficiaryResource::class;

public function mount(int|string $record): void
{
parent::mount($record);

Activity::create([
'log_name' => 'default',
'description' => ActivityDescription::RETRIEVED,
'subject_type' => $this->getRecord()->getMorphClass(),
'subject_id' => $this->getRecord()->id,
'event' => ActivityDescription::RETRIEVED->value,
'causer_type' => auth()->user()->getMorphClass(),
'causer_id' => auth()->id(),
'properties' => ['old' => $this->getRecord()->toArray()],
]);
}

public function getBreadcrumbs(): array
{
return BeneficiaryBreadcrumb::make($this->getRecord())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function table(Table $table): Table
->label(__('monitoring.labels.last_monitoring_date')),
Tables\Columns\TextColumn::make('count')
->label(__('monitoring.labels.count'))
->default(fn () => $this->record->monitoring()->count()),
->default(fn () => $this->record->monitoring->count()),
])
->emptyStateHeading(__('monitoring.headings.widget_empty_state'))
->emptyStateActions([
Expand Down

0 comments on commit 0727084

Please sign in to comment.