Skip to content

Commit

Permalink
Merge pull request #51 from alkrauss48/issue-49-50/feat/presentation-…
Browse files Browse the repository at this point in the history
…and-image-upload-updates

Issue 49 50/feat/presentation and image upload updates
  • Loading branch information
alkrauss48 authored Oct 26, 2024
2 parents 8cb40e4 + dfc6c7a commit 478b404
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 18 deletions.
31 changes: 18 additions & 13 deletions app/Filament/Resources/ImageUploadResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Filament\Tables\Columns\SpatieMediaLibraryImageColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Webbingbrasil\FilamentCopyActions\Tables\Actions\CopyAction;

class ImageUploadResource extends Resource
{
Expand Down Expand Up @@ -80,36 +81,40 @@ function () {
public static function table(Table $table): Table
{
return $table
->defaultSort('updated_at', 'desc')
->columns([
Tables\Columns\TextColumn::make('title')
->searchable(),
SpatieMediaLibraryImageColumn::make('image')->collection('image'),
Tables\Columns\TextColumn::make('foo')
->label('Markdown URL')
->badge()
->getStateUsing(function (ImageUpload $record) {
return 'Copy Markdown URL';
})
->copyable()
->copyableState(fn (ImageUpload $record): string => $record->markdownUrl),
SpatieMediaLibraryImageColumn::make('image')
->collection('image'),
Tables\Columns\TextColumn::make('user.name')
->numeric()
->hidden(fn () => ! auth()->user()->isAdministrator())
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->label('Created At')
->date()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->label('Updated At')
->date()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
->toggleable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\ActionGroup::make([
Tables\Actions\EditAction::make(),
CopyAction::make('copyImageUrl')
->label('Copy Image URL')
->copyable(fn (ImageUpload $record): string => $record->getFirstMediaUrl('image')),
CopyAction::make('copyMarkdownUrl')
->label('Copy Markdown URL')
->copyable(fn (ImageUpload $record): string => $record->markdownUrl),
]),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Filament\Resources\ImageUploadResource\Pages;

use App\Filament\Resources\ImageUploadResource;
use App\Models\ImageUpload;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Webbingbrasil\FilamentCopyActions\Pages\Actions\CopyAction;

class EditImageUpload extends EditRecord
{
Expand All @@ -13,7 +15,15 @@ class EditImageUpload extends EditRecord
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\ActionGroup::make([
CopyAction::make('copyImageUrl')
->label('Copy Image URL')
->copyable(fn (ImageUpload $record): string => $record->getFirstMediaUrl('image')),
CopyAction::make('copyMarkdownUrl')
->label('Copy Markdown URL')
->copyable(fn (ImageUpload $record): string => $record->markdownUrl),
Actions\DeleteAction::make(),
]),
];
}
}
10 changes: 6 additions & 4 deletions app/Filament/Resources/PresentationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ function () {
public static function table(Table $table): Table
{
return $table
->defaultSort('updated_at', 'desc')
->columns([
SpatieMediaLibraryImageColumn::make('thumbnail')->collection('thumbnail'),
Tables\Columns\TextColumn::make('title')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('slug')
->sortable()
->toggleable()
->searchable(),
Tables\Columns\ToggleColumn::make('is_published')
->label('Published')
Expand All @@ -139,15 +141,15 @@ public static function table(Table $table): Table
->hidden(fn () => ! auth()->user()->isAdministrator())
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->date()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->date()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
->toggleable(),
Tables\Columns\TextColumn::make('deleted_at')
->dateTime()
->date()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
Expand Down
42 changes: 42 additions & 0 deletions tests/Filament/ImageUploadResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,46 @@

$this->assertModelMissing($record);
});

// Actions

it('has copyImageUrl action on list page', function () {
$record = Model::factory()
->for($this->nonAdmin)
->create();

livewire(ListResource::class)
->assertTableActionVisible('copyImageUrl');
});

it('has copyImageUrl action on edit page', function () {
$record = Model::factory()
->for($this->nonAdmin)
->create();

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

it('has copyMarkdownUrl action on list page', function () {
$record = Model::factory()
->for($this->nonAdmin)
->create();

livewire(ListResource::class)
->assertTableActionVisible('copyMarkdownUrl');
});

it('has copyMarkdownUrl action on edit page', function () {
$record = Model::factory()
->for($this->nonAdmin)
->create();

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

0 comments on commit 478b404

Please sign in to comment.