pxlrbt / filament-activity-log

Spatie activity log integration into Filament
MIT License
126 stars 24 forks source link

Support for array type property #2

Closed wit3 closed 11 months ago

wit3 commented 1 year ago

Hi

If my model has a property casted to array the view cannot print changes

htmlspecialchars(): Argument #1 ($string) must be of type string, array given

in

https://github.com/pxlrbt/filament-activity-log/blob/fe30892bedd829617bb30ee50c783eea99f3b5b3/resources/views/pages/list-activities.blade.php#L50

my property in activity_log is this

{
    "attributes": {
        "number": "23080827832",
        "service": "multi",
        "type": "s",
        "date_issued": "2023-01-18",
        "date_expiration": "2023-02-09",
        "status": 4,
        "status_updated_at": "2023-05-30T10:18:44.000000Z",
        "supplier_sfid": "0011i00000KFLiiAAH",
        "customer_sfid": "0016N00000cuRhOQAU",
        "consumptions": {
            "gn": 170,
            "ee": 262
        },
        "amounts": {
            "gn": 236.95,
            "ee": 122.27
        },
        "fattura_sfid": {
            "ee": "a036N00000ABhMAQA1",
            "gn": "a036N00000ABhM6QAL"
        },
        "ranking": 30,
        "home_sfid": null
    },
    "old": {
        "number": "2308082783",
        "service": "multi",
        "type": "ds",
        "date_issued": "2023-01-18",
        "date_expiration": "2023-02-09",
        "status": 4,
        "status_updated_at": "2023-05-30T10:18:44.000000Z",
        "supplier_sfid": "0011i00000KFLiiAAH",
        "customer_sfid": "0016N00000cuRhOQAU",
        "consumptions": {
            "gn": 170,
            "ee": 262
        },
        "amounts": {
            "gn": 236.95,
            "ee": 122.27
        },
        "fattura_sfid": {
            "ee": "a036N00000ABhMAQA1",
            "gn": "a036N00000ABhM6QAL"
        },
        "ranking": 0,
        "home_sfid": "a116N000004LMnLQAW"
    }
}
pxlrbt commented 1 year ago

Any idea how this would look like? I think the easiest way would be a <pre> and json_encode(). What do you think?

wit3 commented 1 year ago

maybe provide a method to map every field in attributes/old json? the user can choose to use Field->formatState or any method of field ( ex: for date issued use the DateTime, or use a key/value for array)?

This require more complex implementation instead of table rapresented now actually

pxlrbt commented 11 months ago

7 Introduced basic array support. I added your formateState() suggestions as a new issues #8