-
-
Notifications
You must be signed in to change notification settings - Fork 254
fix client side view database unlimited state #2047
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe max_connections field display in the DatabaseResource is refactored to use a localized translation string. A corresponding translation entry is added to the English language file to support this localization change. Changes
Pre-merge checks❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
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: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
app/Filament/Server/Resources/Databases/DatabaseResource.phplang/en/server/database.php
🧰 Additional context used
🧬 Code graph analysis (1)
app/Filament/Server/Resources/Databases/DatabaseResource.php (1)
app/Models/Database.php (1)
Database(29-195)
🔇 Additional comments (1)
lang/en/server/database.php (1)
14-14: LGTM! Translation key properly added.The new translation entry follows the existing naming convention and correctly supports the localization change in
DatabaseResource.php.
| TextInput::make('max_connections') | ||
| ->label(trans('server/database.max_connections')) | ||
| ->formatStateUsing(fn (Database $database) => $database->max_connections === 0 ? $database->max_connections : 'Unlimited'), | ||
| ->formatStateUsing(fn (Database $database) => $database->max_connections === 0 ? trans('server/database.unlimited') : $database->max_connections), |
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.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check database migrations for max_connections definition
rg "max_connections" --type=php -g "**/database/migrations/**" -C 3
echo "---"
# Check the Database model for validation and nullability
cat -n app/Models/Database.php | head -100
echo "---"
# Search for any null assignments or nullable casts
rg -n "max_connections" app/Models/Database.php -C 2Repository: pelican-dev/panel
Length of output: 6086
🏁 Script executed:
#!/bin/bash
# Check if max_connections is set to null anywhere
rg -n "max_connections\s*=\s*null" --type=php -C 2
echo "---"
# Check for nullable in migration or model
rg -n "nullable.*max_connections|max_connections.*nullable" --type=php -C 2Repository: pelican-dev/panel
Length of output: 1041
null handling fix needed.
The field is indeed nullable—the migration explicitly allows it (->nullable()) and validation confirms this ('nullable', 'integer'). The current code only checks for zero values, so null entries would display as empty instead of "Unlimited". Update the formatStateUsing logic to handle both cases:
->formatStateUsing(fn (Database $database) => $database->max_connections === 0 || $database->max_connections === null ? trans('server/database.unlimited') : $database->max_connections)🤖 Prompt for AI Agents
In app/Filament/Server/Resources/Databases/DatabaseResource.php around lines 99
to 101, the formatStateUsing callback only treats zero as "Unlimited" but the
max_connections field is nullable, so null values render empty; update the
callback to treat both null and zero as "Unlimited" (i.e., check for null OR
zero) and return trans('server/database.unlimited') in those cases, otherwise
return the numeric value.
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.
| TextInput::make('max_connections') | |
| ->label(trans('server/database.max_connections')) | |
| ->formatStateUsing(fn (Database $database) => $database->max_connections === 0 ? $database->max_connections : 'Unlimited'), | |
| ->formatStateUsing(fn (Database $database) => $database->max_connections === 0 ? trans('server/database.unlimited') : $database->max_connections), | |
| ->formatStateUsing(fn (Database $database) => $database->max_connections ?: trans('server/database.unlimited')), |
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.
@rmartinoscar Thanks for the cleaner approach! Your suggestion using truthiness ($database->max_connections ? ... : ...) correctly handles both null and 0 values, since both are falsy in PHP. This is more concise than explicitly checking for each case. 👍
|
I like @rmartinoscar suggestion of using truthiness instead and he said there are a couple more places for the translation, otherwise looks good! |
No description provided.