Fix badge, update table

This commit is contained in:
notCharles 2024-05-31 16:39:23 -04:00
parent 7d0ce1627b
commit 5081cc3f63
3 changed files with 9 additions and 28 deletions

View File

@ -4,9 +4,7 @@ namespace App\Filament\Resources;
use App\Filament\Resources\ApiKeyResource\Pages; use App\Filament\Resources\ApiKeyResource\Pages;
use App\Models\ApiKey; use App\Models\ApiKey;
use Filament\Resources\Components\Tab;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Illuminate\Database\Eloquent\Builder;
class ApiKeyResource extends Resource class ApiKeyResource extends Resource
{ {
@ -16,7 +14,7 @@ class ApiKeyResource extends Resource
public static function getNavigationBadge(): ?string public static function getNavigationBadge(): ?string
{ {
return static::getModel()::count() ?: null; return static::getModel()::where('key_type', '2')->count() ?: null;
} }
public static function canEdit($record): bool public static function canEdit($record): bool
@ -24,20 +22,6 @@ class ApiKeyResource extends Resource
return false; return false;
} }
public function getTabs(): array
{
return [
'all' => Tab::make('All Keys'),
'application' => Tab::make('Application Keys')
->modifyQueryUsing(fn (Builder $query) => $query->where('key_type', ApiKey::TYPE_APPLICATION)),
];
}
public function getDefaultActiveTab(): string|int|null
{
return 'application';
}
public static function getRelations(): array public static function getRelations(): array
{ {
return [ return [

View File

@ -19,11 +19,6 @@ class ListApiKeys extends ListRecords
->searchable(false) ->searchable(false)
->modifyQueryUsing(fn ($query) => $query->where('key_type', ApiKey::TYPE_APPLICATION)) ->modifyQueryUsing(fn ($query) => $query->where('key_type', ApiKey::TYPE_APPLICATION))
->columns([ ->columns([
Tables\Columns\TextColumn::make('user.username')
->hidden()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('key') Tables\Columns\TextColumn::make('key')
->copyable() ->copyable()
->icon('tabler-clipboard-text') ->icon('tabler-clipboard-text')
@ -40,6 +35,7 @@ class ListApiKeys extends ListRecords
Tables\Columns\TextColumn::make('last_used_at') Tables\Columns\TextColumn::make('last_used_at')
->label('Last Used') ->label('Last Used')
->placeholder('Not Used')
->dateTime() ->dateTime()
->sortable(), ->sortable(),
@ -47,13 +43,13 @@ class ListApiKeys extends ListRecords
->label('Created') ->label('Created')
->dateTime() ->dateTime()
->sortable(), ->sortable(),
])
->filters([ Tables\Columns\TextColumn::make('user.username')
// ->label('Created By')
->url(fn (ApiKey $apiKey): string => route('filament.admin.resources.users.edit', ['record' => $apiKey->user])),
]) ])
->actions([ ->actions([
Tables\Actions\DeleteAction::make(), Tables\Actions\DeleteAction::make(),
//Tables\Actions\EditAction::make()
]); ]);
} }

View File

@ -158,7 +158,7 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile
->schema([ ->schema([
Grid::make('asdf')->columns(5)->schema([ Grid::make('asdf')->columns(5)->schema([
Section::make('Create API Key')->columnSpan(3)->schema([ Section::make('Create API Key')->columnSpan(3)->schema([
TextInput::make('description'), TextInput::make('description')->required(),
TagsInput::make('allowed_ips') TagsInput::make('allowed_ips')
->splitKeys([',', ' ', 'Tab']) ->splitKeys([',', ' ', 'Tab'])
->placeholder('Example: 127.0.0.1 or 192.168.1.1') ->placeholder('Example: 127.0.0.1 or 192.168.1.1')
@ -182,8 +182,9 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile
$action->success(); $action->success();
}), }),
]), ]),
Section::make('API Keys')->columnSpan(2)->schema([ Section::make('Keys')->columnSpan(2)->schema([
Repeater::make('keys') Repeater::make('keys')
->label('')
->relationship('apiKeys') ->relationship('apiKeys')
->addable(false) ->addable(false)
->itemLabel(fn ($state) => $state['identifier']) ->itemLabel(fn ($state) => $state['identifier'])