Skip to content

Commit

Permalink
Merge branch 'main' into feature/case-insensitive-search
Browse files Browse the repository at this point in the history
  • Loading branch information
pxlrbt authored Nov 18, 2024
2 parents 2a3504c + 860e1d3 commit 78dacd3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
3 changes: 1 addition & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div class="filament-hidden">

![header](./.github/resources/pxlrbt-spotlight.png)
pxlrbt-translate-action.png
</div>

# Filament Spotlight
Expand Down Expand Up @@ -77,7 +76,7 @@ CMD + /

### Setup

This plugin relies on the same properties and methods used for Filament's global search. For records showing up with the correct name in "Edit/View" you need to set `$recordTitleAttribute`. [Check the docs for more information](https://filamentphp.com/docs/2.x/admin/resources/global-search)
This plugin relies on the same properties and methods used for Filament's global search. For records showing up with the correct name in "Edit/View" you need to set `$recordTitleAttribute`. [Check the docs for more information](https://filamentphp.com/docs/3.x/panels/resources/global-search)

#### Excluding pages

Expand Down
6 changes: 6 additions & 0 deletions resources/lang/de/spotlight.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
'placeholder' => 'Nach :Record suchen',
'account' => 'Dein Konto',
];
6 changes: 6 additions & 0 deletions resources/lang/en/spotlight.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
'placeholder' => 'Search for a :record',
'account' => 'Your account',
];
9 changes: 9 additions & 0 deletions src/Actions/RegisterPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public static function boot(Panel $panel)
*/
$page = new $pageClass;

if (self::hasParameters($page::getSlug())) {
continue;
}

if (method_exists($page, 'shouldRegisterSpotlight') && $page::shouldRegisterSpotlight() === false) {
continue;
}
Expand All @@ -43,4 +47,9 @@ public static function boot(Panel $panel)
Spotlight::$commands[$command->getId()] = $command;
}
}

private static function hasParameters(string $slug): bool
{
return preg_match('/{[^}]+}/', $slug) === 1;
}
}
6 changes: 3 additions & 3 deletions src/Actions/RegisterUserMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public static function boot(Panel $panel)
protected function getName(string $key, MenuItem $item): ?string
{
return match ($key) {
'account' => $item->getLabel() ?? __('Your Account'),
'logout' => $item->getLabel() ?? __('filament::layout.buttons.logout.label'),
'account' => $item->getLabel() ?? __('filament-spotlight::spotlight.account'),
'logout' => $item->getLabel() ?? __('filament-panels::layout.actions.logout.label'),
default => $item->getLabel()
};
}

protected function getUrl(string $key, MenuItem $item): string
protected function getUrl(string $key, MenuItem $item): ?string
{
return match ($key) {
'logout' => $item->getUrl() ?? Filament::getLogoutUrl(),
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/ResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public function dependencies(): ?SpotlightCommandDependencies
}

return SpotlightCommandDependencies::collection()->add(
SpotlightCommandDependency::make('record')->setPlaceholder(__('Search for a :record', ['record' => $this->resource::getModelLabel()]))
SpotlightCommandDependency::make('record')->setPlaceholder(
__('filament-spotlight::spotlight.placeholder', ['record' => $this->resource::getModelLabel()])
)
);
}

Expand All @@ -111,7 +113,7 @@ public function searchRecord($query): EloquentCollection|Collection|array
->limit(50)
->get()
->map(fn (Model $record) => new SpotlightSearchResult(
$record->getKey(),
$record->getRouteKey(),
$resource::getGlobalSearchResultTitle($record),
collect($resource::getGlobalSearchResultDetails($record))
->map(fn ($value, $key) => $key.': '.$value)
Expand Down
1 change: 1 addition & 0 deletions src/SpotlightPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function boot(Panel $panel): void
{
Filament::serving(function () use ($panel) {
config()->set('livewire-ui-spotlight.include_js', false);

if (Filament::hasTenancy()) {
Event::listen(TenantSet::class, function () use ($panel) {
self::registerNavigation($panel);
Expand Down
2 changes: 2 additions & 0 deletions src/SpotlightServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class SpotlightServiceProvider extends ServiceProvider
{
public function boot()
{
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'filament-spotlight');

config()->set('livewire-ui-spotlight.commands', []);

FilamentAsset::register([
Expand Down

0 comments on commit 78dacd3

Please sign in to comment.