Skip to content

Conversation

@Boy132
Copy link
Member

@Boy132 Boy132 commented Sep 16, 2025

Closes #1712

@Boy132 Boy132 self-assigned this Sep 16, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 16, 2025

📝 Walkthrough

Walkthrough

Introduces a new state cast class to handle server condition values as either ServerState or ContainerStatus enums and applies it to the EditServer page’s condition toggle. The change impacts how the condition field’s state is read and written, without altering public APIs or broader control flow.

Changes

Cohort / File(s) Summary
State cast application
app/Filament/Admin/Resources/Servers/Pages/EditServer.php
Imports and applies ServerConditionStateCast to the condition toggle (server_status) via ->stateCast(new ServerConditionStateCast()).
State cast implementation
app/Filament/Components/StateCasts/ServerConditionStateCast.php
Adds ServerConditionStateCast implementing Filament’s StateCast. get(): normalizes state to ServerState or ContainerStatus enums (or null). set(): returns scalar value of a BackedEnum, or the input if not an enum.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant EditServer Page
  participant Filament Form
  participant ServerConditionStateCast as StateCast
  participant ServerState Enum
  participant ContainerStatus Enum
  participant Backend

  User->>EditServer Page: Open/Edit server
  EditServer Page->>Filament Form: Load form state
  Filament Form->>StateCast: get(state)
  alt State is enum instance
    StateCast-->>Filament Form: enum instance
  else State is scalar
    StateCast->>ServerState Enum: tryFrom(value)
    alt Matches ServerState
      StateCast-->>Filament Form: ServerState
    else No match
      StateCast->>ContainerStatus Enum: tryFrom(value)
      alt Matches ContainerStatus
        StateCast-->>Filament Form: ContainerStatus
      else No match
        StateCast-->>Filament Form: null
      end
    end
  end
  User->>Filament Form: Update condition
  Filament Form->>StateCast: set(enum or value)
  alt Input is BackedEnum
    StateCast-->>Filament Form: enum->value
  else Not an enum
    StateCast-->>Filament Form: original input
  end
  Filament Form->>Backend: Persist condition value
  Backend-->>Filament Form: OK
Loading

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Add state cast for server condition" succinctly and accurately summarizes the primary change in the diff: introducing a ServerConditionStateCast and applying it to the server condition control in EditServer.php, so a reviewer can quickly understand the PR's main purpose.
Linked Issues Check ✅ Passed Issue #1712 reports a 500 caused by the condition field being either a ServerState or a container enum and Filament failing to cast; this PR adds ServerConditionStateCast (get() attempts ServerState then ContainerStatus and set() returns the enum's scalar) and applies it to the EditServer condition control, which directly addresses the reported casting mismatch.
Out of Scope Changes Check ✅ Passed The changes are limited to adding App\Filament\Components\StateCasts\ServerConditionStateCast and updating app/Filament/Admin/Resources/Servers/Pages/EditServer.php to use it; there are no other unrelated file or behavior changes in the provided summary.
Description Check ✅ Passed The PR description contains "Closes #1712", which directly ties this change to the reported EditServer 500 issue and is therefore on-topic for the changeset, albeit minimal.

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

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5d50d4 and c7bd03d.

📒 Files selected for processing (2)
  • app/Filament/Admin/Resources/Servers/Pages/EditServer.php (2 hunks)
  • app/Filament/Components/StateCasts/ServerConditionStateCast.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/Filament/Admin/Resources/Servers/Pages/EditServer.php (1)
app/Filament/Components/StateCasts/ServerConditionStateCast.php (1)
  • ServerConditionStateCast (10-43)
🔇 Additional comments (4)
app/Filament/Admin/Resources/Servers/Pages/EditServer.php (1)

11-11: Import looks correct and scoped.

Importing the state cast here aligns with its localized use on the field below. No issues.

app/Filament/Components/StateCasts/ServerConditionStateCast.php (3)

10-11: Good placement and contract implementation.

File/class name and namespace match, and the contract import is correct.


35-42: Setter behavior is appropriate.

Returning the backing value for BackedEnum and passthrough otherwise matches Filament’s de/rehydration expectations.

Consider a tiny hardening if future callers pass scalars that match neither enum: add a comment explaining passthrough is intentional. No code change required.


12-33: Simplify enum probing and add phpdoc union

Both ServerState and ContainerStatus expose getIcon/getColor/getLabel, so the refactor is safe.

-    public function get(mixed $state): ?BackedEnum
+    /**
+     * @return ServerState|ContainerStatus|null
+     */
+    public function get(mixed $state): ?BackedEnum
     {
         if (blank($state)) {
             return null;
         }
 
         if ($state instanceof ServerState || $state instanceof ContainerStatus) {
             return $state;
         }
 
-        $serverState = ServerState::tryFrom($state);
-        if ($serverState) {
-            return $serverState;
-        }
-
-        $containerStatus = ContainerStatus::tryFrom($state);
-        if ($containerStatus) {
-            return $containerStatus;
-        }
+        foreach ([ServerState::class, ContainerStatus::class] as $enum) {
+            if ($candidate = $enum::tryFrom($state)) {
+                return $candidate;
+            }
+        }
 
         return null;
     }

@Boy132 Boy132 merged commit 932809f into main Sep 16, 2025
25 checks passed
@Boy132 Boy132 deleted the boy132/fix-server-condition branch September 16, 2025 19:34
@github-actions github-actions bot locked and limited conversation to collaborators Sep 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EditServer page throws 500

3 participants