-
-
Notifications
You must be signed in to change notification settings - Fork 254
Add state cast for server condition #1713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughIntroduces 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
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
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
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. Comment |
There was a problem hiding this 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
📒 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 unionBoth 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; }
Closes #1712