Skip to content

Conversation

@rmartinoscar
Copy link
Member

Closes #1977

@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Fixed the startup command selector validation in the server edit form. Refactored the options source to use a simpler closure, updated the state formatter to map values correctly, and modified the afterStateUpdated handler to conditionally update the startup state based on whether the custom option is selected.

Changes

Cohort / File(s) Change Summary
Startup selector refactoring
app/Filament/Admin/Resources/Servers/Pages/EditServer.php
Reworked startup command selector: replaced state-aware closure with Get-only closure for options, added formatStateUsing inline function to validate state against available commands, and updated afterStateUpdated to conditionally update startup only when not 'custom'

Possibly related PRs

Pre-merge checks

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'EditServer select_startup refactor' accurately summarizes the main change—refactoring startup command selection logic in the EditServer resource.
Description check ✅ Passed The PR description 'Closes #1977' is concise and directly related to the changeset, properly linking to the issue being addressed.
Linked Issues check ✅ Passed The code changes address the invalid default value issue by simplifying state mapping logic and ensuring proper initialization of the startup field with valid options.
Out of Scope Changes check ✅ Passed All changes are limited to the startup field configuration in EditServer.php and directly address the scope of issue #1977.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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: 0

🧹 Nitpick comments (2)
app/Filament/Admin/Resources/Servers/Pages/EditServer.php (2)

801-805: Consider adding a null guard for defensive programming.

If Egg::find() returns null (e.g., due to data corruption or race conditions during deletion), accessing $egg->startup_commands on line 804 would throw an error.

Apply this diff to add a null check:

 ->options(function (Get $get) {
     $egg = Egg::find($get('egg_id'));
     
-    return array_flip($egg->startup_commands ?? []) + ['custom' => 'Custom Startup'];
+    return $egg 
+        ? array_flip($egg->startup_commands ?? []) + ['custom' => 'Custom Startup']
+        : ['custom' => 'Custom Startup'];
 })

806-806: Excellent fix for the invalid default value issue—consider null-safe operator.

This correctly validates the startup command against the egg's list and falls back to 'custom' when not found, which directly addresses issue #1977.

For additional robustness, consider using the null-safe operator:

-->formatStateUsing(fn (Server $server) => in_array($server->startup, $server->egg->startup_commands) ? $server->startup : 'custom')
+->formatStateUsing(fn (Server $server) => in_array($server->startup, $server->egg?->startup_commands ?? []) ? $server->startup : 'custom')
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3939c40 and 43b74b4.

📒 Files selected for processing (1)
  • app/Filament/Admin/Resources/Servers/Pages/EditServer.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/Filament/Admin/Resources/Servers/Pages/EditServer.php (2)
app/Models/Server.php (2)
  • egg (298-301)
  • Server (134-525)
app/Models/Egg.php (1)
  • Egg (60-332)
🔇 Additional comments (1)
app/Filament/Admin/Resources/Servers/Pages/EditServer.php (1)

807-812: LGTM! Clean conditional logic.

The conditional update prevents overwriting custom startup values, and unconditionally clearing the previewing flag ensures the preview state is properly reset when the selection changes.

@rmartinoscar rmartinoscar marked this pull request as draft December 11, 2025 11:35
@rmartinoscar rmartinoscar marked this pull request as ready for review December 11, 2025 11:42
@rmartinoscar rmartinoscar merged commit f278041 into main Dec 11, 2025
25 checks passed
@rmartinoscar rmartinoscar deleted the issue/1977 branch December 11, 2025 12:48
@github-actions github-actions bot locked and limited conversation to collaborators Dec 11, 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.

Default value for Startup select is invalid on EditServer

3 participants