Skip to content

Commit

Permalink
Merge pull request #3 from howdu/hotfix/redirect-route-key-name
Browse files Browse the repository at this point in the history
Improve redirect speed using js instead of extra server request
  • Loading branch information
howdu authored Jun 28, 2024
2 parents 6a4325c + 86c5144 commit 658ab7b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/howdu/filament-record-switcher/fix-php-code-styling.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/howdu/filament-record-switcher/actions?query=workflow%3A"Fix+PHP+code+styling"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/howdu/filament-record-switcher.svg?style=flat-square)](https://packagist.org/packages/howdu/filament-record-switcher)

Subtly convert the page title into a dropdown navigation that's displayed on click.
Subtly convert the page title into a dropdown navigation that's displayed on click.

It works similar to Filament's global search but only show results for the current resource.
It works similar to Filament's global search but only shows results for the current resource.

![preview](https://github.com/howdu/filament-record-switcher/assets/533658/f0c62589-bd5f-4463-bf93-124b1c37955b)

Expand Down Expand Up @@ -45,7 +45,7 @@ class AdminPanelProvider extends PanelProvider
}
```
2. Add the `HasRecordSwitcher` trait to each of your edit record Page.
E.g `app/Filament/Resources/Category/EditCategory.php`
E.g `app/Filament/Resources/Category/Pages/EditCategory.php`
```php
use Howdu\FilamentRecordSwitcher\Filament\Concerns\HasRecordSwitcher;

Expand All @@ -54,6 +54,10 @@ class EditCategory extends EditRecord
use HasRecordSwitcher;
}
```

Note: this trail will overwrite the `getHeading()` method if you've overwritten it in your Page you need to
overwrite `getRecordTitle()` instead.

3. Publish plugin assets.
```bash
php artisan filament:assets
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/record-switcher.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
searchPrompt: '{{ __('filament-forms::components.select.search_prompt') }}',
searchingMessage: '{{ __('filament-forms::components.select.searching_message') }}',
state: @js($value),
updateSelected: async (value) => await $wire.updateRecordSwitcher(value),
updateSelected: (value) => window.location.href = value,
})"
wire:ignore
x-on:keydown.esc="select.dropdown.isActive && $event.stopPropagation()"
Expand Down
11 changes: 2 additions & 9 deletions src/Filament/Concerns/HasRecordSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected static function applyRecordSwitcherAttributeConstraint(Builder $query,

$query->when(
str($searchAttribute)->contains('.')
&& ! str($searchAttribute)->contains('`'),
&& ! str($searchAttribute)->contains('`'),
function (Builder $query) use ($databaseConnection, $isForcedCaseInsensitive, $searchAttribute, $search, $whereClause): Builder {
return $query->{"{$whereClause}Relation"}(
(string) str($searchAttribute)->beforeLast('.'),
Expand All @@ -113,17 +113,10 @@ function (Builder $query) use ($databaseConnection, $isForcedCaseInsensitive, $s
return $query;
}

public function updateRecordSwitcher($value)
{
$url = self::getResource()::getUrl('edit', ['record' => $value]);

$this->redirect($url);
}

protected function recordSwitcherItem(Model $model): array
{
$item = [
'value' => $model->getKey(),
'value' => self::getResource()::getUrl('edit', ['record' => $model->getRouteKey()]),
'label' => $this->recordSwitcherItemLabel($model),
];

Expand Down

0 comments on commit 658ab7b

Please sign in to comment.