Skip to content

Commit

Permalink
fix(filament): fixed attach action (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrch authored May 29, 2024
1 parent a7f314d commit cbd7fe7
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/Filament/Resources/BaseRelationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static function getHeaderActions(): array
/** @var string */
$model = $livewire->getTable()->getModel();
$title = $livewire->getTable()->getRecordTitle(new $model);
return Select::make($title)
return Select::make('recordId')
->label($title)
->useScout($model);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function form(Form $form): Form
public function table(Table $table): Table
{
return $table
->heading(ArtistResource::getPluralLabel())
->modelLabel(ArtistResource::getLabel())
->heading(__('filament.resources.label.groups'))
->modelLabel(__('filament.resources.singularLabel.group'))
->recordTitleAttribute(Artist::ATTRIBUTE_NAME)
->inverseRelationship(Artist::RELATION_MEMBERS)
->columns(ArtistResource::table($table)->getColumns())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function form(Form $form): Form
public function table(Table $table): Table
{
return $table
->heading(ArtistResource::getPluralLabel())
->modelLabel(ArtistResource::getLabel())
->heading(__('filament.resources.label.members'))
->modelLabel(__('filament.resources.singularLabel.member'))
->recordTitleAttribute(Artist::ATTRIBUTE_NAME)
->inverseRelationship(Artist::RELATION_GROUPS)
->columns(ArtistResource::table($table)->getColumns())
Expand Down
33 changes: 33 additions & 0 deletions app/Filament/TableActions/BaseTableAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace App\Filament\TableActions;

use Filament\Tables\Actions\Action;

/**
* Class BaseTableAction.
*/
abstract class BaseTableAction extends Action
{
/**
* Initial setup for the action.
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();

$this->action(fn (array $data) => $this->handle($data));
}

/**
* Perform the action on the table.
*
* @param array $fields
* @return void
*/
abstract public function handle(array $fields): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,30 @@
use App\Actions\Models\Wiki\UploadImageAction;
use App\Enums\Models\Wiki\ImageFacet;
use App\Filament\Components\Fields\Select;
use App\Filament\TableActions\BaseTableAction;
use App\Models\Wiki\Image;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Form;
use Filament\Tables\Actions\Action;
use Illuminate\Validation\Rules\Enum;

/**
* Class UploadImageTableAction.
*/
class UploadImageTableAction extends Action
class UploadImageTableAction extends BaseTableAction
{
protected array $facets = [];

/**
* Initial setup for the action.
* Perform the action on the table.
*
* @param array $fields
* @return void
*/
protected function setUp(): void
public function handle(array $fields): void
{
parent::setUp();
$action = new UploadImageAction();

$this->action(fn (array $data) => (new UploadImageAction())->handle($data));
$action->handle($fields);
}

/**
Expand Down
20 changes: 3 additions & 17 deletions app/Filament/TableActions/Repositories/ReconcileTableAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,27 @@
namespace App\Filament\TableActions\Repositories;

use App\Concerns\Repositories\ReconcilesRepositories;
use App\Models\BaseModel;
use App\Filament\TableActions\BaseTableAction;
use Exception;
use Filament\Tables\Actions\Action;

/**
* Class ReconcileTableAction.
*/
abstract class ReconcileTableAction extends Action
abstract class ReconcileTableAction extends BaseTableAction
{
use ReconcilesRepositories;

/**
* Initial setup for the action.
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();

$this->action(fn (BaseModel $record, array $data) => $this->handle($record, $data));
}

/**
* Perform the action on the given models.
*
* @param BaseModel $record
* @param array $fields
* @return void
*
* @throws Exception
*
* @noinspection PhpUnusedParameterInspection
*/
public function handle(BaseModel $record, array $fields): void
public function handle(array $fields): void
{
$result = $this->reconcileRepositories($fields);

Expand Down
18 changes: 3 additions & 15 deletions app/Filament/TableActions/Storage/StorageTableAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,13 @@
namespace App\Filament\TableActions\Storage;

use App\Contracts\Actions\Storage\StorageAction as BaseStorageAction;
use Filament\Tables\Actions\Action;
use App\Filament\TableActions\BaseTableAction;

/**
* Class StorageTableAction.
*/
abstract class StorageTableAction extends Action
abstract class StorageTableAction extends BaseTableAction
{
/**
* Initial setup for the action.
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();

$this->action(fn (array $data) => $this->handle($data));
}

/**
* Get the underlying storage action.
*
Expand All @@ -33,7 +21,7 @@ protected function setUp(): void
abstract protected function storageAction(array $fields): BaseStorageAction;

/**
* Perform the action on the given models.
* Perform the action on the table.
*
* @param array $fields
* @return void
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Api/Schema/Admin/FeaturedThemeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ public function allowedIncludes(): array
new AllowedInclude(new AnimeSchema(), FeaturedTheme::RELATION_ANIME),
new AllowedInclude(new ArtistSchema(), FeaturedTheme::RELATION_ARTISTS),
new AllowedInclude(new EntrySchema(), FeaturedTheme::RELATION_ENTRY),
new AllowedInclude(new GroupSchema(), FeaturedTheme::RELATION_GROUP),
new AllowedInclude(new ImageSchema(), FeaturedTheme::RELATION_IMAGES),
new AllowedInclude(new SongSchema(), FeaturedTheme::RELATION_SONG),
new AllowedInclude(new ThemeSchema(), FeaturedTheme::RELATION_THEME),
new AllowedInclude(new UserSchema(), FeaturedTheme::RELATION_USER),
new AllowedInclude(new VideoSchema(), FeaturedTheme::RELATION_VIDEO),

new AllowedInclude(new GroupSchema(), 'animethemeentry.animetheme.group'),
];
}

Expand Down
3 changes: 1 addition & 2 deletions app/Http/Api/Schema/List/Playlist/TrackSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ public function allowedIncludes(): array
return [
new AllowedInclude(new ArtistSchema(), PlaylistTrack::RELATION_ARTISTS),
new AllowedInclude(new AudioSchema(), PlaylistTrack::RELATION_AUDIO),
new AllowedInclude(new GroupSchema(), PlaylistTrack::RELATION_THEME_GROUP),
new AllowedInclude(new ImageSchema(), PlaylistTrack::RELATION_IMAGES),
new AllowedInclude(new PlaylistSchema(), PlaylistTrack::RELATION_PLAYLIST),
new AllowedInclude(new TrackSchema(), PlaylistTrack::RELATION_NEXT),
new AllowedInclude(new TrackSchema(), PlaylistTrack::RELATION_PREVIOUS),
new AllowedInclude(new VideoSchema(), PlaylistTrack::RELATION_VIDEO),

new AllowedInclude(new GroupSchema(), 'video.animethemeentries.animetheme.group'),
];
}

Expand Down
1 change: 1 addition & 0 deletions app/Models/Admin/FeaturedTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FeaturedTheme extends BaseModel
final public const RELATION_ANIME = 'animethemeentry.animetheme.anime';
final public const RELATION_ARTISTS = 'animethemeentry.animetheme.song.artists';
final public const RELATION_ENTRY = 'animethemeentry';
final public const RELATION_GROUP = 'animethemeentry.animetheme.group';
final public const RELATION_IMAGES = 'animethemeentry.animetheme.anime.images';
final public const RELATION_SONG = 'animethemeentry.animetheme.song';
final public const RELATION_THEME = 'animethemeentry.animetheme';
Expand Down
1 change: 1 addition & 0 deletions lang/en/filament.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@
'featured_theme' => 'Featured Theme',
'group' => 'Group',
'image' => 'Image',
'member' => 'Member',
'page' => 'Page',
'permission' => 'Permission',
'playlist_track' => 'Playlist Track',
Expand Down

0 comments on commit cbd7fe7

Please sign in to comment.