Feature: Callback to map values #8

Open
opened 2023-08-02 07:06:03 +00:00 by pxlrbt · 1 comment
pxlrbt commented 2023-08-02 07:06:03 +00:00 (Migrated from github.com)

Callback to map values formatState() or similar for display.

Callback to map values `formatState()` or similar for display.
digitall-it commented 2024-07-13 10:30:11 +00:00 (Migrated from github.com)

I was searching exactly for this feature, here's a proposal on how it could work and remain consistent with the LogsActivity trait in spatie/laravel-activitylog:

<?php

namespace App\Filament\Resources\UserResource\Pages;

use App\Filament\Resources\UserResource;
use pxlrbt\FilamentActivityLog\Pages\ListActivities;

class ListUserActivities extends ListActivities
{
    protected static string $resource = UserResource::class;
    
    public function tapActivity(Activity $activity, string $eventName): void    {}
}

the use case is that you don't want to actually change the properties in the database while logging, just the way they are shown on the screen (for example to fetch relationship names, format dates, a meaningful display of structured data).

Suggesting to use tapActivity in the model instead would mess up this package "Restore" feature, because it is used to actually replace the changed data. For things like dates and times it may be OK but for structured data or relationship names it wouldn't work anymore.

The feature is implemented in the spatie package like this if (method_exists($model, 'tapActivity')) {$logger->tap([$model, 'tapActivity'], $eventName);} and could become something like if (method_exists($this, 'tapActivity')) {$logger->tap([$model, 'tapActivity'], $eventName);} somewhere in ListActivities.php.

What's your stance on this?

I was searching exactly for this feature, here's a proposal on how it could work and remain consistent with the LogsActivity trait in spatie/laravel-activitylog: ``` <?php namespace App\Filament\Resources\UserResource\Pages; use App\Filament\Resources\UserResource; use pxlrbt\FilamentActivityLog\Pages\ListActivities; class ListUserActivities extends ListActivities { protected static string $resource = UserResource::class; public function tapActivity(Activity $activity, string $eventName): void {} } ``` the use case is that you don't want to actually change the properties in the database while logging, just the way they are shown on the screen (for example to fetch relationship names, format dates, a meaningful display of structured data). Suggesting to use tapActivity in the model instead would mess up this package "Restore" feature, because it is used to actually replace the changed data. For things like dates and times it may be OK but for structured data or relationship names it wouldn't work anymore. The feature is implemented in the spatie package like this `if (method_exists($model, 'tapActivity')) {$logger->tap([$model, 'tapActivity'], $eventName);}` and could become something like `if (method_exists($this, 'tapActivity')) {$logger->tap([$model, 'tapActivity'], $eventName);}` somewhere in ListActivities.php. What's your stance on this?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pxlrbt/filament-activity-log#8
No description provided.