Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor config/translation, fix some minor stuff #24

Merged
merged 1 commit into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ class Handler extends ExceptionHandler
}
```

## Configuration
The configuration file filament-exceptions.php is automatically published into your config directory.
You can change icons and navigations settings as well as the active pill and slug there.

## Translations
Publish the translations with
```bash
php artisan vendor:publish --tag=filament-exceptions-translations
```

## Testing

Expand Down
18 changes: 17 additions & 1 deletion config/filament-exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@

'slug' => 'exceptions',

/** Show or hide in navigation/sidebare */
'navigation_enabled' => true,

/** Sort order, if shown. No effect, if navigation_enabled it set to false. */
'navigation_sort' => -1,

/** Whether to show a navigation badge. No effect, if navigation_enabled it set to false. */
'navigation_badge' => true,

'navigation_group' => true,
/** Name of navigation group. Empty means to group. No effect, if navigation_enabled it set to false. */
'navigation_group' => 'Settings',

/** Icons to use for navigation (if enabled) and pills */
'icons' => [
'navigation' => 'heroicon-o-chip',
'exception' => 'heroicon-o-chip',
'headers' => 'heroicon-o-switch-horizontal',
'cookies' => 'heroicon-o-database',
'body' => 'heroicon-s-code',
'queries' => 'heroicon-s-database',
],

'is_globally_searchable' => false,

Expand Down
48 changes: 12 additions & 36 deletions resources/lang/en/filament-exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,21 @@

return [

'model' => [
'label' => 'Exception',
'plural_label' => 'Exceptions',
],

'navigation' => [
'label' => 'Exception',
'group' => 'Settings',
'icon' => 'heroicon-o-chip',
],

'pills' => [

'exception' => [
'label' => 'Exception',
'icon' => 'heroicon-o-chip',
],

'headers' => [
'label' => 'Headers',
'icon' => 'heroicon-o-switch-horizontal',
],

'cookies' => [
'label' => 'Cookies',
'icon' => 'heroicon-o-database',
],

'body' => [
'label' => 'Body',
'icon' => 'heroicon-s-code',
],

'queries' => [
'label' => 'Queries',
'icon' => 'heroicon-s-database',
'labels' => [
'navigation' => 'Exception',
'model' => 'Exception',
'model_plural' => 'Exceptions',
'pills' => [
'exception' => 'Exception',
'headers' => 'Headers',
'cookies' => 'Cookies',
'body' => 'Body',
'queries' => 'Queries',
],
],

'empty_list' => 'Horray! just sit back & enjoy 😎',

'columns' => [
'method' => 'Method',
'path' => 'Path',
Expand Down
61 changes: 36 additions & 25 deletions src/Resources/ExceptionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use BezhanSalleh\FilamentAddons\Forms\Components\Pills\Pill;
use BezhanSalleh\FilamentExceptions\Models\Exception;
use BezhanSalleh\FilamentExceptions\Resources\ExceptionResource\Pages;
use BezhanSalleh\FilamentExceptions\Support\Utils;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
Expand All @@ -19,83 +18,95 @@ class ExceptionResource extends Resource

public static function getModelLabel(): string
{
return __('filament-exceptions::filament-exceptions.model.label');
return __('filament-exceptions::filament-exceptions.labels.model');
}

public static function getPluralModelLabel(): string
{
return __('filament-exceptions::filament-exceptions.model.plural_label');
return __('filament-exceptions::filament-exceptions.labels.model_plural');
}

protected static function getNavigationGroup(): ?string
{
return Utils::isNavigationGroupEnabled()
? __('filament-exceptions::filament-exceptions.navigation.group')
: '';
return config('filament-exceptions.navigation_group');
}

protected static function getNavigationLabel(): string
{
return __('filament-exceptions::filament-exceptions.navigation.label');
return __('filament-exceptions::filament-exceptions.labels.navigation');
}

protected static function getNavigationIcon(): string
{
return __('filament-exceptions::filament-exceptions.navigation.icon');
return config('filament-exceptions::icons.navigation');
}

public static function getSlug(): string
{
return Utils::getSlug();
return config('filament-exceptions.slug');
}

protected static function getNavigationBadge(): ?string
{
return Utils::isNavigationBadgeEnabled()
? static::$model::count()
: null;
if (config('filament-exceptions.navigation_badge')) {
return static::$model::count();
}

return null;
}

protected static function shouldRegisterNavigation(): bool
{
return (bool) config('filament-exceptions.navigation_enabled');
}

protected static function getNavigationSort(): ?int
{
return config('filament-exceptions.navigation_sort');
}

public static function canGloballySearch(): bool
{
return Utils::isGloballySearchable() && count(static::getGloballySearchableAttributes()) && static::canViewAny();
return config('filament-exceptions.is_globally_searchable')
&& count(static::getGloballySearchableAttributes())
&& static::canViewAny();
}

public static function form(Form $form): Form
{
return $form
->schema([
Pills::make('Heading')
->activePill(fn (): int => Utils::getActivePill())
->activePill(static fn (): int => config('filament-exceptions.active_pill'))
->pills([
Pill::make('Exception')
->label(fn (): string => __('filament-exceptions::filament-exceptions.pills.exception.label'))
->icon(fn (): string => __('filament-exceptions::filament-exceptions.pills.exception.icon'))
->label(static fn (): string => __('filament-exceptions::filament-exceptions.labels.pills.exception'))
->icon(static fn (): string => config('filament-exceptions.icons.exception'))
->schema([
Forms\Components\View::make('filament-exceptions::exception'),
]),
Pill::make('Headers')
->label(fn (): string => __('filament-exceptions::filament-exceptions.pills.headers.label'))
->icon(fn (): string => __('filament-exceptions::filament-exceptions.pills.headers.icon'))
->label(static fn (): string => __('filament-exceptions::filament-exceptions.labels.pills..headers'))
->icon(static fn (): string => config('filament-exceptions.icons.headers'))
->schema([
Forms\Components\View::make('filament-exceptions::headers'),
])->columns(1),
Pill::make('Cookies')
->label(fn (): string => __('filament-exceptions::filament-exceptions.pills.cookies.label'))
->icon(fn (): string => __('filament-exceptions::filament-exceptions.pills.cookies.icon'))
->label(static fn (): string => __('filament-exceptions::filament-exceptions.labels.pills.cookies'))
->icon(static fn (): string => config('filament-exceptions.icons.cookies'))
->schema([
Forms\Components\View::make('filament-exceptions::cookies'),
]),
Pill::make('Body')
->label(fn (): string => __('filament-exceptions::filament-exceptions.pills.body.label'))
->icon(fn (): string => __('filament-exceptions::filament-exceptions.pills.body.icon'))
->label(static fn (): string => __('filament-exceptions::filament-exceptions.labels.pills.body'))
->icon(static fn (): string => config('filament-exceptions.icons.body'))
->schema([
Forms\Components\View::make('filament-exceptions::body'),
]),
Pill::make('Queries')
->label(fn (): string => __('filament-exceptions::filament-exceptions.pills.queries.label'))
->icon(fn (): string => __('filament-exceptions::filament-exceptions.pills.queries.icon'))
->badge(fn ($record): string => collect(json_decode($record->query, true))->count())
->label(static fn (): string => __('filament-exceptions::filament-exceptions.labels.pills.queries'))
->icon(static fn (): string => config('filament-exceptions.icons.queries'))
->badge(static fn ($record): string => collect(json_decode($record->query, true, 512, JSON_THROW_ON_ERROR))->count())
->schema([
Forms\Components\View::make('filament-exceptions::query'),
]),
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/ExceptionResource/Pages/ListExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class ListExceptions extends ListRecords

protected function getTableEmptyStateIcon(): ?string
{
return 'heroicon-o-chip';
return config('filament-exceptions.icons.exception');
}

protected function getTableEmptyStateHeading(): ?string
{
return 'Horray! just set back & enjoy 😎';
return __('filament-exceptions::filament-exceptions.empty_list');
}
}
36 changes: 0 additions & 36 deletions src/Support/Utils.php

This file was deleted.