diff --git a/app/Filament/Resources/PresentationResource.php b/app/Filament/Resources/PresentationResource.php index ffd40f5..98215f9 100644 --- a/app/Filament/Resources/PresentationResource.php +++ b/app/Filament/Resources/PresentationResource.php @@ -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([ diff --git a/app/Models/Presentation.php b/app/Models/Presentation.php index 7d0d129..1290c22 100644 --- a/app/Models/Presentation.php +++ b/app/Models/Presentation.php @@ -24,7 +24,7 @@ class Presentation extends Model implements HasMedia use InteractsWithMedia; use SoftDeletes; - public const DEFAULT_MARKDOWN = <<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); + }); });