Skip to content

Fix product status color matching in products table#2292

Merged
glennjacobs merged 5 commits intolunarphp:1.xfrom
repl6669:fix/fix-product-status-match-in-products-table
Nov 11, 2025
Merged

Fix product status color matching in products table#2292
glennjacobs merged 5 commits intolunarphp:1.xfrom
repl6669:fix/fix-product-status-match-in-products-table

Conversation

@repl6669
Copy link
Contributor

@repl6669 repl6669 commented Sep 15, 2025

If we were to use a different status than published | draft | deleted, we get an exception in products table. This PR just adds default status color handling.

Summary by CodeRabbit

  • Bug Fixes
    • Product status badges now display a consistent default color when an unrecognized status appears, improving readability and visual consistency in the products table.
    • Previously, only certain statuses had defined colors, which could lead to unexpected or missing styling for others.
    • No other user-facing behavior changes.

@vercel
Copy link

vercel bot commented Sep 15, 2025

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

Project Deployment Preview Comments Updated (UTC)
lunar-docs Ready Ready Preview Comment Sep 24, 2025 5:06pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 15, 2025

Walkthrough

Adds a default case to the color state resolution in ProductResource::getTableColumns() so any unrecognized status maps to "primary". Existing handling for known statuses remains; no public signatures changed.

Changes

Cohort / File(s) Summary of changes
Product table column state mapping
packages/admin/src/Filament/Resources/ProductResource.php
Introduced a default mapping in getTableColumns() to assign "primary" when status is unrecognized; retained existing explicit mappings for known statuses.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title precisely reflects the main change of adding default color handling to product status color matching in the products table, making it clear and specific to the update described in the PR.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87ce2e2 and c1062c9.

📒 Files selected for processing (1)
  • packages/admin/src/Filament/Resources/ProductResource.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). (19)
  • GitHub Check: PHP 8.4 - L^12.0 ↑
  • GitHub Check: shipping - PHP 8.4 - L12.* ↑ E
  • GitHub Check: core - 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: stripe - PHP 8.4 - L11.* ↑ E
  • GitHub Check: admin - PHP 8.4 - L11.* ↑
  • GitHub Check: core - PHP 8.4 - L11.* ↑
  • GitHub Check: admin - PHP 8.4 - L11.* ↑ E
  • GitHub Check: shipping - PHP 8.3 - L12.* ↑
  • GitHub Check: core - PHP 8.4 - L11.* ↑ E
  • GitHub Check: core - PHP 8.3 - L12.* ↑ E
  • GitHub Check: admin - PHP 8.3 - L12.* ↑
  • GitHub Check: admin - PHP 8.3 - L11.* ↑
  • GitHub Check: core - PHP 8.3 - L12.* ↑
  • GitHub Check: core - PHP 8.3 - L11.* ↑
  • GitHub Check: admin - PHP 8.3 - L11.* ↑ E
  • GitHub Check: core - PHP 8.3 - L11.* ↑ E
🔇 Additional comments (1)
packages/admin/src/Filament/Resources/ProductResource.php (1)

270-275: LGTM! Properly handles unknown product statuses.

The addition of a default case that maps to 'primary' color effectively prevents exceptions when products have status values other than the explicitly handled ones ('draft', 'published', 'deleted'). This provides a graceful fallback for custom or future status types.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

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 (2)
packages/admin/src/Filament/Resources/ProductResource.php (1)

266-275: Harden against null/unknown states and missing translations.

If $record->status can be null, the typed fn (string $state) may throw. Also, missing i18n keys will render the raw key. Consider a small defensive tweak:

Apply this diff in-place:

-                ->getStateUsing(
-                    fn (Model $record) => $record->deleted_at ? 'deleted' : $record->status
-                )
-                ->formatStateUsing(fn ($state) => __('lunarpanel::product.table.status.states.'.$state))
-                ->color(fn (string $state): string => match ($state) {
+                ->getStateUsing(
+                    fn (Model $record) => $record->deleted_at ? 'deleted' : ($record->status ?? 'unknown')
+                )
+                ->formatStateUsing(function ($state) {
+                    $key = 'lunarpanel::product.table.status.states.'.(string) $state;
+                    return \Illuminate\Support\Facades\Lang::has($key)
+                        ? __($key)
+                        : \Illuminate\Support\Str::headline((string) $state);
+                })
+                ->color(fn ($state): string => match ((string) $state) {
                     'draft' => 'warning',
                     'published' => 'success',
                     'deleted' => 'danger',
                     default => 'primary',
                 }),

Add these imports at the top of the file if not present:

use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Str;

Please confirm whether status can be null in your dataset. If it cannot, feel free to ignore the null-guard and keep the current signature.

packages/core/src/Facades/StorefrontSession.php (1)

8-27: Add @mixin for the manager to reduce drift and improve IDE support.

Laravel facades commonly use @mixin to inherit method signatures from the underlying class and avoid duplicating many @method tags.

Apply this diff to the docblock header:

 /**
- * @method static \Lunar\Models\Contracts\Channel getChannel()
+ * @mixin \Lunar\Managers\StorefrontSessionManager
+ * @method static \Lunar\Models\Contracts\Channel getChannel()
  * @method static \Lunar\Managers\StorefrontSessionManager setChannel(\Lunar\Models\Contracts\Channel $channel)
  * @method static \Illuminate\Support\Collection getCustomerGroups()
  * @method static \Lunar\Managers\StorefrontSessionManager setCustomerGroups(\Illuminate\Support\Collection $customerGroups)
  * @method static \Lunar\Managers\StorefrontSessionManager setCustomerGroup(\Lunar\Models\Contracts\CustomerGroup $customerGroup)
  * @method static \Lunar\Managers\StorefrontSessionManager resetCustomerGroups()
  * @method static \Lunar\Models\Contracts\Currency getCurrency()
  * @method static \Lunar\Managers\StorefrontSessionManager setCurrency(\Lunar\Models\Contracts\Currency $currency)
  * @method static \Lunar\Models\Contracts\Customer|null getCustomer()
  * @method static \Lunar\Managers\StorefrontSessionManager setCustomer(\Lunar\Models\Contracts\Customer $customer)
  * @method static void initChannel()
  * @method static void initCustomerGroups()
  * @method static void initCurrency()
  * @method static void initCustomer()
  * @method static void forget()
  * @method static string getSessionKey()
  *
  * @see \Lunar\Managers\StorefrontSessionManager
  */
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c34f27 and 87ce2e2.

📒 Files selected for processing (2)
  • packages/admin/src/Filament/Resources/ProductResource.php (1 hunks)
  • packages/core/src/Facades/StorefrontSession.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). (10)
  • GitHub Check: core - PHP 8.4 - L12.* ↑
  • GitHub Check: core - PHP 8.4 - L12.* ↑ E
  • GitHub Check: admin - PHP 8.4 - L12.* ↑ E
  • GitHub Check: admin - PHP 8.4 - L11.* ↑ E
  • GitHub Check: core - PHP 8.4 - L11.* ↑ E
  • GitHub Check: core - PHP 8.4 - L11.* ↑
  • GitHub Check: core - PHP 8.3 - L12.* ↑
  • GitHub Check: core - PHP 8.3 - L11.* ↑ E
  • GitHub Check: core - PHP 8.3 - L12.* ↑ E
  • GitHub Check: core - PHP 8.3 - L11.* ↑
🔇 Additional comments (1)
packages/admin/src/Filament/Resources/ProductResource.php (1)

270-275: Good fix: add default color to avoid UnhandledMatchError.

The default => 'primary' makes the match exhaustive and prevents crashes on unknown statuses. Looks correct.

@alecritson
Copy link
Collaborator

Thanks @repl6669 Looks like some formatting changes to the StorefrontSession class snuck in there, are you able to sort? Then I'll get this in.

@repl6669
Copy link
Contributor Author

Hello @alecritson, I cleaned up the formatting changes. Is everything ok now?

@glennjacobs glennjacobs merged commit e41a128 into lunarphp:1.x Nov 11, 2025
44 checks passed
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