Skip to content

Commit

Permalink
Fix media admin (#32)
Browse files Browse the repository at this point in the history
* add default table options

I want to see more at at time.
i want to see most recent stuff at top

* Fix: Work with media type name enum

* fix: select filter cannot support mapping to enum

Unfortunately i need to remove this filter
With Selects, I can easily map the string to an enum.
with select filters i need the title attribute to exist on the record.
it's a reuqired field of relatinship.
They recommedn as a workaround to add a virtual column but eh

* this isn't numeric!
  • Loading branch information
davidharting authored Dec 27, 2024
1 parent 4a4bcfa commit ae07102
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
9 changes: 8 additions & 1 deletion app/Enum/MediaTypeName.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Enum;

enum MediaTypeName: string
use Filament\Support\Contracts\HasLabel;

enum MediaTypeName: string implements HasLabel
{
case Album = 'album';
case Book = 'book';
Expand All @@ -24,6 +26,11 @@ public function displayName(): string
};
}

public function getLabel(): ?string
{
return $this->displayName();
}

/**
* @return string[]
*/
Expand Down
2 changes: 2 additions & 0 deletions app/Filament/Resources/CreatorResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static function form(Form $form): Form
public static function table(Table $table): Table
{
return $table
->defaultSort('updated_at', 'desc')
->defaultPaginationPageOption(50)
->columns([
Tables\Columns\TextColumn::make('created_at')
->dateTime()
Expand Down
2 changes: 2 additions & 0 deletions app/Filament/Resources/MediaEventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public static function form(Form $form): Form
public static function table(Table $table): Table
{
return $table
->defaultSort('occurred_at', 'desc')
->defaultPaginationPageOption(50)
->columns([
Tables\Columns\TextColumn::make('mediaEventType.name')
->sortable(),
Expand Down
10 changes: 5 additions & 5 deletions app/Filament/Resources/MediaResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static function form(Form $form): Form
return $form
->schema([
Forms\Components\Select::make('media_type_id')
->relationship('mediaType', 'name')
->relationship('mediaType')
->getOptionLabelFromRecordUsing(fn ($record) => $record->name->getLabel())
->required(),
Forms\Components\TextInput::make('year')
->numeric(),
Expand All @@ -45,6 +46,8 @@ public static function form(Form $form): Form
public static function table(Table $table): Table
{
return $table
->defaultSort('updated_at', 'desc')
->defaultPaginationPageOption(50)
->columns([
Tables\Columns\TextColumn::make('created_at')
->dateTime()
Expand All @@ -55,7 +58,6 @@ public static function table(Table $table): Table
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('mediaType.name')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('year')
->numeric(thousandsSeparator: false)
Expand All @@ -64,9 +66,7 @@ public static function table(Table $table): Table
->searchable(),
])
->filters([
Tables\Filters\SelectFilter::make('media_type_id')
->relationship('mediaType', 'name')
->label(__('Media Type')),
//
])
->actions([
Tables\Actions\ViewAction::make(),
Expand Down

0 comments on commit ae07102

Please sign in to comment.