Skip to content

Filament search improvements (non-Scout)#2269

Merged
glennjacobs merged 6 commits into1.xfrom
panel-search-improvements
Aug 15, 2025
Merged

Filament search improvements (non-Scout)#2269
glennjacobs merged 6 commits into1.xfrom
panel-search-improvements

Conversation

@glennjacobs
Copy link
Contributor

@glennjacobs glennjacobs commented Aug 14, 2025

Improves non-Scout searching in a few areas.

Summary by CodeRabbit

  • New Features

    • Enable search by brand name in Brands table.
    • Add search to Order columns: customer reference, billing name, postcode, and contact email.
    • Make Product Option names searchable in tables.
    • Allow searching by attribute name when attaching Collections in discount limits.
    • Enable SKU-based search when selecting Product Variants in discount limits.
  • Chores

    • Disable Scout-backed searches in the admin panel by default.
  • Documentation

    • Upgrade notes: how to re-enable Scout and new telemetry opt-out info.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 14, 2025

Walkthrough

Adds searchable() or searchColumns() calls to multiple Filament table columns and relation selectors, disables Scout in the admin panel config, and documents the Scout and telemetry changes; no public method signatures or exported APIs were changed.

Changes

Cohort / File(s) Summary
Brand & Product option table columns
packages/admin/src/Filament/Resources/BrandResource.php, packages/admin/src/Filament/Resources/ProductOptionResource.php
Added ->searchable() to name columns (Brand.name, ProductOption.name).
Order table columns
packages/admin/src/Filament/Resources/OrderResource.php
Added ->searchable() to customer_reference; billingAddress.fullName (searchable(['first_name','last_name'])); billingAddress.postcode; billingAddress.contact_email (retaining toggleable/copyable settings).
Discount relation managers
packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionLimitationRelationManager.php, packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/ProductVariantLimitationRelationManager.php
CollectionLimitation AttachAction now calls recordSelectSearchColumns(['attribute_data->name']) before preloadRecordSelect(). ProductVariantLimitation adds ->searchColumns(['sku']) to the MorphToSelect for ProductVariant; existing getSearchResultsUsing callback unchanged.
Admin config
packages/admin/config/panel.php
Flipped 'scout_enabled' from true to false.
Docs: upgrading notes
docs/core/upgrading.md
Added notes about Scout default being disabled and a new telemetry (anonymous usage) subsection with opt-out instructions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Bump Filament version #2268 — Adds multiple Filament searchable/searchColumns calls and flips Scout off; shares the same Filament JSON-search changes and feature intent.
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch panel-search-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vercel
Copy link

vercel bot commented Aug 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
lunar-docs Ready Preview Comment Aug 15, 2025 8:48am

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/ProductVariantLimitationRelationManager.php (1)

48-60: searchColumns(['sku']) is currently a no-op due to the custom getSearchResultsUsing override

Because getSearchResultsUsing is defined, the component won’t use the default query that respects ->searchColumns(['sku']). As a result, searching by SKU won’t work unless the callback itself includes an SKU condition.

Proposed fix: include SKU matching in the custom search and reduce result size.

Apply this diff:

-                                ->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search): array {
-                                    $products = get_search_builder(Product::modelClass(), $search)
-                                        ->get();
-
-                                    return ProductVariant::whereIn('product_id', $products->pluck('id'))
-                                        ->with(['product'])
-                                        ->get()
-                                        ->mapWithKeys(fn (ProductVariantContract $record): array => [$record->getKey() => $record->product->attr('name').' - '.$record->sku])
-                                        ->all();
-                                })
+                                ->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search): array {
+                                    $productIds = get_search_builder(Product::modelClass(), $search)
+                                        ->pluck('id');
+
+                                    $variants = ProductVariant::query()
+                                        ->with('product')
+                                        ->where(function ($query) use ($productIds, $search) {
+                                            if ($productIds->isNotEmpty()) {
+                                                $query->whereIn('product_id', $productIds);
+                                            }
+                                            $query->orWhere('sku', 'like', '%' . $search . '%');
+                                        })
+                                        ->limit(50)
+                                        ->get();
+
+                                    return $variants
+                                        ->mapWithKeys(fn (ProductVariantContract $record): array => [
+                                            $record->getKey() => $record->product->attr('name') . ' - ' . $record->sku,
+                                        ])
+                                        ->all();
+                                })

Optional enhancement: If you’d prefer to rely on Filament’s default search with ->searchColumns(['sku']) and still show “product name - sku” as the label, you can remove the getSearchResultsUsing override and instead use getOptionLabelFromRecordUsing on the Type:

  • getOptionLabelFromRecordUsing(fn (ProductVariant $record) => $record->product->attr('name').' - '.$record->sku')

This keeps SKU-native searching and preserves the label format.

🧹 Nitpick comments (1)
packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionLimitationRelationManager.php (1)

48-50: Verify JSON path search compatibility for attribute_data->name

recordSelectSearchColumns(['attribute_data->name']) may behave differently across databases:

  • MySQL: where('json->path', 'like', ...) is generally supported but may match quoted JSON strings.
  • PostgreSQL: text extraction typically requires ->> to unquote; LIKE on -> may not work as expected.

Please verify this works on all supported DB engines in Lunar. If cross-DB issues arise, consider a custom search callback using get_search_builder(Collection::class, $search) or narrowing to the current locale path (e.g., attribute_data->name->{locale}) where applicable.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between fac5850 and 3ed7554.

📒 Files selected for processing (5)
  • packages/admin/src/Filament/Resources/BrandResource.php (1 hunks)
  • packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionLimitationRelationManager.php (1 hunks)
  • packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/ProductVariantLimitationRelationManager.php (2 hunks)
  • packages/admin/src/Filament/Resources/OrderResource.php (2 hunks)
  • packages/admin/src/Filament/Resources/ProductOptionResource.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: admin - PHP 8.4 - L12.* ↑
  • GitHub Check: shipping - PHP 8.4 - L12.* ↑ E
  • GitHub Check: core - PHP 8.4 - L12.* ↑ E
  • GitHub Check: core - PHP 8.4 - L12.* ↑
  • GitHub Check: admin - PHP 8.4 - L12.* ↑ E
  • GitHub Check: search - PHP 8.4 - L11.* ↑
  • GitHub Check: shipping - PHP 8.4 - L11.* ↑
  • GitHub Check: search - PHP 8.4 - L11.* ↑ E
  • GitHub Check: stripe - PHP 8.3 - L12.* ↑
  • GitHub Check: stripe - PHP 8.4 - L11.* ↑
  • GitHub Check: admin - PHP 8.4 - L11.* ↑ E
  • GitHub Check: admin - PHP 8.4 - L11.* ↑
  • GitHub Check: core - PHP 8.4 - L11.* ↑ E
  • GitHub Check: core - PHP 8.3 - L12.* ↑
  • GitHub Check: admin - PHP 8.3 - L12.* ↑ E
  • GitHub Check: core - PHP 8.3 - L12.* ↑ E
  • GitHub Check: admin - PHP 8.3 - L11.* ↑ E
  • GitHub Check: core - PHP 8.3 - L11.* ↑
  • GitHub Check: core - PHP 8.3 - L11.* ↑ E
  • GitHub Check: fix-code-style
🔇 Additional comments (6)
packages/admin/src/Filament/Resources/ProductOptionResource.php (1)

96-98: Making the translated name column searchable is a solid improvement

This aligns with the PR goal and should materially improve admin UX for large catalogs. No issues spotted.

packages/admin/src/Filament/Resources/BrandResource.php (1)

124-126: Enabling search on brand name: LGTM

Straightforward and consistent with other resources. No concerns.

packages/admin/src/Filament/Resources/OrderResource.php (4)

99-101: Customer reference: searchable is appropriate

This improves operator workflows without side effects.


103-105: Confirm relation-scoped search columns are correctly prefixed

For TextColumn::make('billingAddress.fullName')->searchable(['first_name', 'last_name']), Filament may assume the relationship context. If not, this could miss the relation or cause ambiguous column errors. Prefer explicit prefixes to be safe.

Apply this diff for explicitness:

-                ->searchable(['first_name', 'last_name']),
+                ->searchable(['billingAddress.first_name', 'billingAddress.last_name']),

118-121: Postcode: searchable is fine

Good addition for narrowing down orders quickly by postcode.


126-128: Email: searchable and copy UX improvements look good

The copyable and copy message duration changes are sensible and the column being searchable aligns with common workflows.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/admin/config/panel.php (1)

37-37: Make this flag environment-configurable for easier ops toggling

Allow admins to switch behavior without editing published config by honoring an env var.

Apply this diff:

-    'scout_enabled' => false,
+    'scout_enabled' => env('LUNAR_ADMIN_SCOUT_ENABLED', false),

Optional follow-up: add a brief note in the comment above indicating the corresponding ENV key.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 99e6c8d and e6cd3df.

📒 Files selected for processing (1)
  • packages/admin/config/panel.php (1 hunks)
🔇 Additional comments (1)
packages/admin/config/panel.php (1)

37-37: Confirmed — Scout disabled by default is intentional and properly gated

Code and tests show the config is read and Scout usage is guarded; docs reflect the default. No change required.

  • packages/admin/config/panel.php — 'scout_enabled' => false
  • packages/admin/src/helpers.php — checks config('lunar.panel.scout_enabled', false) and Searchable::class in get_search_builder()
  • packages/admin/src/Support/Resources/BaseResource.php — checks config + Searchable before Scout global search
  • packages/admin/src/Support/Pages/BaseListRecords.php — checks config + applies column searches
  • tests/admin/Feature/... (BrandResource/Actions/SearchTest.php, GlobalSearchTest.php) — set Config::set('lunar.panel.scout_enabled', false)
  • docs/core/installation.md — shows 'scout_enabled' => false

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/core/upgrading.md (1)

38-46: Show opt-out usage in a concrete service provider context.

Embedding the call in a typical Service Provider method reduces ambiguity for where to place it.

Apply this diff to replace the snippet with a complete example:

 ```php
-\Lunar\Facades\Telemetry::optOut();
+public function register()
+{
+    \Lunar\Facades\Telemetry::optOut();
+}

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

**💡 Knowledge Base configuration:**

- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between e6cd3df5ec846b0eedbd3cc2cf204c55a59bf61a and 9cd4dacf2c73eb800c3c31b86cdc48da23e44379.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `docs/core/upgrading.md` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 LanguageTool</summary>

<details>
<summary>docs/core/upgrading.md</summary>

[grammar] ~25-~25: There might be a mistake here.
Context: ...#### Scout no longer enabled by default for admin panel With the recent panel searc...

(QB_NEW_EN)

</details>

</details>

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)</summary>

* GitHub Check: shipping - PHP 8.4 - L12.* ↑
* GitHub Check: admin - PHP 8.4 - L11.* ↑ E
* GitHub Check: search - PHP 8.4 - L11.* ↑
* GitHub Check: stripe - PHP 8.4 - L12.* ↑
* GitHub Check: shipping - PHP 8.4 - L11.* ↑
* GitHub Check: search - PHP 8.4 - L12.* ↑ E
* GitHub Check: admin - PHP 8.4 - L12.* ↑
* GitHub Check: admin - PHP 8.4 - L12.* ↑ E
* GitHub Check: core - PHP 8.4 - L12.* ↑
* GitHub Check: admin - PHP 8.4 - L11.* ↑
* GitHub Check: core - PHP 8.4 - L11.* ↑
* GitHub Check: admin - PHP 8.3 - L12.* ↑
* GitHub Check: admin - PHP 8.3 - L12.* ↑ E
* GitHub Check: core - PHP 8.3 - L12.* ↑ E
* GitHub Check: shipping - PHP 8.3 - L11.* ↑ E
* GitHub Check: admin - PHP 8.3 - L11.* ↑
* GitHub Check: core - PHP 8.3 - L11.* ↑
* GitHub Check: admin - PHP 8.3 - L11.* ↑ E
* GitHub Check: core - PHP 8.3 - L11.* ↑ E
* GitHub Check: fix-code-style

</details>

<details>
<summary>🔇 Additional comments (1)</summary><blockquote>

<details>
<summary>docs/core/upgrading.md (1)</summary>

`23-23`: **Section addition looks good.**

Clear separation for “Medium Impact” is helpful for readers scanning the Unreleased changes.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@glennjacobs glennjacobs merged commit e615339 into 1.x Aug 15, 2025
48 checks passed
@glennjacobs glennjacobs deleted the panel-search-improvements branch August 15, 2025 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants