Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$state value in configureTitleUsing is different with $state value in modifiedTitle for TimeLineTitleEntry #66

Open
huiyang opened this issue Nov 5, 2024 · 1 comment
Labels
bug Something isn't working unconfirmed

Comments

@huiyang
Copy link

huiyang commented Nov 5, 2024

Package Version

v1.0.7

Laravel Version

v11.29.0

PHP Version

PHP 8.2.18

Problem description

When the title value is evaluate using TimeLineTitleEntry->configureTitleUsing, wrong $state is been used.

Expected behavior

update date of activity logs shown in ActivityLogTimelineTableAction should be the same when
modifyTitleUsing method is called or when it is not called.

Steps to reproduce

  1. checkout the example repo
  2. login to filament admin panel at /admin (username: [email protected], password: admin)
  3. view activitylog for ExampleResource, the update date is actually wrong. (latest date should be 5 Nov 2024)
  4. uncomment the modifyTitleUsing method in ExampleResource
  5. view the activitylog for ExampleResource again, the update date is now correct.

Conclusion:
When there is multiple activity logs with different date,
when use the following code to modify the title of the activity log, all update date of the activity log is wrong.

ActivityLogTimelineTableAction::make()
                    ->modifyTitleUsing(function($state, $record) {
                        if ($state['description'] == $state['event']) {
                            $aliases = [
                            ];
                            $className = isset($state['subject']) ? class_basename($state['subject']) : class_basename($record->subject_type);
                            $className  = $aliases[$className] ?? Str::lower(Str::snake($className, ' '));

                            $causer = $state['causer'];
                            $causerName = $causer->name ?? $causer->first_name ?? $causer->last_name ?? $causer->username ?? 'Unknown';
                            $update_at  = \Carbon\Carbon::parse($state['update'])->translatedFormat(config('filament-activitylog.datetime_format'));

                            return new HtmlString(
                                sprintf(
                                    'The <strong>%s</strong> was <strong>%s</strong> by <strong>%s</strong>. <br><small> Updated at: <strong>%s</strong></small>',
                                    $className,
                                    $state['event'],
                                    $causerName,
                                    $update_at
                                )
                            );
                        }
                    })

Reproduction repository (issue will be closed if this is not valid)

https://github.com/huiyang/example-app

Relevant log output

No response

@huiyang huiyang added bug Something isn't working unconfirmed labels Nov 5, 2024
@dharen008
Copy link

Can anyone explain why we need this part of the code?

image

If you try changing the description, as I did here:

image

The timeline title won't appear because the description and event are no longer equal.

image

I suggest removing this part of the code to fix the issue for anyone who wants to update the description.

Additionally, there's a CSS issue when you click the timeline menu link and the modal appears:

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed
Projects
None yet
Development

No branches or pull requests

2 participants