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

added customization closures #29

Merged
merged 1 commit into from
Jun 19, 2024
Merged

Conversation

ainesophaur
Copy link
Contributor

  • Added the ability to modify the eloquent query via closure
  • Added the ability to provide the list of activities via closure
  • Added the ability to set the text/value for TimeLineTitleEntry via closure

all of the closures are backed by the evaluate() function so you're able to inject the regular filament variables like $record, $component etc

ActivityLogTimelineAction::make('Activities')
    ->modifyQueryUsing(function (Builder $query) { 
    //some logic modify the query
    // ex return $query->where('log_name', '=', 'custom');
    })
ActivityLogTimelineAction::make('Activities')
    ->activitiesUsing(function (Model $record) { 
    //some logic to fetch the activities as a collection
    // ex Activity::all() or $record->activities;
    })
ActivityLogTimelineAction::make('Activities')
 ->shouldModifyTitleUsing(function (Activity $record) {
        //by default returns true, allows user to selectively skip the custom modifyTitleUsing function
        return $record->description !== $record->event;
    })
  ->modifyTitleUsing(function (Activity $record) {
      return $record->description;
  })

…dTitle which returns a string or html string

- add closures to modify query and TimeLineTitleEntry
@rmsramos rmsramos added the enhancement New feature or request label Jun 18, 2024
@rmsramos
Copy link
Owner

It looks good, at the weekend I'll take my time to launch a new release.
thanks for the contribution

@rmsramos rmsramos merged commit 94fe6e6 into rmsramos:main Jun 19, 2024
@ainesophaur ainesophaur deleted the improvements branch June 19, 2024 04:38
Copy link

@sparksp sparksp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have noticed that modifyQueryUsing does not get correctly applied.

public function getModifyQueryUsing(Builder $builder): Builder
{
$this->evaluate($this->modifyQueryUsing, ['builder' => $builder]);
return $builder;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns the original $builder not the modified query.

$builder = $this->getQuery()
->latest()
->limit($this->getLimit());
$this->getModifyQueryUsing($builder);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The modified query is not used.

sparksp added a commit to sparksp/rmsramos-activitylog that referenced this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Error in timeline view for User.
3 participants