From cbd7fe75d373a54df676934c64c0eab13f9269c2 Mon Sep 17 00:00:00 2001 From: Kyrch Date: Wed, 29 May 2024 14:50:43 -0300 Subject: [PATCH] fix(filament): fixed attach action (#682) --- .../Resources/BaseRelationManager.php | 2 +- .../GroupArtistRelationManager.php | 4 +-- .../MemberArtistRelationManager.php | 4 +-- app/Filament/TableActions/BaseTableAction.php | 33 +++++++++++++++++++ .../Wiki/Image/UploadImageTableAction.php | 13 ++++---- .../Repositories/ReconcileTableAction.php | 20 ++--------- .../Storage/StorageTableAction.php | 18 ++-------- .../Api/Schema/Admin/FeaturedThemeSchema.php | 3 +- .../Api/Schema/List/Playlist/TrackSchema.php | 3 +- app/Models/Admin/FeaturedTheme.php | 1 + lang/en/filament.php | 1 + 11 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 app/Filament/TableActions/BaseTableAction.php diff --git a/app/Filament/Resources/BaseRelationManager.php b/app/Filament/Resources/BaseRelationManager.php index bb1c2a3ec..3f97172c0 100644 --- a/app/Filament/Resources/BaseRelationManager.php +++ b/app/Filament/Resources/BaseRelationManager.php @@ -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); }), diff --git a/app/Filament/Resources/Wiki/Artist/RelationManagers/GroupArtistRelationManager.php b/app/Filament/Resources/Wiki/Artist/RelationManagers/GroupArtistRelationManager.php index 89ea430de..d06aaeeba 100644 --- a/app/Filament/Resources/Wiki/Artist/RelationManagers/GroupArtistRelationManager.php +++ b/app/Filament/Resources/Wiki/Artist/RelationManagers/GroupArtistRelationManager.php @@ -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()) diff --git a/app/Filament/Resources/Wiki/Artist/RelationManagers/MemberArtistRelationManager.php b/app/Filament/Resources/Wiki/Artist/RelationManagers/MemberArtistRelationManager.php index f98eb3f7c..7f2f99280 100644 --- a/app/Filament/Resources/Wiki/Artist/RelationManagers/MemberArtistRelationManager.php +++ b/app/Filament/Resources/Wiki/Artist/RelationManagers/MemberArtistRelationManager.php @@ -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()) diff --git a/app/Filament/TableActions/BaseTableAction.php b/app/Filament/TableActions/BaseTableAction.php new file mode 100644 index 000000000..06c36fb9f --- /dev/null +++ b/app/Filament/TableActions/BaseTableAction.php @@ -0,0 +1,33 @@ +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; +} diff --git a/app/Filament/TableActions/Models/Wiki/Image/UploadImageTableAction.php b/app/Filament/TableActions/Models/Wiki/Image/UploadImageTableAction.php index 5498b3403..3e5912329 100644 --- a/app/Filament/TableActions/Models/Wiki/Image/UploadImageTableAction.php +++ b/app/Filament/TableActions/Models/Wiki/Image/UploadImageTableAction.php @@ -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); } /** diff --git a/app/Filament/TableActions/Repositories/ReconcileTableAction.php b/app/Filament/TableActions/Repositories/ReconcileTableAction.php index a58dabca5..95393a2c8 100644 --- a/app/Filament/TableActions/Repositories/ReconcileTableAction.php +++ b/app/Filament/TableActions/Repositories/ReconcileTableAction.php @@ -5,33 +5,19 @@ 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 * @@ -39,7 +25,7 @@ protected function setUp(): void * * @noinspection PhpUnusedParameterInspection */ - public function handle(BaseModel $record, array $fields): void + public function handle(array $fields): void { $result = $this->reconcileRepositories($fields); diff --git a/app/Filament/TableActions/Storage/StorageTableAction.php b/app/Filament/TableActions/Storage/StorageTableAction.php index 9e2f7478a..a909bf3ef 100644 --- a/app/Filament/TableActions/Storage/StorageTableAction.php +++ b/app/Filament/TableActions/Storage/StorageTableAction.php @@ -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. * @@ -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 diff --git a/app/Http/Api/Schema/Admin/FeaturedThemeSchema.php b/app/Http/Api/Schema/Admin/FeaturedThemeSchema.php index 3184395d5..49a256a0c 100644 --- a/app/Http/Api/Schema/Admin/FeaturedThemeSchema.php +++ b/app/Http/Api/Schema/Admin/FeaturedThemeSchema.php @@ -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'), ]; } diff --git a/app/Http/Api/Schema/List/Playlist/TrackSchema.php b/app/Http/Api/Schema/List/Playlist/TrackSchema.php index dcd5878bd..31863e7a0 100644 --- a/app/Http/Api/Schema/List/Playlist/TrackSchema.php +++ b/app/Http/Api/Schema/List/Playlist/TrackSchema.php @@ -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'), ]; } diff --git a/app/Models/Admin/FeaturedTheme.php b/app/Models/Admin/FeaturedTheme.php index 06bc1d72d..0f9a316a9 100644 --- a/app/Models/Admin/FeaturedTheme.php +++ b/app/Models/Admin/FeaturedTheme.php @@ -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'; diff --git a/lang/en/filament.php b/lang/en/filament.php index 123d18f9e..6248777fa 100644 --- a/lang/en/filament.php +++ b/lang/en/filament.php @@ -901,6 +901,7 @@ 'featured_theme' => 'Featured Theme', 'group' => 'Group', 'image' => 'Image', + 'member' => 'Member', 'page' => 'Page', 'permission' => 'Permission', 'playlist_track' => 'Playlist Track',