Skip to content

Commit

Permalink
Merge pull request #48 from alkrauss48/issue-42-replicate-presentatio…
Browse files Browse the repository at this point in the history
…n-action

feat: add replicate action and action group
  • Loading branch information
alkrauss48 authored Oct 25, 2024
2 parents 805aa88 + 0d775e3 commit 8cb40e4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
25 changes: 17 additions & 8 deletions app/Filament/Resources/PresentationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,23 @@ public static function table(Table $table): Table
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\Action::make('View')
->url(fn (Presentation $record): string => route('presentations.show', [
'user' => $record->user->username,
'slug' => $record->slug,
]))
->icon('heroicon-o-arrow-top-right-on-square')
->openUrlInNewTab(),
Tables\Actions\EditAction::make(),
Tables\Actions\ActionGroup::make([
Tables\Actions\Action::make('View')
->url(fn (Presentation $record): string => route('presentations.show', [
'user' => $record->user->username,
'slug' => $record->slug,
]))
->icon('heroicon-o-arrow-top-right-on-square')
->openUrlInNewTab(),
Tables\Actions\EditAction::make(),
Tables\Actions\ReplicateAction::make()
->beforeReplicaSaved(function (Presentation $replica, Presentation $record): void {
$replica->title = 'Copy of '.$record->title;
$replica->slug = 'copy-of-'.$record->slug;
$replica->is_published = false;
})
->successNotificationTitle('Presentation replicated'),
]),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Presentation extends Model implements HasMedia
use InteractsWithMedia;
use SoftDeletes;

public const DEFAULT_MARKDOWN = <<<MARKDOWN
public const DEFAULT_MARKDOWN = <<<'MARKDOWN'
# My Presentation
A Cool Subtitle
Expand Down
15 changes: 15 additions & 0 deletions tests/Filament/PresentationResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,19 @@
])
->assertActionDisabled('copyShareUrl');
});

// Replicate Records

it('can replicate a record', function () {
$record = Model::factory()
->for($this->nonAdmin)
->create();

expect(Model::count())->toBe(1);

livewire(ListResource::class)
->callTableAction(\Filament\Actions\ReplicateAction::class, $record);

expect(Model::count())->toBe(2);
});
});

0 comments on commit 8cb40e4

Please sign in to comment.