Skip to content

Commit

Permalink
Merge pull request #32 from alkrauss48/issue-31/refactor/simplify-act…
Browse files Browse the repository at this point in the history
…ions-ui

Issue 31/refactor/simplify actions UI
  • Loading branch information
alkrauss48 authored Sep 4, 2024
2 parents bad9542 + 8276e6b commit afac95e
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
namespace App\Filament\Resources\PresentationResource\Pages;

use App\Filament\Resources\PresentationResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;

class CreatePresentation extends CreateRecord
{
protected static string $resource = PresentationResource::class;

protected static bool $canCreateAnother = false;

protected function getHeaderActions(): array
{
return [
Actions\Action::make('create')
->action('create'),
];
}
}
112 changes: 59 additions & 53 deletions app/Filament/Resources/PresentationResource/Pages/EditPresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,62 +18,68 @@ class EditPresentation extends EditRecord
protected function getHeaderActions(): array
{
return [
CopyAction::make('Copy Share URL')
->label('Copy Share URL')
->color('gray')
->copyable(fn (Presentation $record) => route('presentations.show', [
'user' => $record->user->username,
'slug' => $record->slug,
])),
Actions\Action::make('View')
->color('gray')
->url(fn (Presentation $record): string => route('presentations.show', [
'user' => $record->user->username,
'slug' => $record->slug,
]))
->icon('heroicon-o-arrow-top-right-on-square')
->openUrlInNewTab(),
Actions\Action::make('Generate Thumbnail')
->icon('heroicon-o-camera')
->color('info')
->requiresConfirmation()
->modalHeading('Generate a thumbnail of your first slide')
->modalIcon('heroicon-o-camera')
->modalIconColor('info')
->modalDescription(new HtmlString(
'This will overwrite any existing thumbnail that you have '
.'set for this presentation. Do you wish to continue?'
.'<br><br><strong>Note:</strong> Your presentation must first be published.'
))->modalSubmitActionLabel('Generate it')
->action(function (Presentation $record) {
if (! $record->is_published) {
Notification::make()
->title('You must publish your presentation to generate a thumbnail.')
->danger()
->send();

return;
}

Notification::make()
->title(
'Hang tight, your thumbnail is being generated in '
.'the background. Please refresh your browser in 5-10 '
.'seconds.'
)->info()
->send();

GenerateThumbnail::dispatch(
presentation: $record,
user: auth()->user(),
);
}),
Actions\Action::make('save')
->label('Save changes')
->action('save'),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
Actions\ActionGroup::make([
Actions\Action::make('view')
->label('View')
->color('gray')
->url(fn (Presentation $record): string => route('presentations.show', [
'user' => $record->user->username,
'slug' => $record->slug,
]))
->icon('heroicon-o-arrow-top-right-on-square')
->openUrlInNewTab(),
CopyAction::make('copyShareUrl')
->label('Copy Share URL')
->disabled(fn (Presentation $record) => ! $record->is_published)
->color('gray')
->copyable(fn (Presentation $record) => route('presentations.show', [
'user' => $record->user->username,
'slug' => $record->slug,
])),
Actions\Action::make('Generate Thumbnail')
->icon('heroicon-o-camera')
->requiresConfirmation()
->modalHeading('Generate a thumbnail of your first slide')
->modalIcon('heroicon-o-camera')
->modalIconColor('info')
->modalDescription(new HtmlString(
'This will overwrite any existing thumbnail that you have '
.'set for this presentation. Do you wish to continue?'
.'<br><br><strong>Note:</strong> Your presentation must first be published.'
))->modalSubmitActionLabel('Generate it')
->action(function (Presentation $record) {
if (! $record->is_published) {
Notification::make()
->title('You must publish your presentation to generate a thumbnail.')
->danger()
->send();

return;
}

Notification::make()
->title(
'Hang tight, your thumbnail is being generated in '
.'the background. Please refresh your browser in 5-10 '
.'seconds.'
)->info()
->send();

GenerateThumbnail::dispatch(
presentation: $record,
user: auth()->user(),
);
}),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
])
->color('gray')
->button()
->label('More'),
];
}
}
38 changes: 38 additions & 0 deletions tests/Filament/PresentationResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,42 @@

Queue::assertNotPushed(GenerateThumbnail::class);
});

it('can view the presentation', function () {
$record = Model::factory()->create([
'user_id' => $this->nonAdmin->id,
]);

livewire(EditResource::class, [
'record' => $record->getRouteKey(),
])
->assertActionHasUrl('view', route('presentations.show', [
'user' => $record->user->username,
'slug' => $record->slug,
]))
->assertActionShouldOpenUrlInNewTab('view');
});

it('can copy the share url of a published presentation', function () {
$record = Model::factory()->create([
'user_id' => $this->nonAdmin->id,
]);

livewire(EditResource::class, [
'record' => $record->getRouteKey(),
])
->assertActionEnabled('copyShareUrl');
});

it('can not copy the share url of a draft presentation', function () {
$record = Model::factory()->create([
'user_id' => $this->nonAdmin->id,
'is_published' => false,
]);

livewire(EditResource::class, [
'record' => $record->getRouteKey(),
])
->assertActionDisabled('copyShareUrl');
});
});

0 comments on commit afac95e

Please sign in to comment.